Module: UI::DropdownMenuCheckboxItemBehavior

Included in:
DropdownMenuCheckboxItem, DropdownMenuCheckboxItemComponent
Defined in:
app/behaviors/ui/dropdown_menu_checkbox_item_behavior.rb

Overview

DropdownMenuCheckboxItemBehavior

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

Instance Method Summary collapse

Instance Method Details

#checkbox_indicatorObject

Renders the checkbox indicator



40
41
42
43
# File 'app/behaviors/ui/dropdown_menu_checkbox_item_behavior.rb', line 40

def checkbox_indicator
  # This will be implemented in the actual components
  @checked
end

Returns combined CSS classes for the checkbox item



19
20
21
22
23
24
# File 'app/behaviors/ui/dropdown_menu_checkbox_item_behavior.rb', line 19

def dropdown_menu_checkbox_item_classes
  classes_value = respond_to?(:classes, true) ? classes : @classes
  base_classes = "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"

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

Returns data attributes for Stimulus



27
28
29
30
31
32
33
34
35
36
37
# File 'app/behaviors/ui/dropdown_menu_checkbox_item_behavior.rb', line 27

def dropdown_menu_checkbox_item_data_attributes
  attributes_value = respond_to?(:attributes, true) ? attributes : @attributes
  data_attrs = (attributes_value&.fetch(:data, {}) || {}).merge({
    "ui--dropdown-target": "item",
    action: "mouseenter->ui--dropdown#trackHoveredItem click->ui--dropdown#toggleCheckbox",
    state: @checked ? "checked" : "unchecked"
  })

  data_attrs[:disabled] = true if @disabled
  data_attrs
end

Returns HTML attributes for the checkbox item



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

def dropdown_menu_checkbox_item_html_attributes
  {
    class: dropdown_menu_checkbox_item_classes,
    data: dropdown_menu_checkbox_item_data_attributes,
    role: "menuitemcheckbox",
    "aria-checked": @checked,
    tabindex: "-1"
  }
end