Class: ShadcnPhlexcomponents::ComboboxItem

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/combobox.rb

Constant Summary

Constants inherited from Base

Base::SANITIZER_ALLOWED_ATTRIBUTES, Base::SANITIZER_ALLOWED_TAGS, Base::TAILWIND_MERGER

Instance Method Summary collapse

Methods inherited from Base

#before_template, #convert_collection_hash_to_struct, #find_as_child, #icon, #item_disabled?, #merge_default_attributes, #merged_as_child_attributes, #nokogiri_attributes_to_hash, #overlay, #sanitize_as_child

Constructor Details

#initialize(value: nil, disabled: false, aria_id: nil, **attributes) ⇒ ComboboxItem

Returns a new instance of ComboboxItem.



325
326
327
328
329
330
331
# File 'lib/shadcn_phlexcomponents/components/combobox.rb', line 325

def initialize(value: nil, disabled: false, aria_id: nil, **attributes)
  @value = value
  @disabled = disabled
  @aria_id = aria_id
  @aria_labelledby = "#{@aria_id}-item-#{SecureRandom.hex(5)}"
  super(**attributes)
end

Instance Method Details

#default_attributesObject



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/shadcn_phlexcomponents/components/combobox.rb', line 344

def default_attributes
  {
    role: "option",
    tabindex: -1,
    aria: {
      selected: false,
      labelledby: @aria_labelledby,
    },
    data: {
      highlighted: "false",
      disabled: @disabled,
      value: @value,
      action: <<~HEREDOC,
        click->combobox#select
        mouseover->combobox#highlightItem
      HEREDOC
      combobox_target: "item",
    },
  }
end

#view_templateObject



333
334
335
336
337
338
339
340
341
342
# File 'lib/shadcn_phlexcomponents/components/combobox.rb', line 333

def view_template(&)
  div(**@attributes) do
    span(id: @aria_labelledby, &)

    span(class: "absolute right-2 h-3.5 w-3.5 items-center hidden justify-center
                group-aria-[selected=true]/item:flex group-data-[value='']/item:hidden") do
      icon("check", class: "size-4")
    end
  end
end