Class: PhlexKit::ToggleGroupItem
- Inherits:
-
Toggle
- Object
- Phlex::HTML
- BaseComponent
- Toggle
- PhlexKit::ToggleGroupItem
- Defined in:
- app/components/phlex_kit/toggle_group/toggle_group_item.rb
Constant Summary
Constants inherited from Toggle
PhlexKit::Toggle::SIZES, PhlexKit::Toggle::VARIANTS
Instance Method Summary collapse
-
#initialize(value:, group_context:, variant: nil, size: nil, **attrs) ⇒ ToggleGroupItem
constructor
A new instance of ToggleGroupItem.
- #view_template(&block) ⇒ Object
Methods inherited from Toggle
Methods inherited from BaseComponent
Constructor Details
#initialize(value:, group_context:, variant: nil, size: nil, **attrs) ⇒ ToggleGroupItem
Returns a new instance of ToggleGroupItem.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/components/phlex_kit/toggle_group/toggle_group_item.rb', line 3 def initialize(value:, group_context:, variant: nil, size: nil, **attrs) # Toggle kwargs this item renders no markup for, or that the group # derives itself (pressed: comes from the group's selected_values) — # inheriting them silently discarded the caller's input. unsupported = attrs.keys & %i[wrapper name unpressed_value pressed] if unsupported.any? raise ArgumentError, "ToggleGroupItem does not support #{unsupported.join(", ")} (group items render a bare button)" end @item_value = value.to_s @group_context = group_context pressed = group_context[:selected_values].include?(@item_value) item_disabled = attrs.key?(:disabled) ? attrs.delete(:disabled) : group_context[:disabled] # Roving tabindex initial stop: when nothing is selected yet, the first # enabled item claims tabindex="0" (see ToggleGroup#claim_tab_stop). # group_context[:group] is nil for a hand-built context (bypassing # ToggleGroup#item_context) — treat that as "no tab-stop claim" rather # than raising, since standalone tests construct contexts by hand. @is_first_tab_stop = group_context[:group]&.claim_tab_stop(item_disabled) || false super(pressed: pressed, name: nil, value: @item_value, variant: variant || group_context[:variant], size: size || group_context[:size], disabled: item_disabled, **attrs) end |
Instance Method Details
#view_template(&block) ⇒ Object
27 28 29 |
# File 'app/components/phlex_kit/toggle_group/toggle_group_item.rb', line 27 def view_template(&block) (**mix(item_default_attrs, @attrs), &block) end |