Module: UI::DropdownMenuTriggerBehavior
- Included in:
- DropdownMenuTrigger, DropdownMenuTriggerComponent
- Defined in:
- app/behaviors/ui/dropdown_menu_trigger_behavior.rb
Overview
DropdownMenuTriggerBehavior
Shared behavior for DropdownMenuTrigger component across ERB, ViewComponent, and Phlex implementations.
Instance Method Summary collapse
-
#dropdown_menu_trigger_base_classes ⇒ Object
Base classes for trigger (focus styles).
-
#dropdown_menu_trigger_classes ⇒ Object
Returns combined CSS classes for the trigger.
-
#dropdown_menu_trigger_data_attributes ⇒ Object
Returns data attributes for Stimulus.
-
#dropdown_menu_trigger_html_attributes ⇒ Object
Returns HTML attributes for the trigger When as_child is true, only data attributes are returned to avoid overriding child’s classes.
Instance Method Details
#dropdown_menu_trigger_base_classes ⇒ Object
Base classes for trigger (focus styles)
34 35 36 |
# File 'app/behaviors/ui/dropdown_menu_trigger_behavior.rb', line 34 def "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 rounded-sm" end |
#dropdown_menu_trigger_classes ⇒ Object
Returns combined CSS classes for the trigger
25 26 27 28 29 30 31 |
# File 'app/behaviors/ui/dropdown_menu_trigger_behavior.rb', line 25 def classes_value = respond_to?(:classes, true) ? classes : @classes TailwindMerge::Merger.new.merge([ , classes_value ].compact.join(" ")) end |
#dropdown_menu_trigger_data_attributes ⇒ Object
Returns data attributes for Stimulus
39 40 41 42 43 44 45 |
# File 'app/behaviors/ui/dropdown_menu_trigger_behavior.rb', line 39 def attributes_value = respond_to?(:attributes, true) ? attributes : @attributes (attributes_value&.fetch(:data, {}) || {}).merge({ "ui--dropdown-target": "trigger", action: "click->ui--dropdown#toggle keydown.enter->ui--dropdown#toggle keydown.space->ui--dropdown#toggle" }) end |
#dropdown_menu_trigger_html_attributes ⇒ Object
Returns HTML attributes for the trigger When as_child is true, only data attributes are returned to avoid overriding child’s classes
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/behaviors/ui/dropdown_menu_trigger_behavior.rb', line 9 def attrs = { data: , tabindex: "0", role: "button", "aria-haspopup": "menu" } # Only include class if it's not empty (to avoid overriding child component's classes) trigger_classes = attrs[:class] = trigger_classes unless trigger_classes.blank? attrs end |