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

Class Method Summary collapse

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.



16
17
18
19
20
21
22
23
24
25
# File 'lib/cmdk/group.rb', line 16

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

Class Method Details

.next_heading_idObject



12
13
14
# File 'lib/cmdk/group.rb', line 12

def self.next_heading_id
  @heading_mutex.synchronize { "cmdk-heading-#{@heading_seq += 1}" }
end

Instance Method Details

#view_template(&block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/cmdk/group.rb', line 27

def view_template(&block)
  heading_id = @heading ? Group.next_heading_id : 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, &block)
  end
end