Class: Shadcn::Command::Group::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/command/group/component.rb

Overview

A titled run of items. cmdk renders three elements — the group, an aria-hidden heading and a role="group" wrapper named by it (vendor/cmdk/index.tsx:750-764) — and shadcn's classes select the middle one by [cmdk-group-heading], so all three are reproduced.

The whole group hides when every item in it is filtered away, which is the controller's job and the reason hidden is not a caller's argument.

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(heading: nil, **attributes) ⇒ Component

Returns a new instance of Component.



27
28
29
30
# File 'app/components/shadcn/command/group/component.rb', line 27

def initialize(heading: nil, **attributes)
  @heading = heading
  super(**attributes)
end

Instance Attribute Details

#headingObject (readonly)

Returns the value of attribute heading.



25
26
27
# File 'app/components/shadcn/command/group/component.rb', line 25

def heading
  @heading
end

Instance Method Details

#callObject



40
41
42
# File 'app/components/shadcn/command/group/component.rb', line 40

def call
  render_element(body: safe_join([ title, items ].compact))
end

#element_attributes(**defaults) ⇒ Object



32
33
34
35
36
37
38
# File 'app/components/shadcn/command/group/component.rb', line 32

def element_attributes(**defaults)
  super(**{
    "cmdk-group" => "",
    role: "presentation",
    "data-shadcn--command-target" => "group"
  }.merge(defaults))
end