Skip to content

Commit

Permalink
Add disabled options support to Select component
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillplatonov committed Sep 6, 2021
1 parent ed5c998 commit 6b76761
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/components/polaris/select_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<%= render Polaris::LabelledComponent.new(**@wrapper_arguments) do %>
<%= render Polaris::BaseComponent.new(**@system_arguments) do %>
<% if @form.present? && @attribute.present? %>
<%= @form.select(@attribute, options_for_select(@options, @selected), @select_options, @input_options) %>
<%= @form.select(
@attribute,
options_for_select(@options, selected: @selected, disabled: @disabled_options),
@select_options,
@input_options,
) %>
<% else %>
<%= select_tag(@name, options_for_select(@options, @selected), @input_options) %>
<%= select_tag(
@name,
options_for_select(@options, selected: @selected, disabled: @disabled_options),
@input_options,
) %>
<% end %>

<div
Expand Down
2 changes: 2 additions & 0 deletions app/components/polaris/select_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def initialize(
name: nil,
options:,
selected: nil,
disabled_options: nil,
label: nil,
label_hidden: false,
label_inline: false,
Expand All @@ -26,6 +27,7 @@ def initialize(
@name = name
@options = options
@selected = selected
@disabled_options = disabled_options
@label = label
@label_hidden = label_hidden
@label_inline = label_inline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,16 @@
"Last 7 days" => "lastWeek",
},
) %>

<br>

<%= polaris_select(
name: :date_range,
label: "Disabled options",
options: {
"Today" => "today",
"Yesterday" => "yesterday",
"Last 7 days" => "lastWeek",
},
disabled_options: ["yesterday", "lastWeek"],
) %>
13 changes: 13 additions & 0 deletions test/components/polaris/select_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ def test_disabled
end
end

def test_disabled_options
render_inline(Polaris::SelectComponent.new(
name: :input_name,
label: "Input Label",
options: [["Option 1", "option1"], ["Option 2", "option2"]],
disabled_options: "option2",
))

assert_selector ".Polaris-Select > select" do
assert_selector "option[value=option2][disabled]"
end
end

def test_required
render_inline(Polaris::SelectComponent.new(
name: :input_name,
Expand Down

0 comments on commit 6b76761

Please sign in to comment.