-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.test.html
More file actions
33 lines (29 loc) · 1.5 KB
/
example.test.html
File metadata and controls
33 lines (29 loc) · 1.5 KB
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
<!--
==== HOW TO TEST THE FORMATTER ====
Copy this file to test.html, then run the following command in the terminal:
npx prettier --plugin ./index.mjs --write test.html
If it doesn't format, then it might be because Prettier ignores files in .gitignore.
-->
<div x-data="{ options: {{ options|default:"[]" }}, search: '{{ initial_value }}', value: '{{ initial_value }}', filteredOptions: [], activeOptionIndex: -1, expanded: false }"
@click.away="expanded = false; search = value"
@keydown.escape="expanded = false; search = value"
@keydown.arrow-up.prevent="activeOptionIndex = Math.max(activeOptionIndex - 1, 0)"
@keydown.arrow-down.prevent="activeOptionIndex = Math.min(activeOptionIndex + 1, filteredOptions.length - 1)"
@keydown.enter="if (expanded) $event.preventDefault(); value = filteredOptions[activeOptionIndex] ?? filteredOptions[0] ?? value; search = value; expanded = false"
x-model="{{ x_model }}"
x-modelable="search"
>
{% if label %}
<label for="combobox">{{ label }}</label>
{% endif %}
<div class="relative">
<input id="combobox"
type="text"
role="combobox"
aria-controls="options"
ria-expanded="false"
x-model="search"
required
@input="expanded = search.length > 0; filteredOptions = options.filter(option => option.toLowerCase().includes(search.toLowerCase())).slice(0, 5); activeOptionIndex = filteredOptions.findIndex(option => option === search)">
</div>
</div>