Class: PhlexKit::TabsContent

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/tabs/tabs_content.rb

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(value:, active: false, id: nil, **attrs) ⇒ TabsContent

id: is a named kwarg (not left in **attrs) — see TabsTrigger.



4
5
6
7
8
9
# File 'app/components/phlex_kit/tabs/tabs_content.rb', line 4

def initialize(value:, active: false, id: nil, **attrs)
  @value = value
  @active = active
  @id = id || "pk-tabs-panel-#{value}"
  @attrs = attrs
end

Instance Method Details

#view_templateObject



10
11
12
13
14
15
16
17
# File 'app/components/phlex_kit/tabs/tabs_content.rb', line 10

def view_template(&)
  # id / aria-labelledby mirror TabsTrigger's deterministic ids (re-scoped
  # per instance by the controller); tabindex="0" makes the panel itself
  # focusable, per the APG tabs pattern. `active:` (mirroring TabsTrigger's)
  # renders the panel visible pre-JS/no-JS; the controller's sync()
  # reconciles visibility from the active value after connect.
  div(**mix({ class: @active ? "pk-tabs-content" : "pk-tabs-content pk-hidden", role: "tabpanel", id: @id, aria_labelledby: "pk-tabs-trigger-#{@value}", tabindex: "0", data: { phlex_kit__tabs_target: "content", value: @value } }, @attrs), &)
end