Class: PhlexKit::AccordionContent

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/accordion/accordion_content.rb

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(open: false, **attrs) ⇒ AccordionContent

Pass open: true alongside AccordionItem(open: true) so the content is readable without JS — the closed-state hidden + height:0 otherwise makes a server-rendered open item unreachable pre-hydration.



6
7
8
9
# File 'app/components/phlex_kit/accordion/accordion_content.rb', line 6

def initialize(open: false, **attrs)
  @open = open
  @attrs = attrs
end

Instance Method Details

#view_templateObject



11
12
13
14
15
16
17
# File 'app/components/phlex_kit/accordion/accordion_content.rb', line 11

def view_template(&)
  # role="region" + aria-labelledby → trigger id (wired by the controller
  # in connect(), which also assigns the ids), per the APG accordion pattern.
  base = { class: "pk-accordion-content", role: "region", data: { phlex_kit__accordion_target: "content", state: @open ? "open" : "closed" } }
  base.merge!(style: "height: 0px;", hidden: true) unless @open
  div(**mix(base, @attrs), &)
end