Class: ShadcnPhlexcomponents::DropdownMenuContent

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/dropdown_menu.rb

Constant Summary

Constants inherited from Base

Base::SANITIZER_ALLOWED_ATTRIBUTES, Base::SANITIZER_ALLOWED_TAGS, Base::TAILWIND_MERGER

Instance Method Summary collapse

Methods inherited from Base

#before_template, #convert_collection_hash_to_struct, #find_as_child, #icon, #item_disabled?, #merge_default_attributes, #merged_as_child_attributes, #nokogiri_attributes_to_hash, #overlay, #sanitize_as_child

Constructor Details

#initialize(side: :bottom, align: :center, aria_id: nil, **attributes) ⇒ DropdownMenuContent

Returns a new instance of DropdownMenuContent.



129
130
131
132
133
134
# File 'lib/shadcn_phlexcomponents/components/dropdown_menu.rb', line 129

def initialize(side: :bottom, align: :center, aria_id: nil, **attributes)
  @side = side
  @align = align
  @aria_id = aria_id
  super(**attributes)
end

Instance Method Details

#default_attributes ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/shadcn_phlexcomponents/components/dropdown_menu.rb', line 142

def default_attributes
  {
    id: "#{@aria_id}-content",
    tabindex: -1,
    role: "menu",
    aria: {
      labelledby: "#{@aria_id}-trigger",
      orientation: "vertical",
    },
    data: {
      state: "closed",
      side: @side,
      align: @align,
      dropdown_menu_target: "content",
      action: <<~HEREDOC,
        dropdown-menu:click:outside->dropdown-menu#clickOutside
        keydown.up->dropdown-menu#focusItemByIndex:prevent:self
        keydown.down->dropdown-menu#focusItemByIndex:prevent:self
      HEREDOC
    },
  }
end

#view_template ⇒ Object



136
137
138
139
140
# File 'lib/shadcn_phlexcomponents/components/dropdown_menu.rb', line 136

def view_template(&)
  DropdownMenuContentContainer do
    div(**@attributes, &)
  end
end