x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<button type="button" class="btn" commandfor="command_dialog" command="show-modal">Open Menu</button><dialog id="command_dialog" class="dialog" style="--dialog-size: 24rem;" data-controller="dialog" data-action="click->dialog#closeOnClickOutside"> <div class="command border-0" data-controller="command" data-action="combobox-commit->command#commit"> <label class="command__input input input--actor flex items-center gap"> <span class="icon icon--search" aria-hidden="true"></span> <input type="text" name="search" id="search" data-command-target="input" data-action="command#filter" autofocus="autofocus" autocomplete="off" placeholder="Type a command or search..." /> </label> <div class="command__list" data-command-target="list" role="listbox" aria-label="Commands"> <div class="command__group" role="group" aria-labelledby="suggestions"> <span id="suggestions" class="command__group-header">Suggestions</span> <div id="3edddf4bc9493e205fd822f92652721c" class="btn command__item" data-command-target="item" data-value="calendar" data-href="#" role="option"> <span class="icon icon--calendar" aria-hidden="true"></span> <span>Calendar</span> <span class="command__item-key">⌘C</span> </div> <div id="b26659924ae1e7298e7a01802967931d" class="btn command__item" data-command-target="item" data-value="search emoji" data-href="#" role="option"> <span class="icon icon--smile" aria-hidden="true"></span> <span>Search Emoji</span> <span class="command__item-key">⌘E</span> </div> <div id="72712ef1f88ce9e5c9ee35501f41e487" class="btn command__item" data-command-target="item" data-value="calculator" data-href="#" role="option"> <span class="icon icon--calculator" aria-hidden="true"></span> <span>Calculator</span> <span class="command__item-key">⌘K</span> </div> <div id="faa80bf7254be63c96ca8c8206b61dbc" class="btn command__item" data-command-target="item" data-value="profile" data-href="#" role="option"> <span class="icon icon--user" aria-hidden="true"></span> <span>Profile</span> <span class="command__item-key">⌘P</span> </div> <div id="e4891f96cb18f5f2becb187d31da8be3" class="btn command__item" data-command-target="item" data-value="billing" data-href="#" role="option"> <span class="icon icon--credit-card" aria-hidden="true"></span> <span>Billing</span> <span class="command__item-key">⌘B</span> </div> <div id="9bf96d439f4cbbbca34829cac2cafa9a" class="btn command__item" data-command-target="item" data-value="settings" data-href="#" role="option"> <span class="icon icon--settings" aria-hidden="true"></span> <span>Settings</span> <span class="command__item-key">⌘S</span> </div> </div> <div class="command__group" role="group" aria-labelledby="tools"> <span id="tools" class="command__group-header">Tools</span> <div id="1ee91d3797d8b65c05f2b0545c9d3c66" class="btn command__item" data-command-target="item" data-value="calendar" data-href="#" role="option"> <span class="icon icon--calendar" aria-hidden="true"></span> <span>Calendar</span> <span class="command__item-key">⌘C</span> </div> <div id="ded3da91a5b1f450b608b77e69df5b49" class="btn command__item" data-command-target="item" data-value="search emoji" data-href="#" role="option"> <span class="icon icon--smile" aria-hidden="true"></span> <span>Search Emoji</span> <span class="command__item-key">⌘E</span> </div> <div id="69bed482cb14ab490f52890d7f78e570" class="btn command__item" data-command-target="item" data-value="calculator" data-href="#" role="option"> <span class="icon icon--calculator" aria-hidden="true"></span> <span>Calculator</span> <span class="command__item-key">⌘K</span> </div> <div id="718fa6fae747c14e199e8c8173f4f7b2" class="btn command__item" data-command-target="item" data-value="profile" data-href="#" role="option"> <span class="icon icon--user" aria-hidden="true"></span> <span>Profile</span> <span class="command__item-key">⌘P</span> </div> <div id="8b8a5c92b2cfa3943617a046f576b43d" class="btn command__item" data-command-target="item" data-value="billing" data-href="#" role="option"> <span class="icon icon--credit-card" aria-hidden="true"></span> <span>Billing</span> <span class="command__item-key">⌘B</span> </div> <div id="22d5849b34f2f84e38b81f7c73cca178" class="btn command__item" data-command-target="item" data-value="settings" data-href="#" role="option"> <span class="icon icon--settings" aria-hidden="true"></span> <span>Settings</span> <span class="command__item-key">⌘S</span> </div> </div> <div class="command__group" role="group" aria-labelledby="account"> <span id="account" class="command__group-header">Account</span> <div id="ba59367e57851f9e21e1af135d9e5466" class="btn command__item" data-command-target="item" data-value="calendar" data-href="#" role="option"> <span class="icon icon--calendar" aria-hidden="true"></span> <span>Calendar</span> <span class="command__item-key">⌘C</span> </div> <div id="ea26e32a6618b8380a61ca9f7fdd3bd3" class="btn command__item" data-command-target="item" data-value="search emoji" data-href="#" role="option"> <span class="icon icon--smile" aria-hidden="true"></span> <span>Search Emoji</span> <span class="command__item-key">⌘E</span> </div> <div id="4c5c3f9e4d6e131da298b5f22f8fdd8d" class="btn command__item" data-command-target="item" data-value="calculator" data-href="#" role="option"> <span class="icon icon--calculator" aria-hidden="true"></span> <span>Calculator</span> <span class="command__item-key">⌘K</span> </div> <div id="f1ee19f244d0da30ca032fccd48a6dca" class="btn command__item" data-command-target="item" data-value="profile" data-href="#" role="option"> <span class="icon icon--user" aria-hidden="true"></span> <span>Profile</span> <span class="command__item-key">⌘P</span> </div> <div id="18c75cf6f1eb5275ba4529eb67b849e9" class="btn command__item" data-command-target="item" data-value="billing" data-href="#" role="option"> <span class="icon icon--credit-card" aria-hidden="true"></span> <span>Billing</span> <span class="command__item-key">⌘B</span> </div> <div id="43cee8a5132c26feb23c41b1bd495b07" class="btn command__item" data-command-target="item" data-value="settings" data-href="#" role="option"> <span class="icon icon--settings" aria-hidden="true"></span> <span>Settings</span> <span class="command__item-key">⌘S</span> </div> </div> <div class="command__group" role="group" aria-labelledby="more"> <span id="more" class="command__group-header">More</span> <div id="b4748e44be3875a717c1b9cc78220044" class="btn command__item" data-command-target="item" data-value="calendar" data-href="#" role="option"> <span class="icon icon--calendar" aria-hidden="true"></span> <span>Calendar</span> <span class="command__item-key">⌘C</span> </div> <div id="5fad532abea36054b63d50ddacfe89b3" class="btn command__item" data-command-target="item" data-value="search emoji" data-href="#" role="option"> <span class="icon icon--smile" aria-hidden="true"></span> <span>Search Emoji</span> <span class="command__item-key">⌘E</span> </div> <div id="9f1f280eb0bfd6e5984ccbfb7c30d434" class="btn command__item" data-command-target="item" data-value="calculator" data-href="#" role="option"> <span class="icon icon--calculator" aria-hidden="true"></span> <span>Calculator</span> <span class="command__item-key">⌘K</span> </div> <div id="33b1fcdf579dca0e4f1d6d09773ba92e" class="btn command__item" data-command-target="item" data-value="profile" data-href="#" role="option"> <span class="icon icon--user" aria-hidden="true"></span> <span>Profile</span> <span class="command__item-key">⌘P</span> </div> <div id="dcabd62a1f08e354ff6fbf406027e2cd" class="btn command__item" data-command-target="item" data-value="billing" data-href="#" role="option"> <span class="icon icon--credit-card" aria-hidden="true"></span> <span>Billing</span> <span class="command__item-key">⌘B</span> </div> <div id="5fe4f94e222f915b1fc78b83e9423c3d" class="btn command__item" data-command-target="item" data-value="settings" data-href="#" role="option"> <span class="icon icon--settings" aria-hidden="true"></span> <span>Settings</span> <span class="command__item-key">⌘S</span> </div> </div> </div> </div></dialog>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<% items = [ [ "icon--calendar", "Calendar", "⌘C" ], [ "icon--smile", "Search Emoji", "⌘E" ], [ "icon--calculator", "Calculator", "⌘K" ], [ "icon--user", "Profile", "⌘P" ], [ "icon--credit-card", "Billing", "⌘B" ], [ "icon--settings", "Settings", "⌘S" ] ] %><button type="button" class="btn" commandfor="command_dialog" command="show-modal">Open Menu</button><dialog id="command_dialog" class="dialog" style="--dialog-size: 24rem;" data-controller="dialog" data-action="click->dialog#closeOnClickOutside"> <div class="command border-0" data-controller="command" data-action="combobox-commit->command#commit"> <label class="command__input input input--actor flex items-center gap"> <span class="icon icon--search" aria-hidden="true"></span> <%= text_field_tag "search", nil, data: { command_target: "input", action: "command#filter" }, autofocus: true, autocomplete: "off", placeholder: "Type a command or search..." %> </label> <div class="command__list" data-command-target="list" role="listbox" aria-label="Commands"> <% %w[ Suggestions Tools Account More ].each do |heading| %> <%= tag.div class: "command__group", role: "group", aria: { labelledby: heading.downcase } do %> <%= tag.span heading, id: heading.downcase, class: "command__group-header" %> <% items.each do |icon, label, shortcut| %> <%= tag.div id: SecureRandom.hex, class: "btn command__item", data: { command_target: "item", value: label.downcase, href: "#" }, role: "option" do %> <%= tag.span class: "icon #{icon}", aria: { hidden: true } %> <%= tag.span label %> <%= tag.span shortcut, class: "command__item-key" %> <% end %> <% end %> <% end %> <% end %> </div> </div></dialog>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
.command { background-color: var(--color-surface); border-radius: var(--rounded-xl); border-width: var(--border); box-shadow: var(--shadow-xs); display: flex; padding: var(--size-2); flex-direction: column;}.command__input { --input-background: var(--color-border-light); --input-box-shadow: none; --input-outline-size: 0;}.command__list { max-block-size: 300px; overflow-y: auto; &:not(:has(.command__item:not([hidden]))) { display: none; }}.command__group { display: flex; flex-direction: column; padding-block: var(--size-1); row-gap: 1px; &:not(:has(.command__item:not([hidden]))) { display: none; }}.command__group-header { color: var(--color-text-subtle); font-size: var(--text-xs); font-weight: var(--font-medium); padding: var(--size-1) var(--size-1_5);}.command__item { --btn-border-color: transparent; --btn-box-shadow: none; --btn-font-weight: var(--font-normal); --btn-justify-content: start; --btn-outline-size: 0; --btn-padding: var(--size-1) var(--size-1_5); --btn-radius: var(--rounded-sm); &[aria-selected="true"] { --btn-background: var(--color-border-light); }}.command__item-key { color: var(--color-text-subtle); font-size: var(--text-xs); letter-spacing: var(--tracking-widest); margin-inline-start: auto;}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Controller } from "@hotwired/stimulus"import Combobox from "https://esm.sh/@github/combobox-nav@3.0.1?standalone"import debounce from "https://esm.sh/just-debounce-it@3.2.0?standalone"export default class extends Controller { static targets = [ "input", "list", "item" ] initialize() { this.filter = debounce(this.filter.bind(this), 100) } connect() { this.combobox = new Combobox(this.inputTarget, this.listTarget) this.combobox.start() } disconnect() { this.combobox.destroy() } filter({ target }) { this.itemTargets.forEach(it => this.#matches(it.dataset.value, target.value) ? it.removeAttribute("hidden") : it.toggleAttribute("hidden", true)) } commit({ target }) { Turbo.visit(target.dataset.href, { action: "advance" }) } #matches(text, potentialMatch) { return text.toLowerCase().includes(potentialMatch.toLowerCase()) }}