Class: ShadcnPhlexcomponents::SelectContent

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/select.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(include_blank: false, native: false, side: :bottom, align: :center, aria_id: nil, **attributes) ⇒ SelectContent

Returns a new instance of SelectContent.



259
260
261
262
263
264
265
266
# File 'lib/shadcn_phlexcomponents/components/select.rb', line 259

def initialize(include_blank: false, native: false, side: :bottom, align: :center, aria_id: nil, **attributes)
  @include_blank = include_blank
  @native = native
  @side = side
  @align = align
  @aria_id = aria_id
  super(**attributes)
end

Instance Method Details

#default_attributesObject



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/shadcn_phlexcomponents/components/select.rb', line 282

def default_attributes
  {
    id: "#{@aria_id}-content",
    tabindex: -1,
    role: "listbox",
    aria: {
      labelledby: "#{@aria_id}-trigger",
      orientation: "vertical",
    },
    data: {
      side: @side,
      align: @align,
      state: "closed",
      select_target: "content",
      action: <<~HEREDOC,
        select:click:outside->select#clickOutside
        keydown.up->select#focusItemByIndex:prevent:self
        keydown.down->select#focusItemByIndex:prevent:self
      HEREDOC
    },
  }
end

#view_templateObject



268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/shadcn_phlexcomponents/components/select.rb', line 268

def view_template(&)
  SelectContentContainer do
    div(**@attributes) do
      if @include_blank && !@native
        SelectItem(aria_id: @aria_id, value: "", class: "h-8") do
          @include_blank.is_a?(String) ? @include_blank : ""
        end
      end

      yield
    end
  end
end