Module: UI::TooltipTriggerBehavior

Included in:
TooltipTrigger, TooltipTriggerComponent
Defined in:
app/behaviors/ui/tooltip_trigger_behavior.rb

Overview

TooltipTriggerBehavior

Shared behavior for TooltipTrigger component. The trigger activates the tooltip on hover/focus. Supports asChild pattern for composition.

Instance Method Summary collapse

Instance Method Details

#tooltip_trigger_classesObject

Returns combined CSS classes for the trigger button



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

def tooltip_trigger_classes
  classes_value = instance_variable_defined?(:@classes) ? @classes : nil
  TailwindMerge::Merger.new.merge([
    tooltip_trigger_base_classes,
    classes_value
  ].compact.join(" "))
end

#tooltip_trigger_data_attributesObject

Returns data attributes for the tooltip trigger



38
39
40
41
42
43
44
45
46
# File 'app/behaviors/ui/tooltip_trigger_behavior.rb', line 38

def tooltip_trigger_data_attributes
  attributes_value = respond_to?(:attributes, true) ? attributes : @attributes
  base_data = attributes_value&.fetch(:data, {}) || {}

  base_data.merge({
    ui__tooltip_target: "trigger",
    action: [base_data[:action], "mouseenter->ui--tooltip#show mouseleave->ui--tooltip#hide focus->ui--tooltip#show blur->ui--tooltip#hide"].compact.join(" ")
  }).compact
end

#tooltip_trigger_html_attributesObject

Returns HTML attributes for the tooltip trigger element



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/behaviors/ui/tooltip_trigger_behavior.rb', line 12

def tooltip_trigger_html_attributes
  as_child_value = instance_variable_defined?(:@as_child) ? @as_child : false

  attrs = {
    data: tooltip_trigger_data_attributes
  }.compact

  # Only add button styling when not using asChild
  # (asChild delegates styling to the child component)
  unless as_child_value
    attrs[:class] = tooltip_trigger_classes
  end

  attrs
end