Class: UI::DropdownMenuTriggerComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
DropdownMenuTriggerBehavior
Defined in:
app/view_components/ui/dropdown_menu_trigger_component.rb

Overview

TriggerComponent - ViewComponent implementation

Instance Method Summary collapse

Methods included from DropdownMenuTriggerBehavior

#dropdown_menu_trigger_base_classes, #dropdown_menu_trigger_classes, #dropdown_menu_trigger_data_attributes, #dropdown_menu_trigger_html_attributes

Constructor Details

#initialize(as_child: false, classes: "", **attributes) ⇒ DropdownMenuTriggerComponent

Returns a new instance of DropdownMenuTriggerComponent.



9
10
11
12
13
# File 'app/view_components/ui/dropdown_menu_trigger_component.rb', line 9

def initialize(as_child: false, classes: "", **attributes)
  @as_child = as_child
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#call ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/view_components/ui/dropdown_menu_trigger_component.rb', line 23

def call
  all_attrs = dropdown_menu_trigger_html_attributes.deep_merge(@attributes)

  if @as_child
    # asChild mode: yield attributes to block, child handles rendering
    content
  else
    # Default mode: render as div
     :div, **all_attrs do
      content
    end
  end
end

#trigger_attrs ⇒ Object

Returns trigger attributes for as_child mode



16
17
18
19
20
21
# File 'app/view_components/ui/dropdown_menu_trigger_component.rb', line 16

def trigger_attrs
  attrs = dropdown_menu_trigger_html_attributes.deep_merge(@attributes)
  # When as_child is true, only pass functional attributes (data, aria, tabindex, role)
  # The child component handles its own styling (following shadcn pattern)
  attrs.except(:class)
end