@noctuatech/uswds 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/flags/alabama.svg +5 -0
- package/assets/flags/alaska.svg +14 -0
- package/assets/flags/arizona.svg +7 -0
- package/assets/flags/arkansas.svg +15 -0
- package/assets/flags/california.svg +8 -0
- package/assets/flags/colorado.svg +8 -0
- package/assets/flags/connecticut.svg +5 -0
- package/assets/flags/delaware.svg +7 -0
- package/assets/flags/florida.svg +5 -0
- package/assets/flags/georgia.svg +5 -0
- package/assets/flags/hawaii.svg +19 -0
- package/assets/flags/idaho.svg +5 -0
- package/assets/flags/illinois.svg +5 -0
- package/assets/flags/indiana.svg +15 -0
- package/assets/flags/iowa.svg +13 -0
- package/assets/flags/kansas.svg +5 -0
- package/assets/flags/kentucky.svg +16 -0
- package/assets/flags/louisiana.svg +14 -0
- package/assets/flags/maine.svg +12 -0
- package/assets/flags/maryland.svg +14 -0
- package/assets/flags/massachusetts.svg +15 -0
- package/assets/flags/michigan.svg +5 -0
- package/assets/flags/minnesota.svg +15 -0
- package/assets/flags/mississippi.svg +10 -0
- package/assets/flags/missouri.svg +16 -0
- package/assets/flags/montana.svg +11 -0
- package/assets/flags/nebraska.svg +13 -0
- package/assets/flags/nevada.svg +14 -0
- package/assets/flags/new_hampshire.svg +13 -0
- package/assets/flags/new_jersey.svg +13 -0
- package/assets/flags/new_mexico.svg +7 -0
- package/assets/flags/new_york.svg +13 -0
- package/assets/flags/north_carolina.svg +5 -0
- package/assets/flags/north_dakota.svg +13 -0
- package/assets/flags/ohio.svg +16 -0
- package/assets/flags/oklahoma.svg +12 -0
- package/assets/flags/oregon.svg +13 -0
- package/assets/flags/pennsylvania.svg +15 -0
- package/assets/flags/rhode_island.svg +13 -0
- package/assets/flags/south_carolina.svg +11 -0
- package/assets/flags/south_dakota.svg +15 -0
- package/assets/flags/tennessee.svg +13 -0
- package/assets/flags/texas.svg +8 -0
- package/assets/flags/utah.svg +9 -0
- package/assets/flags/vermont.svg +13 -0
- package/assets/flags/virginia.svg +5 -0
- package/assets/flags/washington.svg +5 -0
- package/assets/flags/west_virginia.svg +24 -0
- package/assets/flags/wisconsin.svg +5 -0
- package/assets/flags/wyoming.svg +5 -0
- package/package.json +1 -1
- package/src/lib/combo-box/combo-box-option/combo-box-option.element.ts +31 -13
- package/src/lib/combo-box/combo-box.element.ts +35 -31
- package/src/lib/combo-box/combo-box.stories.ts +205 -51
- package/src/lib/combo-box/combo-box.test.ts +17 -7
- package/target/lib/combo-box/combo-box-option/combo-box-option.element.d.ts +0 -1
- package/target/lib/combo-box/combo-box-option/combo-box-option.element.js +28 -12
- package/target/lib/combo-box/combo-box-option/combo-box-option.element.js.map +1 -1
- package/target/lib/combo-box/combo-box.element.d.ts +1 -1
- package/target/lib/combo-box/combo-box.element.js +28 -31
- package/target/lib/combo-box/combo-box.element.js.map +1 -1
- package/target/lib/combo-box/combo-box.stories.js +205 -51
- package/target/lib/combo-box/combo-box.stories.js.map +1 -1
- package/target/lib/combo-box/combo-box.test.js +7 -7
- package/target/lib/combo-box/combo-box.test.js.map +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg width="24" height="16" viewBox="0 0 24 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
3
|
+
<rect width="24" height="16" fill="#FFFFFF"/>
|
|
4
|
+
<rect x="0" y="0" width="24" height="16" fill="#002868"/>
|
|
5
|
+
|
|
6
|
+
<!-- State seal circle -->
|
|
7
|
+
<circle cx="12" cy="8" r="6" fill="#FFFFFF"/>
|
|
8
|
+
<circle cx="12" cy="8" r="5" fill="#002868"/>
|
|
9
|
+
|
|
10
|
+
<!-- Rhododendron flowers -->
|
|
11
|
+
<circle cx="8" cy="6" r="1" fill="#FFFFFF"/>
|
|
12
|
+
<circle cx="16" cy="6" r="1" fill="#FFFFFF"/>
|
|
13
|
+
<circle cx="8" cy="10" r="1" fill="#FFFFFF"/>
|
|
14
|
+
<circle cx="16" cy="10" r="1" fill="#FFFFFF"/>
|
|
15
|
+
<circle cx="12" cy="8" r="1" fill="#FFFFFF"/>
|
|
16
|
+
|
|
17
|
+
<!-- Crossed rifles -->
|
|
18
|
+
<path d="M10 6L14 10" stroke="#FFFFFF" stroke-width="1"/>
|
|
19
|
+
<path d="M14 6L10 10" stroke="#FFFFFF" stroke-width="1"/>
|
|
20
|
+
|
|
21
|
+
<!-- Mining tools -->
|
|
22
|
+
<path d="M8 8L16 8" stroke="#FFFFFF" stroke-width="1"/>
|
|
23
|
+
<path d="M12 6L12 10" stroke="#FFFFFF" stroke-width="1"/>
|
|
24
|
+
</svg>
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { inject, injectable } from "@joist/di";
|
|
2
|
-
import { attr, css, element, html } from "@joist/element";
|
|
2
|
+
import { attr, css, element, html, query } from "@joist/element";
|
|
3
3
|
|
|
4
4
|
import { COMBO_BOX_CTX } from "../context.js";
|
|
5
5
|
|
|
@@ -9,42 +9,60 @@ declare global {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
const template = document.createElement("template");
|
|
13
|
+
|
|
14
|
+
template.innerHTML = /*html*/ `
|
|
15
|
+
<li tabindex="-1" role="option">
|
|
16
|
+
<slot></slot>
|
|
17
|
+
</li>
|
|
18
|
+
`;
|
|
19
|
+
|
|
12
20
|
@injectable({
|
|
13
21
|
name: "usa-combo-box-option-ctx",
|
|
14
22
|
})
|
|
15
23
|
@element({
|
|
16
24
|
tagName: "usa-combo-box-option",
|
|
17
|
-
shadowDom: [
|
|
25
|
+
shadowDom: [
|
|
26
|
+
css`
|
|
27
|
+
:host {
|
|
28
|
+
display: flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
gap: 0.5rem;
|
|
31
|
+
padding: 0.5rem;
|
|
32
|
+
}
|
|
33
|
+
`,
|
|
34
|
+
html`<slot></slot>`,
|
|
35
|
+
],
|
|
18
36
|
})
|
|
19
37
|
export class USAComboBoxOptionElement extends HTMLElement {
|
|
20
38
|
@attr()
|
|
21
39
|
accessor value = "";
|
|
22
40
|
|
|
23
|
-
#
|
|
41
|
+
#listItem = template.content.cloneNode(true) as HTMLLIElement;
|
|
42
|
+
#li = query("li", this.#listItem);
|
|
43
|
+
#slot = query("slot", this.#listItem);
|
|
24
44
|
#ctx = inject(COMBO_BOX_CTX);
|
|
25
45
|
|
|
26
|
-
|
|
27
|
-
|
|
46
|
+
attributeChangedCallback() {
|
|
47
|
+
const value = this.value.split(" ").join("-").toLocaleLowerCase();
|
|
28
48
|
|
|
29
|
-
this.#li.
|
|
30
|
-
|
|
49
|
+
this.#li().dataset.value = this.value;
|
|
50
|
+
this.#slot().name = value;
|
|
31
51
|
|
|
32
|
-
|
|
33
|
-
this.#li.dataset.value = this.value;
|
|
34
|
-
this.#li.textContent = this.value;
|
|
52
|
+
this.slot = value;
|
|
35
53
|
}
|
|
36
54
|
|
|
37
55
|
connectedCallback() {
|
|
38
56
|
const ctx = this.#ctx();
|
|
39
57
|
|
|
40
|
-
ctx.addOption(this.#li);
|
|
58
|
+
ctx.addOption(this.#li());
|
|
41
59
|
}
|
|
42
60
|
|
|
43
61
|
disconnectedCallback() {
|
|
44
62
|
const ctx = this.#ctx();
|
|
45
63
|
|
|
46
|
-
ctx.removeOption(this.#li);
|
|
64
|
+
ctx.removeOption(this.#li());
|
|
47
65
|
|
|
48
|
-
this.#li.remove();
|
|
66
|
+
this.#li().remove();
|
|
49
67
|
}
|
|
50
68
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { injectable } from "@joist/di";
|
|
2
2
|
import { css, element, html, listen, query } from "@joist/element";
|
|
3
|
+
|
|
3
4
|
import { COMBO_BOX_CTX, type ComboBoxContainer } from "./context.js";
|
|
4
5
|
|
|
5
6
|
declare global {
|
|
@@ -17,6 +18,8 @@ declare global {
|
|
|
17
18
|
shadowDom: [
|
|
18
19
|
css`
|
|
19
20
|
:host {
|
|
21
|
+
--usa-combo-max-height: 12.5em;
|
|
22
|
+
|
|
20
23
|
display: block;
|
|
21
24
|
max-width: 30rem;
|
|
22
25
|
position: relative;
|
|
@@ -31,7 +34,7 @@ declare global {
|
|
|
31
34
|
transform: translateY(100%);
|
|
32
35
|
margin: 0;
|
|
33
36
|
border: 1px solid rgb(92, 92, 92);
|
|
34
|
-
max-height:
|
|
37
|
+
max-height: var(--usa-combo-max-height);
|
|
35
38
|
overflow-y: scroll;
|
|
36
39
|
overflow-x: visible;
|
|
37
40
|
z-index: 1001;
|
|
@@ -47,7 +50,6 @@ declare global {
|
|
|
47
50
|
border-bottom: 1px solid #e6e6e6;
|
|
48
51
|
cursor: pointer;
|
|
49
52
|
display: block;
|
|
50
|
-
padding: 0.5rem;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
ul li:hover {
|
|
@@ -61,7 +63,7 @@ declare global {
|
|
|
61
63
|
`,
|
|
62
64
|
html`
|
|
63
65
|
<slot name="input"></slot>
|
|
64
|
-
<ul tabindex="-1"></ul>
|
|
66
|
+
<ul tabindex="-1" role="listbox"></ul>
|
|
65
67
|
`,
|
|
66
68
|
],
|
|
67
69
|
})
|
|
@@ -86,19 +88,19 @@ export class USAComboBoxElement
|
|
|
86
88
|
this.#allListItems.delete(el);
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
@listen("
|
|
90
|
-
onFocusIn(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
}
|
|
91
|
+
@listen("focus", (host) => host.input())
|
|
92
|
+
onFocusIn() {
|
|
93
|
+
this.currentItemEl = null;
|
|
94
|
+
|
|
95
|
+
const list = this.list();
|
|
96
|
+
|
|
97
|
+
const fragment = document.createDocumentFragment();
|
|
98
|
+
|
|
99
|
+
for (const item of this.#allListItems) {
|
|
100
|
+
fragment.append(item);
|
|
101
101
|
}
|
|
102
|
+
|
|
103
|
+
list.replaceChildren(fragment);
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
@listen("input", (host) => host)
|
|
@@ -108,17 +110,17 @@ export class USAComboBoxElement
|
|
|
108
110
|
|
|
109
111
|
this.currentItemEl = null;
|
|
110
112
|
|
|
113
|
+
const fragment = document.createDocumentFragment();
|
|
114
|
+
|
|
111
115
|
for (const item of this.#allListItems) {
|
|
112
116
|
if (
|
|
113
117
|
item.dataset.value?.toLowerCase().startsWith(input.value.toLowerCase())
|
|
114
118
|
) {
|
|
115
|
-
|
|
116
|
-
list.append(item);
|
|
117
|
-
}
|
|
118
|
-
} else {
|
|
119
|
-
item.remove();
|
|
119
|
+
fragment.append(item);
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
+
|
|
123
|
+
list.replaceChildren(fragment);
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
@listen("focusout")
|
|
@@ -127,7 +129,7 @@ export class USAComboBoxElement
|
|
|
127
129
|
// This needs to be in a timeout so that it runs as part of the next loop.
|
|
128
130
|
// the active element will not be set until after all of the focus and blur events are done
|
|
129
131
|
if (!this.contains(document.activeElement)) {
|
|
130
|
-
this.list({
|
|
132
|
+
this.list({ innerHTML: "" });
|
|
131
133
|
this.currentItemEl = null;
|
|
132
134
|
}
|
|
133
135
|
}, 0);
|
|
@@ -196,23 +198,25 @@ export class USAComboBoxElement
|
|
|
196
198
|
selectionEnd: value.length,
|
|
197
199
|
}).focus();
|
|
198
200
|
|
|
199
|
-
this.list({
|
|
201
|
+
this.list({ innerHTML: "" });
|
|
200
202
|
}
|
|
201
203
|
|
|
202
204
|
@listen("click")
|
|
203
205
|
onClick(e: MouseEvent) {
|
|
204
|
-
if (e.target instanceof
|
|
205
|
-
const value = e.target.
|
|
206
|
+
if (e.target instanceof HTMLElement) {
|
|
207
|
+
const value = e.target.getAttribute("value");
|
|
206
208
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
if (value) {
|
|
210
|
+
this.input({
|
|
211
|
+
value,
|
|
212
|
+
selectionStart: value.length,
|
|
213
|
+
selectionEnd: value.length,
|
|
214
|
+
}).focus();
|
|
212
215
|
|
|
213
|
-
|
|
216
|
+
this.list({ innerHTML: "" });
|
|
214
217
|
|
|
215
|
-
|
|
218
|
+
this.currentItemEl = null;
|
|
219
|
+
}
|
|
216
220
|
}
|
|
217
221
|
}
|
|
218
222
|
}
|
|
@@ -10,61 +10,215 @@ const meta = {
|
|
|
10
10
|
render() {
|
|
11
11
|
return html`
|
|
12
12
|
<usa-combo-box>
|
|
13
|
-
<usa-input
|
|
13
|
+
<usa-input
|
|
14
|
+
placeholder="Select a state"
|
|
15
|
+
name="state"
|
|
16
|
+
slot="input"
|
|
17
|
+
autocomplete="off"
|
|
18
|
+
detail="sfx">
|
|
14
19
|
States
|
|
15
20
|
<usa-icon slot="detail" icon="expand_more"></usa-icon>
|
|
16
21
|
</usa-input>
|
|
17
22
|
|
|
18
|
-
<usa-combo-box-option value="Alabama"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
<usa-combo-box-option value="
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
<usa-combo-box-option value="
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<usa-combo-box-option value="
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<usa-combo-box-option value="
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<usa-combo-box-option value="
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
<usa-combo-box-option value="
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
<usa-combo-box-option value="
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
<usa-combo-box-option value="
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
<usa-combo-box-option value="
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
<usa-combo-box-option value="
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
<usa-combo-box-option value="
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
<usa-combo-box-option value="
|
|
67
|
-
|
|
23
|
+
<usa-combo-box-option value="Alabama">
|
|
24
|
+
<img src="/assets/flags/alabama.svg" alt="Alabama" height="20" /> Alabama
|
|
25
|
+
</usa-combo-box-option>
|
|
26
|
+
|
|
27
|
+
<usa-combo-box-option value="Alaska">
|
|
28
|
+
<img src="/assets/flags/alaska.svg" alt="Alaska" height="20" /> Alaska
|
|
29
|
+
</usa-combo-box-option>
|
|
30
|
+
|
|
31
|
+
<usa-combo-box-option value="Arizona">
|
|
32
|
+
<img src="/assets/flags/arizona.svg" alt="Arizona" height="20" /> Arizona
|
|
33
|
+
</usa-combo-box-option>
|
|
34
|
+
|
|
35
|
+
<usa-combo-box-option value="Arkansas">
|
|
36
|
+
<img src="/assets/flags/arkansas.svg" alt="Arkansas" height="20" /> Arkansas
|
|
37
|
+
</usa-combo-box-option>
|
|
38
|
+
|
|
39
|
+
<usa-combo-box-option value="California">
|
|
40
|
+
<img src="/assets/flags/california.svg" alt="California" height="20" /> California
|
|
41
|
+
</usa-combo-box-option>
|
|
42
|
+
|
|
43
|
+
<usa-combo-box-option value="Colorado">
|
|
44
|
+
<img src="/assets/flags/colorado.svg" alt="Colorado" height="20" /> Colorado
|
|
45
|
+
</usa-combo-box-option>
|
|
46
|
+
|
|
47
|
+
<usa-combo-box-option value="Connecticut">
|
|
48
|
+
<img src="/assets/flags/connecticut.svg" alt="Connecticut" height="20" /> Connecticut
|
|
49
|
+
</usa-combo-box-option>
|
|
50
|
+
|
|
51
|
+
<usa-combo-box-option value="Delaware">
|
|
52
|
+
<img src="/assets/flags/delaware.svg" alt="Delaware" height="20" /> Delaware
|
|
53
|
+
</usa-combo-box-option>
|
|
54
|
+
|
|
55
|
+
<usa-combo-box-option value="Florida">
|
|
56
|
+
<img src="/assets/flags/florida.svg" alt="Florida" height="20" /> Florida
|
|
57
|
+
</usa-combo-box-option>
|
|
58
|
+
|
|
59
|
+
<usa-combo-box-option value="Georgia">
|
|
60
|
+
<img src="/assets/flags/georgia.svg" alt="Georgia" height="20" /> Georgia
|
|
61
|
+
</usa-combo-box-option>
|
|
62
|
+
|
|
63
|
+
<usa-combo-box-option value="Hawaii">
|
|
64
|
+
<img src="/assets/flags/hawaii.svg" alt="Hawaii" height="20" /> Hawaii
|
|
65
|
+
</usa-combo-box-option>
|
|
66
|
+
|
|
67
|
+
<usa-combo-box-option value="Idaho">
|
|
68
|
+
<img src="/assets/flags/idaho.svg" alt="Idaho" height="20" /> Idaho
|
|
69
|
+
</usa-combo-box-option>
|
|
70
|
+
|
|
71
|
+
<usa-combo-box-option value="Illinois">
|
|
72
|
+
<img src="/assets/flags/illinois.svg" alt="Illinois" height="20" /> Illinois
|
|
73
|
+
</usa-combo-box-option>
|
|
74
|
+
|
|
75
|
+
<usa-combo-box-option value="Indiana">
|
|
76
|
+
<img src="/assets/flags/indiana.svg" alt="Indiana" height="20" /> Indiana
|
|
77
|
+
</usa-combo-box-option>
|
|
78
|
+
|
|
79
|
+
<usa-combo-box-option value="Iowa">
|
|
80
|
+
<img src="/assets/flags/iowa.svg" alt="Iowa" height="20" /> Iowa
|
|
81
|
+
</usa-combo-box-option>
|
|
82
|
+
|
|
83
|
+
<usa-combo-box-option value="Kansas">
|
|
84
|
+
<img src="/assets/flags/kansas.svg" alt="Kansas" height="20" /> Kansas
|
|
85
|
+
</usa-combo-box-option>
|
|
86
|
+
|
|
87
|
+
<usa-combo-box-option value="Kentucky">
|
|
88
|
+
<img src="/assets/flags/kentucky.svg" alt="Kentucky" height="20" /> Kentucky
|
|
89
|
+
</usa-combo-box-option>
|
|
90
|
+
|
|
91
|
+
<usa-combo-box-option value="Louisiana">
|
|
92
|
+
<img src="/assets/flags/louisiana.svg" alt="Louisiana" height="20" /> Louisiana
|
|
93
|
+
</usa-combo-box-option>
|
|
94
|
+
|
|
95
|
+
<usa-combo-box-option value="Maine">
|
|
96
|
+
<img src="/assets/flags/maine.svg" alt="Maine" height="20" /> Maine
|
|
97
|
+
</usa-combo-box-option>
|
|
98
|
+
|
|
99
|
+
<usa-combo-box-option value="Maryland">
|
|
100
|
+
<img src="/assets/flags/maryland.svg" alt="Maryland" height="20" /> Maryland
|
|
101
|
+
</usa-combo-box-option>
|
|
102
|
+
|
|
103
|
+
<usa-combo-box-option value="Massachusetts">
|
|
104
|
+
<img src="/assets/flags/massachusetts.svg" alt="Massachusetts" height="20" /> Massachusetts
|
|
105
|
+
</usa-combo-box-option>
|
|
106
|
+
|
|
107
|
+
<usa-combo-box-option value="Michigan">
|
|
108
|
+
<img src="/assets/flags/michigan.svg" alt="Michigan" height="20" /> Michigan
|
|
109
|
+
</usa-combo-box-option>
|
|
110
|
+
|
|
111
|
+
<usa-combo-box-option value="Minnesota">
|
|
112
|
+
<img src="/assets/flags/minnesota.svg" alt="Minnesota" height="20" /> Minnesota
|
|
113
|
+
</usa-combo-box-option>
|
|
114
|
+
|
|
115
|
+
<usa-combo-box-option value="Mississippi">
|
|
116
|
+
<img src="/assets/flags/mississippi.svg" alt="Mississippi" height="20" /> Mississippi
|
|
117
|
+
</usa-combo-box-option>
|
|
118
|
+
|
|
119
|
+
<usa-combo-box-option value="Missouri">
|
|
120
|
+
<img src="/assets/flags/missouri.svg" alt="Missouri" height="20" /> Missouri
|
|
121
|
+
</usa-combo-box-option>
|
|
122
|
+
|
|
123
|
+
<usa-combo-box-option value="Montana">
|
|
124
|
+
<img src="/assets/flags/montana.svg" alt="Montana" height="20" /> Montana
|
|
125
|
+
</usa-combo-box-option>
|
|
126
|
+
|
|
127
|
+
<usa-combo-box-option value="Nebraska">
|
|
128
|
+
<img src="/assets/flags/nebraska.svg" alt="Nebraska" height="20" /> Nebraska
|
|
129
|
+
</usa-combo-box-option>
|
|
130
|
+
|
|
131
|
+
<usa-combo-box-option value="Nevada">
|
|
132
|
+
<img src="/assets/flags/nevada.svg" alt="Nevada" height="20" /> Nevada
|
|
133
|
+
</usa-combo-box-option>
|
|
134
|
+
|
|
135
|
+
<usa-combo-box-option value="New Hampshire">
|
|
136
|
+
<img src="/assets/flags/new_hampshire.svg" alt="New Hampshire" height="20" /> New Hampshire
|
|
137
|
+
</usa-combo-box-option>
|
|
138
|
+
|
|
139
|
+
<usa-combo-box-option value="New Jersey">
|
|
140
|
+
<img src="/assets/flags/new_jersey.svg" alt="New Jersey" height="20" /> New Jersey
|
|
141
|
+
</usa-combo-box-option>
|
|
142
|
+
|
|
143
|
+
<usa-combo-box-option value="New Mexico">
|
|
144
|
+
<img src="/assets/flags/new_mexico.svg" alt="New Mexico" height="20" /> New Mexico
|
|
145
|
+
</usa-combo-box-option>
|
|
146
|
+
|
|
147
|
+
<usa-combo-box-option value="New York">
|
|
148
|
+
<img src="/assets/flags/new_york.svg" alt="New York" height="20" /> New York
|
|
149
|
+
</usa-combo-box-option>
|
|
150
|
+
|
|
151
|
+
<usa-combo-box-option value="North Carolina">
|
|
152
|
+
<img src="/assets/flags/north_carolina.svg" alt="North Carolina" height="20" /> North Carolina
|
|
153
|
+
</usa-combo-box-option>
|
|
154
|
+
|
|
155
|
+
<usa-combo-box-option value="North Dakota">
|
|
156
|
+
<img src="/assets/flags/north_dakota.svg" alt="North Dakota" height="20" /> North Dakota
|
|
157
|
+
</usa-combo-box-option>
|
|
158
|
+
|
|
159
|
+
<usa-combo-box-option value="Ohio">
|
|
160
|
+
<img src="/assets/flags/ohio.svg" alt="Ohio" height="20" /> Ohio
|
|
161
|
+
</usa-combo-box-option>
|
|
162
|
+
|
|
163
|
+
<usa-combo-box-option value="Oklahoma">
|
|
164
|
+
<img src="/assets/flags/oklahoma.svg" alt="Oklahoma" height="20" /> Oklahoma
|
|
165
|
+
</usa-combo-box-option>
|
|
166
|
+
|
|
167
|
+
<usa-combo-box-option value="Oregon">
|
|
168
|
+
<img src="/assets/flags/oregon.svg" alt="Oregon" height="20" /> Oregon
|
|
169
|
+
</usa-combo-box-option>
|
|
170
|
+
|
|
171
|
+
<usa-combo-box-option value="Pennsylvania">
|
|
172
|
+
<img src="/assets/flags/pennsylvania.svg" alt="Pennsylvania" height="20" /> Pennsylvania
|
|
173
|
+
</usa-combo-box-option>
|
|
174
|
+
|
|
175
|
+
<usa-combo-box-option value="Rhode Island">
|
|
176
|
+
<img src="/assets/flags/rhode_island.svg" alt="Rhode Island" height="20" /> Rhode Island
|
|
177
|
+
</usa-combo-box-option>
|
|
178
|
+
|
|
179
|
+
<usa-combo-box-option value="South Carolina">
|
|
180
|
+
<img src="/assets/flags/south_carolina.svg" alt="South Carolina" height="20" /> South Carolina
|
|
181
|
+
</usa-combo-box-option>
|
|
182
|
+
|
|
183
|
+
<usa-combo-box-option value="South Dakota">
|
|
184
|
+
<img src="/assets/flags/south_dakota.svg" alt="South Dakota" height="20" /> South Dakota
|
|
185
|
+
</usa-combo-box-option>
|
|
186
|
+
|
|
187
|
+
<usa-combo-box-option value="Tennessee">
|
|
188
|
+
<img src="/assets/flags/tennessee.svg" alt="Tennessee" height="20" /> Tennessee
|
|
189
|
+
</usa-combo-box-option>
|
|
190
|
+
|
|
191
|
+
<usa-combo-box-option value="Texas">
|
|
192
|
+
<img src="/assets/flags/texas.svg" alt="Texas" height="20" /> Texas
|
|
193
|
+
</usa-combo-box-option>
|
|
194
|
+
|
|
195
|
+
<usa-combo-box-option value="Utah">
|
|
196
|
+
<img src="/assets/flags/utah.svg" alt="Utah" height="20" /> Utah
|
|
197
|
+
</usa-combo-box-option>
|
|
198
|
+
|
|
199
|
+
<usa-combo-box-option value="Vermont">
|
|
200
|
+
<img src="/assets/flags/vermont.svg" alt="Vermont" height="20" /> Vermont
|
|
201
|
+
</usa-combo-box-option>
|
|
202
|
+
|
|
203
|
+
<usa-combo-box-option value="Virginia">
|
|
204
|
+
<img src="/assets/flags/virginia.svg" alt="Virginia" height="20" /> Virginia
|
|
205
|
+
</usa-combo-box-option>
|
|
206
|
+
|
|
207
|
+
<usa-combo-box-option value="Washington">
|
|
208
|
+
<img src="/assets/flags/washington.svg" alt="Washington" height="20" /> Washington
|
|
209
|
+
</usa-combo-box-option>
|
|
210
|
+
|
|
211
|
+
<usa-combo-box-option value="West Virginia">
|
|
212
|
+
<img src="/assets/flags/west_virginia.svg" alt="West Virginia" height="20" /> West Virginia
|
|
213
|
+
</usa-combo-box-option>
|
|
214
|
+
|
|
215
|
+
<usa-combo-box-option value="Wisconsin">
|
|
216
|
+
<img src="/assets/flags/wisconsin.svg" alt="Wisconsin" height="20" /> Wisconsin
|
|
217
|
+
</usa-combo-box-option>
|
|
218
|
+
|
|
219
|
+
<usa-combo-box-option value="Wyoming">
|
|
220
|
+
<img src="/assets/flags/wyoming.svg" alt="Wyoming" height="20" /> Wyoming
|
|
221
|
+
</usa-combo-box-option>
|
|
68
222
|
</usa-combo-box>
|
|
69
223
|
`;
|
|
70
224
|
},
|
|
@@ -37,9 +37,10 @@ describe("usa-combo-box", () => {
|
|
|
37
37
|
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
38
38
|
|
|
39
39
|
const suggestions = autocomplete.listItems();
|
|
40
|
+
|
|
40
41
|
assert.equal(suggestions.length, 2);
|
|
41
|
-
assert.equal(suggestions[0].
|
|
42
|
-
assert.equal(suggestions[1].
|
|
42
|
+
assert.equal(suggestions[0].dataset.value, "Banana");
|
|
43
|
+
assert.equal(suggestions[1].dataset.value, "Blueberry");
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
it("should show all suggestions when input is empty", async () => {
|
|
@@ -56,8 +57,8 @@ describe("usa-combo-box", () => {
|
|
|
56
57
|
|
|
57
58
|
const suggestions = autocomplete.listItems();
|
|
58
59
|
assert.equal(suggestions.length, 2);
|
|
59
|
-
assert.equal(suggestions[0].
|
|
60
|
-
assert.equal(suggestions[1].
|
|
60
|
+
assert.equal(suggestions[0].dataset.value, "Banana");
|
|
61
|
+
assert.equal(suggestions[1].dataset.value, "Blueberry");
|
|
61
62
|
});
|
|
62
63
|
|
|
63
64
|
it("should navigate suggestions with arrow keys", async () => {
|
|
@@ -69,13 +70,19 @@ describe("usa-combo-box", () => {
|
|
|
69
70
|
input.dispatchEvent(
|
|
70
71
|
new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true }),
|
|
71
72
|
);
|
|
72
|
-
assert.equal(
|
|
73
|
+
assert.equal(
|
|
74
|
+
autocomplete.currentItemEl?.getAttribute("data-value"),
|
|
75
|
+
"Banana",
|
|
76
|
+
);
|
|
73
77
|
|
|
74
78
|
// Arrow down again
|
|
75
79
|
input.dispatchEvent(
|
|
76
80
|
new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true }),
|
|
77
81
|
);
|
|
78
|
-
assert.equal(
|
|
82
|
+
assert.equal(
|
|
83
|
+
autocomplete.currentItemEl?.getAttribute("data-value"),
|
|
84
|
+
"Blueberry",
|
|
85
|
+
);
|
|
79
86
|
});
|
|
80
87
|
|
|
81
88
|
it("should select suggestion with enter key", async () => {
|
|
@@ -135,6 +142,9 @@ describe("usa-combo-box", () => {
|
|
|
135
142
|
new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true }),
|
|
136
143
|
);
|
|
137
144
|
|
|
138
|
-
assert.equal(
|
|
145
|
+
assert.equal(
|
|
146
|
+
autocomplete.currentItemEl?.getAttribute("data-value"),
|
|
147
|
+
"Blueberry",
|
|
148
|
+
);
|
|
139
149
|
});
|
|
140
150
|
});
|