Module: UI::MenubarRadioGroupBehavior

Included in:
MenubarRadioGroup, MenubarRadioGroupComponent
Defined in:
app/behaviors/ui/menubar_radio_group_behavior.rb

Overview

MenubarRadioGroupBehavior

Shared behavior for MenubarRadioGroup component across ERB, ViewComponent, and Phlex implementations.

Instance Method Summary collapse

Instance Method Details

Returns combined CSS classes for the radio group



17
18
19
20
21
22
# File 'app/behaviors/ui/menubar_radio_group_behavior.rb', line 17

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

Returns data attributes for the radio group



25
26
27
28
29
30
31
32
33
# File 'app/behaviors/ui/menubar_radio_group_behavior.rb', line 25

def menubar_radio_group_data_attributes
  attributes_value = respond_to?(:attributes, true) ? attributes : @attributes
  base_data = {}

  # Store the current value if provided
  base_data[:"ui--menubar-radio-value"] = @value if defined?(@value) && @value

  (attributes_value&.fetch(:data, {}) || {}).merge(base_data)
end

Returns HTML attributes for the radio group



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

def menubar_radio_group_html_attributes
  {
    class: menubar_radio_group_classes,
    data: menubar_radio_group_data_attributes,
    role: "group"
  }
end