Module: UI::TabsContentBehavior

Included in:
TabsContent, TabsContentComponent
Defined in:
app/behaviors/ui/tabs_content_behavior.rb

Overview

Shared behavior for TabsContent component Panel displaying content for active tab

Instance Method Summary collapse

Instance Method Details

#content_html_attributes ⇒ Object

Build complete HTML attributes hash for content



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/behaviors/ui/tabs_content_behavior.rb', line 16

def content_html_attributes
  base_attrs = @attributes&.except(:data) || {}
  user_data = @attributes&.fetch(:data, {}) || {}

  content_data = {
    ui__tabs_target: "content",
    value: @value
  }.merge(user_data)

  base_attrs.merge(
    class: "flex-1 outline-none #{@classes}".strip,
    id: "tabs-content-#{@value}",
    role: "tabpanel",
    "aria-labelledby": "tabs-trigger-#{@value}",
    "data-state": content_state,
    "data-orientation": @orientation || "horizontal",
    "data-slot": "tabs-content",
    tabindex: "0",
    hidden: content_state == "inactive",
    data: content_data
  )
end

#content_state ⇒ Object

Determine initial state based on value



7
8
9
10
11
12
13
# File 'app/behaviors/ui/tabs_content_behavior.rb', line 7

def content_state
  if @value == @default_value
    "active"
  else
    "inactive"
  end
end