Class: UI::SelectTriggerComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
SelectTriggerBehavior
Defined in:
app/view_components/ui/select_trigger_component.rb

Overview

TriggerComponent - ViewComponent implementation

Button that opens the select dropdown. Note: ViewComponent version uses template for asChild support

Examples:

Default button

<%= render UI::TriggerComponent.new(placeholder: "Select a fruit...") %>

Instance Method Summary collapse

Methods included from SelectTriggerBehavior

#select_trigger_classes, #select_trigger_html_attributes

Constructor Details

#initialize(placeholder: "Select...", classes: "", **attributes) ⇒ SelectTriggerComponent

Returns a new instance of SelectTriggerComponent.

Parameters:

  • placeholder (String) (defaults to: "Select...")

    Placeholder text when no value selected

  • classes (String) (defaults to: "")

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



16
17
18
19
20
# File 'app/view_components/ui/select_trigger_component.rb', line 16

def initialize(placeholder: "Select...", classes: "", **attributes)
  @placeholder = placeholder
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



22
23
24
25
26
# File 'app/view_components/ui/select_trigger_component.rb', line 22

def call
   :button, **select_trigger_html_attributes.deep_merge(@attributes) do
     :span, @placeholder, data: {ui__select_target: "valueDisplay"}
  end
end