Class: Cmdk::Root

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

Overview

Command menu root. Port of ‘<Command>` from cmdk.

React props map to data attributes consumed by the JS runtime: shouldFilter, loop, vimBindings, disablePointerSelection, defaultValue. ‘onValueChange` becomes a bubbling `cmdk-value-change` CustomEvent; a custom `filter` can be registered via `Cmdk.setFilter(rootEl, fn)` in JS.

‘scopes:` enables scoped search (an extension over the React API): pass scope names (`scopes: %w[user doc]`). Typing the scope-picker prefix (“/” by default, override with `scope_picker: ’:‘`, disable with `scope_picker: false`) suggests `Cmdk::Item(enters_scope:)` items; committing one — or typing the name out (“/user ”) — pins the scope as a pill before the input. The rest of the input is then matched only against items/groups tagged with the same `scope:`. Pass `active_scope:` to server-render an already-pinned scope.

Constant Summary

Constants inherited from Base

Base::SR_ONLY_STYLE

Instance Method Summary collapse

Constructor Details

#initialize(label: nil, default_value: nil, should_filter: true, loop: false, vim_bindings: true, disable_pointer_selection: false, scopes: nil, scope_picker: nil, active_scope: nil, **attributes) ⇒ Root

Returns a new instance of Root.



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

def initialize(label: nil, default_value: nil, should_filter: true, loop: false,
               vim_bindings: true, disable_pointer_selection: false, scopes: nil,
               scope_picker: nil, active_scope: nil, **attributes)
  @label = label
  @default_value = default_value
  @should_filter = should_filter
  @loop = loop
  @vim_bindings = vim_bindings
  @disable_pointer_selection = disable_pointer_selection
  @scopes = scopes
  @scope_picker = scope_picker
  @active_scope = active_scope
  @attributes = attributes
end

Instance Method Details

#view_template(&block) ⇒ Object



33
34
35
36
37
38
# File 'lib/cmdk/root.rb', line 33

def view_template(&block)
  div(**merged(root_attributes, @attributes)) do
    label('cmdk-label' => '', style: SR_ONLY_STYLE) { @label }
    block&.call
  end
end