Class: ShadcnPhlexcomponents::DropdownMenuTrigger
- 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
- #default_attributes ⇒ Object
-
#initialize(as_child: false, aria_id: nil, **attributes) ⇒ DropdownMenuTrigger
constructor
A new instance of DropdownMenuTrigger.
- #view_template ⇒ Object
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(as_child: false, aria_id: nil, **attributes) ⇒ DropdownMenuTrigger
Returns a new instance of DropdownMenuTrigger.
67 68 69 70 71 |
# File 'lib/shadcn_phlexcomponents/components/dropdown_menu.rb', line 67 def initialize(as_child: false, aria_id: nil, **attributes) @as_child = as_child @aria_id = aria_id super(**attributes) end |
Instance Method Details
#default_attributes ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/shadcn_phlexcomponents/components/dropdown_menu.rb', line 88 def default_attributes { id: "#{@aria_id}-trigger", role: "button", aria: { haspopup: "menu", expanded: false, controls: "#{@aria_id}-content", }, data: { state: "closed", as_child: @as_child.to_s, dropdown_menu_target: "trigger", action: " click->dropdown-menu#toggle\n keydown.down->dropdown-menu#open:prevent\n keydown.space->dropdown-menu#open:prevent\n keydown.enter->dropdown-menu#open:prevent\n HEREDOC\n },\n }\nend\n", |
#view_template ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/shadcn_phlexcomponents/components/dropdown_menu.rb', line 73 def view_template(&) if @as_child content = capture(&) element = find_as_child(content.to_s) vanish(&) merged_attributes = merged_as_child_attributes(element, @attributes) send(element.name, **merged_attributes) do sanitize_as_child(element.children.to_s) end else div(**@attributes, &) end end |