Skip to content

Commit

Permalink
fix(params): ensure toggle input displays correct initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
allmarkedup committed Dec 21, 2022
1 parent 2be2256 commit 4060575
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions app/components/lookbook/params/field/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def before_render
styles, html = StylesExtractor.call(render_input)
Editor::Component.add_styles(param.input, styles)

escaped_value = json_escape(param.value.to_json)
value = param.value.nil? ? nil : param.cast_value
escaped_value = json_escape(value.to_json)
wrapper_attrs = {
data: {"param-input": param.input},
"x-data": "paramsInputComponent({name: '#{param.name}', value: #{escaped_value}})"
Expand All @@ -31,7 +32,7 @@ def render_input
render(param.input_partial,
name: param.name,
input: param.input,
value: param.value,
value: (param.cast_value unless param.value.nil?),
value_type: param.value_type,
value_default: param.value_default,
input_options: input_options.except(:choices, :opts),
Expand Down
6 changes: 3 additions & 3 deletions app/views/lookbook/inspector/inputs/_toggle.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ button_classes = [
"relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full
cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2
focus:ring-offset-2 focus:ring-input-border-focus",
value == "true" ? "bg-lookbook-input-toggle-active" : "bg-lookbook-input-toggle"
value == true ? "bg-lookbook-input-toggle-active" : "bg-lookbook-input-toggle"
]
span_classes = [
"pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow ring-0 transition ease-in-out duration-200",
value == "true" ? "translate-x-5" : "translate-x-0"
value == true ? "translate-x-5" : "translate-x-0"
]
%>

<%= tag.button **input_options,
class: class_names(button_classes),
role: "switch",
type: "button",
"@click.stop": "value = value == 'true' ? 'false' : 'true'", escape: false do %>
"@click.stop": "value = !value", escape: false do %>
<%= tag.span "aria-hidden": true, class: class_names(span_classes) %>
<% end %>

0 comments on commit 4060575

Please sign in to comment.