Class: Shadcn::DropdownMenu::Content::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/dropdown_menu/content/component.rb

Overview

DropdownMenuContent

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#css_classes, default_tag, #initialize, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

This class inherits a constructor from Shadcn::ApplicationViewComponent

Instance Method Details

#callObject

shadcn wraps the content in a DropdownMenuPortal. Radix relocates it to document.body; here it stays put (see the Stimulus controller for why) and is display: contents, so it adds no box of its own.



41
42
43
44
45
# File 'app/components/shadcn/dropdown_menu/content/component.rb', line 41

def call
  tag.div("data-slot": "dropdown-menu-portal", style: CONTENTS_STYLE) do
    render_element(body: safe_join([ items, content ].flatten.compact))
  end
end

#element_attributes(**defaults) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'app/components/shadcn/dropdown_menu/content/component.rb', line 26

def element_attributes(**defaults)
  super(**{
    role: "menu",
    tabindex: "-1",
    "aria-orientation" => "vertical",
    "data-state" => "closed",
    hidden: true,
    "data-shadcn--dropdown-menu-target" => "content",
    "data-action" => "keydown->shadcn--dropdown-menu#contentKeydown"
  }.merge(defaults))
end