Skip to content

Commit cdd54c7

Browse files
committed
fix(color-select): Do not prefill color picker value on init
Sometimes we do not want to save a color, because it is optional.
1 parent 8146559 commit cdd54c7

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

app/components/alchemy/ingredients/color_editor.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ def input_field
1111
value,
1212
disabled: !editable?
1313
)
14+
concat color_field_tag(nil, value, disabled: disabled?)
1415
else
1516
concat select_tag(
1617
form_field_name,
1718
color_options.join.html_safe,
1819
disabled: !editable?
1920
)
21+
concat color_field_tag(form_field_name, value, disabled: disabled?)
2022
end
21-
concat color_field_tag(form_field_name, value, disabled: disabled?)
2223
end
2324
end
2425

app/javascript/alchemy_admin/components/color_select.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ class ColorSelect extends HTMLElement {
2121
this.#toggleColorPicker(event.val === "custom_color")
2222
)
2323
} else {
24-
if (this.textInput) {
25-
this.colorInput.addEventListener("input", this)
26-
this.textInput.addEventListener("input", this)
27-
this.textInput.value = this.colorInput.value
28-
}
24+
this.colorInput?.addEventListener("input", this)
25+
this.textInput?.addEventListener("input", this)
2926
this.#toggleColorPicker(true)
3027
}
3128
}

spec/components/alchemy/ingredients/color_editor_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
context "with no color option" do
3535
let(:settings) { {} }
3636

37-
it "renders a text input field with a color picker" do
37+
it "renders a text input field and a color picker without name attribute" do
3838
is_expected.to have_selector("input[type='text'] + input[type='color']")
39+
is_expected.to_not have_selector("input[type='color'][name]")
3940
end
4041
end
4142

0 commit comments

Comments
 (0)