petalframework / petal_components

Phoenix + Live View HEEX Components
https://petal.build/components
MIT License
818 stars 94 forks source link

Switch string interpolation breaks when passing a class to component #275

Closed John-vd-Berg closed 11 months ago

John-vd-Berg commented 11 months ago

Greetings,

After updating to petal 1.7 we noticed an error when using a form_field of type switch and passing a class attribute.

Heres the error message: cannot convert the given list to a string.

To be converted to a string, a list must either be empty or only contain the following elements:

Please check the given list or call inspect/1 to get the list representation, got:

["", nil]

The error occurs here: petal_components/lib/petal_components/form.ex:611

This happens due to the string interpolation used for the switch.

This works: <.form_field type="switch" form={f} field={:my_field} classes={if @read_only?, do: "cursor-not-allowed"} />

This breaks: <.form_field type="switch" form={f} field={:my_field} class={if @read_only?, do: "cursor-not-allowed"} />

John-vd-Berg commented 11 months ago

Amendment: this seems to happen only when using if without an else

mplatts commented 11 months ago

Thanks will take a look

mplatts commented 11 months ago

Should be fixed in 1.7.1