Module: UI::DropdownMenuBehavior

Included in:
DropdownMenu, DropdownMenuComponent
Defined in:
app/behaviors/ui/dropdown_menu_behavior.rb

Overview

UI::DropdownMenuBehavior

Instance Method Summary collapse

Instance Method Details

Returns combined CSS classes for the dropdown menu



47
48
49
50
51
52
53
# File 'app/behaviors/ui/dropdown_menu_behavior.rb', line 47

def dropdown_menu_classes
  classes_value = respond_to?(:classes, true) ? classes : @classes
  TailwindMerge::Merger.new.merge([
    "relative inline-block text-left",
    classes_value
  ].compact.join(" "))
end

Returns data attributes for Stimulus controller



56
57
58
59
60
61
62
63
64
# File 'app/behaviors/ui/dropdown_menu_behavior.rb', line 56

def dropdown_menu_data_attributes
  attributes_value = respond_to?(:attributes, true) ? attributes : @attributes
  (attributes_value&.fetch(:data, {}) || {}).merge({
    controller: "ui--dropdown",
    "ui--dropdown-placement-value": @placement,
    "ui--dropdown-offset-value": @offset,
    "ui--dropdown-flip-value": @flip
  })
end

Returns HTML attributes for the dropdown menu container When used with asChild, these attributes will be yielded to the child



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/behaviors/ui/dropdown_menu_behavior.rb', line 32

def dropdown_menu_html_attributes
  attrs = {
    data: dropdown_menu_data_attributes
  }

  # Only add container classes if not using asChild
  # When asChild is true, we don't render a wrapper
  unless @as_child
    attrs[:class] = dropdown_menu_classes
  end

  attrs
end