Module: UI::DropdownMenuContentBehavior

Included in:
DropdownMenuContent, DropdownMenuContentComponent
Defined in:
app/behaviors/ui/dropdown_menu_content_behavior.rb

Overview

DropdownMenuContentBehavior

Shared behavior for DropdownMenuContent component across ERB, ViewComponent, and Phlex implementations.

Instance Method Summary collapse

Instance Method Details

Returns combined CSS classes for the content



18
19
20
21
22
23
24
25
26
27
# File 'app/behaviors/ui/dropdown_menu_content_behavior.rb', line 18

def dropdown_menu_content_classes
  classes_value = respond_to?(:classes, true) ? classes : @classes
  base_classes = "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--ui-dropdown-menu-content-available-height) min-w-[8rem] origin-(--ui-dropdown-menu-content-transform-origin) overflow-visible rounded-md border p-1 shadow-md absolute"

  TailwindMerge::Merger.new.merge([
    "hidden absolute",
    base_classes,
    classes_value
  ].compact.join(" "))
end

Returns data attributes for Stimulus target



30
31
32
33
34
35
36
# File 'app/behaviors/ui/dropdown_menu_content_behavior.rb', line 30

def dropdown_menu_content_data_attributes
  attributes_value = respond_to?(:attributes, true) ? attributes : @attributes
  (attributes_value&.fetch(:data, {}) || {}).merge({
    "ui--dropdown-target": "content",
    state: "closed"
  })
end

Returns HTML attributes for the content container



8
9
10
11
12
13
14
15
# File 'app/behaviors/ui/dropdown_menu_content_behavior.rb', line 8

def dropdown_menu_content_html_attributes
  {
    class: dropdown_menu_content_classes,
    data: dropdown_menu_content_data_attributes,
    role: "menu",
    tabindex: "-1"
  }
end