@noctuatech/uswds 0.1.0 → 0.1.3

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.
Files changed (143) hide show
  1. package/assets/flags/alabama.svg +5 -0
  2. package/assets/flags/alaska.svg +14 -0
  3. package/assets/flags/arizona.svg +7 -0
  4. package/assets/flags/arkansas.svg +15 -0
  5. package/assets/flags/california.svg +8 -0
  6. package/assets/flags/colorado.svg +8 -0
  7. package/assets/flags/connecticut.svg +5 -0
  8. package/assets/flags/delaware.svg +7 -0
  9. package/assets/flags/florida.svg +5 -0
  10. package/assets/flags/georgia.svg +5 -0
  11. package/assets/flags/hawaii.svg +19 -0
  12. package/assets/flags/idaho.svg +5 -0
  13. package/assets/flags/illinois.svg +5 -0
  14. package/assets/flags/indiana.svg +15 -0
  15. package/assets/flags/iowa.svg +13 -0
  16. package/assets/flags/kansas.svg +5 -0
  17. package/assets/flags/kentucky.svg +16 -0
  18. package/assets/flags/louisiana.svg +14 -0
  19. package/assets/flags/maine.svg +12 -0
  20. package/assets/flags/maryland.svg +14 -0
  21. package/assets/flags/massachusetts.svg +15 -0
  22. package/assets/flags/michigan.svg +5 -0
  23. package/assets/flags/minnesota.svg +15 -0
  24. package/assets/flags/mississippi.svg +10 -0
  25. package/assets/flags/missouri.svg +16 -0
  26. package/assets/flags/montana.svg +11 -0
  27. package/assets/flags/nebraska.svg +13 -0
  28. package/assets/flags/nevada.svg +14 -0
  29. package/assets/flags/new_hampshire.svg +13 -0
  30. package/assets/flags/new_jersey.svg +13 -0
  31. package/assets/flags/new_mexico.svg +7 -0
  32. package/assets/flags/new_york.svg +13 -0
  33. package/assets/flags/north_carolina.svg +5 -0
  34. package/assets/flags/north_dakota.svg +13 -0
  35. package/assets/flags/ohio.svg +16 -0
  36. package/assets/flags/oklahoma.svg +12 -0
  37. package/assets/flags/oregon.svg +13 -0
  38. package/assets/flags/pennsylvania.svg +15 -0
  39. package/assets/flags/rhode_island.svg +13 -0
  40. package/assets/flags/south_carolina.svg +11 -0
  41. package/assets/flags/south_dakota.svg +15 -0
  42. package/assets/flags/tennessee.svg +13 -0
  43. package/assets/flags/texas.svg +8 -0
  44. package/assets/flags/utah.svg +9 -0
  45. package/assets/flags/vermont.svg +13 -0
  46. package/assets/flags/virginia.svg +5 -0
  47. package/assets/flags/washington.svg +5 -0
  48. package/assets/flags/west_virginia.svg +24 -0
  49. package/assets/flags/wisconsin.svg +5 -0
  50. package/assets/flags/wyoming.svg +5 -0
  51. package/package.json +13 -11
  52. package/src/lib/combo-box/combo-box-option/combo-box-option.element.ts +32 -13
  53. package/src/lib/combo-box/combo-box.element.ts +161 -43
  54. package/src/lib/combo-box/combo-box.stories.ts +202 -56
  55. package/src/lib/combo-box/combo-box.test.ts +140 -22
  56. package/target/lib/accordion/accordion.element.js +2 -86
  57. package/target/lib/accordion/accordion.stories.js +1 -26
  58. package/target/lib/accordion/accordion.test.js +5 -72
  59. package/target/lib/alert/alert.element.js +2 -71
  60. package/target/lib/alert/alert.stories.js +1 -41
  61. package/target/lib/alert/alert.test.js +1 -9
  62. package/target/lib/button/button.element.js +2 -142
  63. package/target/lib/button/button.stories.js +1 -6
  64. package/target/lib/button/button.test.js +1 -3
  65. package/target/lib/card/card-body/card-body.element.js +1 -8
  66. package/target/lib/card/card-footer/card-footer.element.js +1 -6
  67. package/target/lib/card/card-group/card-group.element.js +1 -12
  68. package/target/lib/card/card-header/card-header.element.js +1 -16
  69. package/target/lib/card/card-media/card-media.element.js +2 -33
  70. package/target/lib/card/card.element.js +1 -32
  71. package/target/lib/card/card.stories.js +2 -107
  72. package/target/lib/card/card.test.js +1 -20
  73. package/target/lib/checkbox/checkbox-group/checkbox-group.element.js +2 -10
  74. package/target/lib/checkbox/checkbox.element.js +2 -112
  75. package/target/lib/checkbox/checkbox.stories.js +2 -43
  76. package/target/lib/checkbox/checkbox.test.js +4 -28
  77. package/target/lib/collection/collection-item/collection-item.element.js +2 -40
  78. package/target/lib/collection/collection-item/collection-item.test.js +1 -3
  79. package/target/lib/collection/collection.element.js +2 -10
  80. package/target/lib/collection/collection.stories.js +1 -63
  81. package/target/lib/collection/collection.test.js +1 -3
  82. package/target/lib/combo-box/combo-box-option/combo-box-option.element.d.ts +0 -1
  83. package/target/lib/combo-box/combo-box-option/combo-box-option.element.js +21 -12
  84. package/target/lib/combo-box/combo-box-option/combo-box-option.element.js.map +1 -1
  85. package/target/lib/combo-box/combo-box.element.d.ts +9 -1
  86. package/target/lib/combo-box/combo-box.element.js +92 -86
  87. package/target/lib/combo-box/combo-box.element.js.map +1 -1
  88. package/target/lib/combo-box/combo-box.stories.js +1 -59
  89. package/target/lib/combo-box/combo-box.stories.js.map +1 -1
  90. package/target/lib/combo-box/combo-box.test.js +65 -22
  91. package/target/lib/combo-box/combo-box.test.js.map +1 -1
  92. package/target/lib/config/config.element.js +1 -5
  93. package/target/lib/config/config.test.js +1 -3
  94. package/target/lib/description/description.element.js +1 -7
  95. package/target/lib/description/description.test.js +1 -3
  96. package/target/lib/file-input/file-input-preview/file-input-preview.element.js +2 -61
  97. package/target/lib/file-input/file-input-preview/file-input-preview.test.js +5 -25
  98. package/target/lib/file-input/file-input.element.js +2 -82
  99. package/target/lib/file-input/file-input.stories.js +1 -13
  100. package/target/lib/file-input/file-input.test.js +2 -16
  101. package/target/lib/icon/icon.element.js +1 -14
  102. package/target/lib/icon/icon.stories.js +2 -13
  103. package/target/lib/input/input.element.js +2 -73
  104. package/target/lib/input/input.stories.js +2 -12
  105. package/target/lib/input/input.test.js +4 -24
  106. package/target/lib/input-mask/input-mask.element.js +1 -5
  107. package/target/lib/input-mask/input-mask.stories.js +1 -12
  108. package/target/lib/input-mask/input-mask.test.js +4 -24
  109. package/target/lib/link/link.element.js +2 -18
  110. package/target/lib/modal/modal-close/modal-close.element.js +2 -36
  111. package/target/lib/modal/modal-close/modal-close.test.js +1 -3
  112. package/target/lib/modal/modal-heading/modal-heading.element.js +2 -24
  113. package/target/lib/modal/modal-heading/modal-heading.test.js +1 -3
  114. package/target/lib/modal/modal.element.js +2 -33
  115. package/target/lib/modal/modal.stories.js +1 -18
  116. package/target/lib/modal/modal.test.js +1 -11
  117. package/target/lib/radio/radio-option/radio-option.element.js +2 -16
  118. package/target/lib/radio/radio-option/radio-option.test.js +1 -5
  119. package/target/lib/radio/radio.element.js +2 -98
  120. package/target/lib/radio/radio.stories.js +1 -26
  121. package/target/lib/radio/radio.test.js +5 -103
  122. package/target/lib/range-slider/range-slider.element.js +2 -52
  123. package/target/lib/range-slider/range-slider.test.js +3 -17
  124. package/target/lib/select/select-option/select-option.element.js +1 -5
  125. package/target/lib/select/select.element.js +2 -49
  126. package/target/lib/select/select.stories.js +1 -10
  127. package/target/lib/select/select.test.js +6 -64
  128. package/target/lib/side-nav/side-nav-item/side-nav-item.element.js +2 -67
  129. package/target/lib/side-nav/side-nav.element.js +1 -8
  130. package/target/lib/side-nav/side-nav.stories.js +1 -39
  131. package/target/lib/side-nav/side-nav.test.js +2 -78
  132. package/target/lib/step-indicator/step/step.element.js +2 -96
  133. package/target/lib/step-indicator/step-indicator.element.js +1 -9
  134. package/target/lib/step-indicator/step-indicator.stories.js +1 -21
  135. package/target/lib/step-indicator/step-indicator.test.js +1 -9
  136. package/target/lib/summary-box/summary-box.element.js +2 -14
  137. package/target/lib/summary-box/summary-box.stories.js +1 -1
  138. package/target/lib/summary-box/summary-box.test.js +1 -3
  139. package/target/lib/tag/tag.element.js +1 -22
  140. package/target/lib/tag/tag.stories.js +1 -1
  141. package/target/lib/tag/tag.test.js +1 -3
  142. package/target/lib/textarea/textarea.element.js +2 -49
  143. package/target/lib/textarea/textarea.test.js +4 -24
@@ -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>
@@ -0,0 +1,5 @@
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="#002868"/>
4
+ <path d="M12 4L16 8L12 12L8 8L12 4Z" fill="#FFD700"/>
5
+ </svg>
@@ -0,0 +1,5 @@
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="#002868"/>
4
+ <path d="M12 4L16 8L12 12L8 8L12 4Z" fill="#FFD700"/>
5
+ </svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noctuatech/uswds",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "workspaces": ["packages/**"],
6
6
  "main": "./target/lib.js",
@@ -29,7 +29,7 @@
29
29
  "dependencies": ["tsc", "build_testing_library"]
30
30
  },
31
31
  "build": {
32
- "dependencies": ["build_storybook", "build_website"]
32
+ "dependencies": ["tsc", "build_storybook", "minify_html_literals"]
33
33
  },
34
34
  "preview": {
35
35
  "command": "eleventy --serve --incremental",
@@ -42,11 +42,7 @@
42
42
  ]
43
43
  },
44
44
  "build_storybook": {
45
- "command": "storybook build -o _site/storybook"
46
- },
47
- "build_website": {
48
- "command": "eleventy --pathprefix=uswds",
49
- "dependencies": ["tsc", "copy_icons"]
45
+ "command": "storybook build"
50
46
  },
51
47
  "build_testing_library": {
52
48
  "command": "./scripts/build_testing_library.sh",
@@ -57,21 +53,26 @@
57
53
  "command": "tsc --build --pretty",
58
54
  "clean": "if-file-deleted",
59
55
  "files": ["src/**", "tsconfig.json"],
60
- "output": ["target/**"]
56
+ "output": ["target/**", "tsconfig.tsbuildinfo"]
61
57
  },
62
58
  "copy_icons": {
63
59
  "command": "./scripts/copy_usa_icons.sh",
64
60
  "files": ["node_modules/@uswds/uswds/dist/img/usa-icons/**"],
65
61
  "output": ["assets/usa-icon/**"]
62
+ },
63
+ "minify_html_literals": {
64
+ "command": "node ./scripts/minify_html_literals.js",
65
+ "files": ["target/**/*.js"],
66
+ "dependencies": []
66
67
  }
67
68
  },
68
69
  "author": "",
69
70
  "license": "ISC",
70
71
  "description": "",
71
72
  "dependencies": {
72
- "@joist/di": "^4.0.0",
73
- "@joist/element": "^4.0.0",
74
- "@joist/observable": "^4.0.0",
73
+ "@joist/di": "^4.2.0",
74
+ "@joist/element": "^4.2.0",
75
+ "@joist/observable": "^4.2.0",
75
76
  "tslib": "2.8.1"
76
77
  },
77
78
  "devDependencies": {
@@ -92,6 +93,7 @@
92
93
  "js-beautify": "^1.15.1",
93
94
  "lint-staged": "^15.2.2",
94
95
  "lit": "^3.2.1",
96
+ "minify-html-literals": "^1.3.5",
95
97
  "mocha": "^11.0.0",
96
98
  "plop": "^4.0.1",
97
99
  "storybook": "^8.6.0",
@@ -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,61 @@ 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: [html`<slot></slot>`],
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
- #li = document.createElement("li");
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
- constructor() {
27
- super();
46
+ attributeChangedCallback() {
47
+ const value = this.value.split(" ").join("-").toLocaleLowerCase();
48
+
49
+ this.#li().dataset.value = this.value;
28
50
 
29
- this.#li.tabIndex = -1;
30
- }
51
+ this.#slot({ name: value });
31
52
 
32
- attributeChangedCallback() {
33
- this.#li.dataset.value = this.value;
34
- this.#li.textContent = this.value;
53
+ this.slot = value;
35
54
  }
36
55
 
37
56
  connectedCallback() {
38
57
  const ctx = this.#ctx();
39
58
 
40
- ctx.addOption(this.#li);
59
+ ctx.addOption(this.#li());
41
60
  }
42
61
 
43
62
  disconnectedCallback() {
44
63
  const ctx = this.#ctx();
45
64
 
46
- ctx.removeOption(this.#li);
65
+ ctx.removeOption(this.#li());
47
66
 
48
- this.#li.remove();
67
+ this.#li().remove();
49
68
  }
50
69
  }
@@ -1,5 +1,14 @@
1
1
  import { injectable } from "@joist/di";
2
- import { css, element, html, listen, query } from "@joist/element";
2
+ import {
3
+ attr,
4
+ attrChanged,
5
+ css,
6
+ element,
7
+ html,
8
+ listen,
9
+ query,
10
+ } from "@joist/element";
11
+
3
12
  import { COMBO_BOX_CTX, type ComboBoxContainer } from "./context.js";
4
13
 
5
14
  declare global {
@@ -16,24 +25,50 @@ declare global {
16
25
  tagName: "usa-combo-box",
17
26
  shadowDom: [
18
27
  css`
28
+ * {
29
+ box-sizing: border-box
30
+ }
31
+
19
32
  :host {
33
+ --usa-combo-max-height: 12.5em;
34
+
20
35
  display: block;
21
36
  max-width: 30rem;
22
37
  position: relative;
38
+ margin-bottom: 1.5rem;
39
+ }
40
+
41
+ input {
42
+ border-width: 1px;
43
+ border-color: #5c5c5c;
44
+ border-style: solid;
45
+ border-radius: 0;
46
+ color: #1b1b1b;
47
+ display: block;
48
+ height: 2.5rem;
49
+ line-height: 1.3;
50
+ font-size: 1.06rem;
51
+ margin-top: 0.5rem;
52
+ padding: 0.5rem;
53
+ width: 100%;
54
+ padding-right: 2.8rem;
55
+ }
56
+
57
+ input:not(:disabled):focus {
58
+ outline: 0.25rem solid #2491ff;
59
+ outline-offset: 0;
23
60
  }
24
61
 
25
62
  ul {
26
63
  padding: 0;
27
64
  position: absolute;
28
65
  bottom: 0;
29
- left: 0;
30
- right: 0;
66
+ width: 100%;
31
67
  transform: translateY(100%);
32
68
  margin: 0;
33
69
  border: 1px solid rgb(92, 92, 92);
34
- max-height: 12em;
70
+ max-height: var(--usa-combo-max-height);
35
71
  overflow-y: scroll;
36
- overflow-x: visible;
37
72
  z-index: 1001;
38
73
  }
39
74
 
@@ -47,7 +82,6 @@ declare global {
47
82
  border-bottom: 1px solid #e6e6e6;
48
83
  cursor: pointer;
49
84
  display: block;
50
- padding: 0.5rem;
51
85
  }
52
86
 
53
87
  ul li:hover {
@@ -58,10 +92,44 @@ declare global {
58
92
  outline: 0.25rem solid #2491ff;
59
93
  outline-offset: -0.25rem;
60
94
  }
95
+
96
+ .usa-combo-box-icon {
97
+ display: block;
98
+ position: absolute;
99
+ bottom: 0rem;
100
+ right: 0.5rem;
101
+ cursor: pointer;
102
+ }
103
+
104
+ .usa-combo-box-icon .line {
105
+ width: 1px;
106
+ top: 0.3rem;
107
+ bottom: 0.5rem;
108
+ left: -0.3rem;
109
+ position: absolute;
110
+ background-color: #c6cace;
111
+ }
61
112
  `,
62
113
  html`
63
- <slot name="input"></slot>
64
- <ul tabindex="-1"></ul>
114
+ <label>
115
+ <slot name="label"></slot>
116
+
117
+ <input
118
+ tabindex="0"
119
+ role="combobox"
120
+ autocomplete="off"
121
+ aria-controls="combo-box-list"
122
+ aria-expanded="false"
123
+ />
124
+
125
+ <div class="usa-combo-box-icon">
126
+ <div class="line"></div>
127
+
128
+ <usa-icon icon="expand_more"></usa-icon>
129
+ </div>
130
+ </label>
131
+
132
+ <ul tabindex="-1" role="listbox" id="combo-box-list"></ul>
65
133
  `,
66
134
  ],
67
135
  })
@@ -69,10 +137,43 @@ export class USAComboBoxElement
69
137
  extends HTMLElement
70
138
  implements ComboBoxContainer
71
139
  {
140
+ static formAssociated = true;
141
+
142
+ @attr()
143
+ accessor name = "";
144
+
145
+ @attr()
146
+ accessor required = false;
147
+
148
+ @attr()
149
+ accessor value = "";
150
+
151
+ @attr()
152
+ accessor placeholder = "";
153
+
72
154
  list = query("ul");
73
- input = query<HTMLInputElement>('[slot="input"]', this);
155
+ input = query("input");
74
156
  currentItemEl: Element | null = null;
157
+
75
158
  #allListItems = new Set<HTMLLIElement>();
159
+ #internals = this.attachInternals();
160
+
161
+ attributeChangedCallback() {
162
+ this.input({
163
+ name: this.name,
164
+ placeholder: this.placeholder,
165
+ required: this.required,
166
+ });
167
+ }
168
+
169
+ @attrChanged("value", "required")
170
+ onValueChanged() {
171
+ this.#syncFormState();
172
+ }
173
+
174
+ connectedCallback() {
175
+ this.#syncFormState();
176
+ }
76
177
 
77
178
  listItems() {
78
179
  return this.list().querySelectorAll("li");
@@ -86,39 +187,41 @@ export class USAComboBoxElement
86
187
  this.#allListItems.delete(el);
87
188
  }
88
189
 
89
- @listen("focusin", (host) => host)
90
- onFocusIn(e: FocusEvent) {
91
- if (e.target instanceof HTMLElement) {
92
- if (e.target.getAttribute("slot") === "input") {
93
- const list = this.list();
94
-
95
- for (const item of this.#allListItems) {
96
- if (!list.contains(item)) {
97
- list.append(item);
98
- }
99
- }
100
- }
190
+ @listen("focus", (host) => host.input())
191
+ onFocusIn() {
192
+ this.currentItemEl = null;
193
+
194
+ const list = this.list();
195
+
196
+ this.input({ ariaExpanded: "true" });
197
+
198
+ const fragment = document.createDocumentFragment();
199
+
200
+ for (const item of this.#allListItems) {
201
+ fragment.append(item);
101
202
  }
203
+
204
+ list.replaceChildren(fragment);
102
205
  }
103
206
 
104
- @listen("input", (host) => host)
207
+ @listen("input")
105
208
  async onInput() {
106
209
  const input = this.input();
107
210
  const list = this.list();
108
211
 
109
212
  this.currentItemEl = null;
110
213
 
214
+ const fragment = document.createDocumentFragment();
215
+
111
216
  for (const item of this.#allListItems) {
112
217
  if (
113
218
  item.dataset.value?.toLowerCase().startsWith(input.value.toLowerCase())
114
219
  ) {
115
- if (!list.contains(item)) {
116
- list.append(item);
117
- }
118
- } else {
119
- item.remove();
220
+ fragment.append(item);
120
221
  }
121
222
  }
223
+
224
+ list.replaceChildren(fragment);
122
225
  }
123
226
 
124
227
  @listen("focusout")
@@ -127,8 +230,10 @@ export class USAComboBoxElement
127
230
  // This needs to be in a timeout so that it runs as part of the next loop.
128
231
  // the active element will not be set until after all of the focus and blur events are done
129
232
  if (!this.contains(document.activeElement)) {
130
- this.list({ textContent: "" });
233
+ this.list({ innerHTML: "" });
131
234
  this.currentItemEl = null;
235
+
236
+ this.input({ ariaExpanded: "false" });
132
237
  }
133
238
  }, 0);
134
239
  }
@@ -190,29 +295,42 @@ export class USAComboBoxElement
190
295
 
191
296
  const value = target.dataset.value || "";
192
297
 
193
- this.input({
194
- value,
195
- selectionStart: value.length,
196
- selectionEnd: value.length,
197
- }).focus();
298
+ this.input().focus();
198
299
 
199
- this.list({ textContent: "" });
300
+ this.list({ innerHTML: "" });
301
+
302
+ this.value = value;
200
303
  }
201
304
 
202
305
  @listen("click")
203
306
  onClick(e: MouseEvent) {
204
- if (e.target instanceof HTMLLIElement) {
205
- const value = e.target.dataset.value || "";
307
+ if (e.target instanceof HTMLElement) {
308
+ const value = e.target.getAttribute("value");
206
309
 
207
- this.input({
208
- value,
209
- selectionStart: value.length,
210
- selectionEnd: value.length,
211
- }).focus();
310
+ if (value) {
311
+ this.input().focus();
212
312
 
213
- this.list({ textContent: "" });
313
+ this.list({ innerHTML: "" });
214
314
 
215
- this.currentItemEl = null;
315
+ this.currentItemEl = null;
316
+
317
+ this.value = value;
318
+ }
319
+ }
320
+ }
321
+
322
+ #syncFormState() {
323
+ const input = this.input({ value: this.value });
324
+
325
+ this.#internals.setValidity({});
326
+ this.#internals.setFormValue(this.value);
327
+
328
+ if (input.validationMessage) {
329
+ this.#internals.setValidity(
330
+ { customError: true },
331
+ input.validationMessage,
332
+ input,
333
+ );
216
334
  }
217
335
  }
218
336
  }