Class: PhlexKit::TabsTrigger
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::TabsTrigger
- Defined in:
- app/components/phlex_kit/tabs/tabs_trigger.rb
Instance Method Summary collapse
-
#initialize(value:, as: :button, active: false, **attrs) ⇒ TabsTrigger
constructor
A new instance of TabsTrigger.
- #view_template ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(value:, as: :button, active: false, **attrs) ⇒ TabsTrigger
Returns a new instance of TabsTrigger.
3 4 5 6 7 8 |
# File 'app/components/phlex_kit/tabs/tabs_trigger.rb', line 3 def initialize(value:, as: :button, active: false, **attrs) @value = value @as = as.to_sym @active = active @attrs = attrs end |
Instance Method Details
#view_template ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/components/phlex_kit/tabs/tabs_trigger.rb', line 9 def view_template(&) # Deterministic ids pair each trigger with its panel (aria-controls / # aria-labelledby); the controller re-scopes them per instance in # connect() so multiple tab sets sharing a value can't collide. # aria-selected and the roving tabindex are kept in sync by the # controller's activeValueChanged. base = { class: "pk-tabs-trigger", role: "tab", id: "pk-tabs-trigger-#{@value}", aria_selected: @active ? "true" : "false", aria_controls: "pk-tabs-panel-#{@value}", tabindex: @active ? "0" : "-1", data: { phlex_kit__tabs_target: "trigger", action: "click->phlex-kit--tabs#show", value: @value } } if @as == :a a(**mix(base, @attrs), &) else (**mix(base.merge(type: :button), @attrs), &) end end |