Class: Cmdk::Group

Inherits:
Base
  • Object
show all
Defined in:
lib/cmdk/group.rb

Overview

Groups items together with an optional heading. Port of ‘<Command.Group>`. Provide `value:` when there is no heading (it is used for sorting groups); with a string heading the value is inferred from it, matching React cmdk.

Constant Summary

Constants inherited from Base

Base::SR_ONLY_STYLE

Instance Method Summary collapse

Constructor Details

#initialize(heading: nil, value: nil, force_mount: false, scope: nil, scope_only: false, server_filtered: false, **attributes) ⇒ Group

Returns a new instance of Group.



8
9
10
11
12
13
14
15
16
17
# File 'lib/cmdk/group.rb', line 8

def initialize(heading: nil, value: nil, force_mount: false, scope: nil, scope_only: false,
               server_filtered: false, **attributes)
  @heading = heading
  @value = value
  @force_mount = force_mount
  @scope = scope
  @scope_only = scope_only
  @server_filtered = server_filtered
  @attributes = attributes
end

Instance Method Details

#view_template(&block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cmdk/group.rb', line 19

def view_template(&block)
  heading_id = @heading ? "cmdk-heading-#{SecureRandom.hex(4)}" : nil

  div(**merged(group_attributes, @attributes)) do
    if @heading
      div('cmdk-group-heading' => '', aria_hidden: 'true', id: heading_id) { @heading }
    end
    div('cmdk-group-items' => '', role: 'group', aria_labelledby: heading_id) do
      block ? block.call : nil
    end
  end
end