Module: UI::MenubarTriggerBehavior
- Included in:
- MenubarTrigger, MenubarTriggerComponent
- Defined in:
- app/behaviors/ui/menubar_trigger_behavior.rb
Overview
MenubarTriggerBehavior
Shared behavior for MenubarTrigger component across ERB, ViewComponent, and Phlex implementations.
Instance Method Summary collapse
-
#menubar_trigger_classes ⇒ Object
Returns combined CSS classes for the trigger.
-
#menubar_trigger_data_attributes ⇒ Object
Returns data attributes for Stimulus.
-
#menubar_trigger_html_attributes ⇒ Object
Returns HTML attributes for the trigger.
Instance Method Details
#menubar_trigger_classes ⇒ Object
Returns combined CSS classes for the trigger
20 21 22 23 24 25 26 27 28 |
# File 'app/behaviors/ui/menubar_trigger_behavior.rb', line 20 def classes_value = respond_to?(:classes, true) ? classes : @classes TailwindMerge::Merger.new.merge([ "flex items-center rounded-sm px-2 py-1 text-sm font-medium outline-hidden select-none", "focus:bg-accent focus:text-accent-foreground", "data-[state=open]:bg-accent data-[state=open]:text-accent-foreground", classes_value ].compact.join(" ")) end |
#menubar_trigger_data_attributes ⇒ Object
Returns data attributes for Stimulus
31 32 33 34 35 36 37 38 |
# File 'app/behaviors/ui/menubar_trigger_behavior.rb', line 31 def attributes_value = respond_to?(:attributes, true) ? attributes : @attributes (attributes_value&.fetch(:data, {}) || {}).merge({ "ui--menubar-target": "trigger", action: "click->ui--menubar#toggle mouseenter->ui--menubar#handleTriggerHover keydown->ui--menubar#handleTriggerKeydown", state: "closed" }) end |
#menubar_trigger_html_attributes ⇒ Object
Returns HTML attributes for the trigger
8 9 10 11 12 13 14 15 16 17 |
# File 'app/behaviors/ui/menubar_trigger_behavior.rb', line 8 def { class: , data: , role: "menuitem", "aria-haspopup": "menu", "aria-expanded": "false", tabindex: first_trigger? ? "0" : "-1" } end |