Module: UI::ToggleGroupBehavior

Included in:
ToggleGroup, ToggleGroupComponent
Defined in:
app/behaviors/ui/toggle_group_behavior.rb

Overview

ToggleGroupBehavior

Shared behavior for ToggleGroup (Root) component across ERB, ViewComponent, and Phlex implementations. This module provides consistent variant and size styling for the group container.

Instance Method Summary collapse

Instance Method Details

#toggle_group_classes ⇒ Object

Returns combined CSS classes for the toggle group container



31
32
33
34
35
36
37
38
39
# File 'app/behaviors/ui/toggle_group_behavior.rb', line 31

def toggle_group_classes
  classes_value = respond_to?(:classes, true) ? classes : @classes
  TailwindMerge::Merger.new.merge([
    toggle_group_base_classes,
    toggle_group_spacing_classes,
    toggle_group_variant_classes,
    classes_value
  ].compact.join(" "))
end

#toggle_group_html_attributes ⇒ Object

Returns HTML attributes for the toggle group container element



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/behaviors/ui/toggle_group_behavior.rb', line 11

def toggle_group_html_attributes
  attrs = {
    class: toggle_group_classes,
    role: (@type == "single") ? "radiogroup" : "group",
    data: {
      controller: "ui--toggle-group",
      "ui--toggle-group-type-value": @type || "single",
      "ui--toggle-group-value-value": @value&.to_json || ((@type == "multiple") ? "[]" : "null")
    }
  }

  # Add orientation for accessibility
  attrs[:"data-orientation"] = @orientation if @orientation
  attrs[:"data-spacing"] = @spacing.to_s if @spacing
  attrs[:"data-variant"] = @variant if @variant

  attrs.compact
end