@vonage/vivid 4.14.0 → 4.14.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.
Files changed (218) hide show
  1. package/custom-elements.json +152 -197
  2. package/lib/divider/divider.d.ts +1 -1
  3. package/lib/divider/divider.template.d.ts +1 -1
  4. package/lib/elevation/elevation.d.ts +1 -0
  5. package/lib/radio/radio.form-associated.d.ts +2 -0
  6. package/lib/tabs/tabs.d.ts +0 -5
  7. package/lib/text-anchor/text-anchor.d.ts +2 -2
  8. package/lib/tree-item/tree-item.d.ts +2 -2
  9. package/lib/tree-view/tree-view.d.ts +2 -2
  10. package/package.json +1 -1
  11. package/shared/affix.cjs +8 -8
  12. package/shared/affix.js +2 -2
  13. package/shared/anchor.cjs +10 -10
  14. package/shared/anchor.js +1 -1
  15. package/shared/anchored.cjs +6 -6
  16. package/shared/anchored.js +1 -1
  17. package/shared/apply-mixins.cjs +3 -3
  18. package/shared/apply-mixins.js +1 -1
  19. package/shared/apply-mixins2.cjs +3 -3
  20. package/shared/apply-mixins2.js +1 -1
  21. package/shared/applyMixinsWithObservables.cjs +3 -3
  22. package/shared/applyMixinsWithObservables.js +1 -1
  23. package/shared/aria-global.cjs +20 -20
  24. package/shared/aria-global.js +1 -1
  25. package/shared/base-progress.cjs +7 -8
  26. package/shared/base-progress.js +2 -3
  27. package/shared/breadcrumb-item.cjs +2 -3
  28. package/shared/breadcrumb-item.js +1 -2
  29. package/shared/button.cjs +10 -11
  30. package/shared/button.js +1 -2
  31. package/shared/calendar-event.cjs +7 -8
  32. package/shared/calendar-event.js +1 -2
  33. package/shared/children.cjs +2 -2
  34. package/shared/children.js +1 -1
  35. package/shared/definition.cjs +14 -15
  36. package/shared/definition.js +2 -3
  37. package/shared/definition10.cjs +5 -6
  38. package/shared/definition10.js +1 -2
  39. package/shared/definition11.cjs +29 -29
  40. package/shared/definition11.js +2 -2
  41. package/shared/definition12.cjs +6 -6
  42. package/shared/definition12.js +1 -1
  43. package/shared/definition13.cjs +13 -14
  44. package/shared/definition13.js +1 -2
  45. package/shared/definition14.cjs +23 -24
  46. package/shared/definition14.js +1 -2
  47. package/shared/definition15.cjs +15 -16
  48. package/shared/definition15.js +1 -2
  49. package/shared/definition16.cjs +21 -21
  50. package/shared/definition16.js +5 -5
  51. package/shared/definition17.cjs +62 -61
  52. package/shared/definition17.js +10 -9
  53. package/shared/definition18.cjs +4 -4
  54. package/shared/definition18.js +1 -1
  55. package/shared/definition19.cjs +12 -12
  56. package/shared/definition19.js +1 -1
  57. package/shared/definition2.cjs +6 -7
  58. package/shared/definition2.js +1 -2
  59. package/shared/definition20.cjs +20 -21
  60. package/shared/definition20.js +1 -2
  61. package/shared/definition21.cjs +27 -28
  62. package/shared/definition21.js +3 -4
  63. package/shared/definition22.cjs +7 -7
  64. package/shared/definition22.js +3 -3
  65. package/shared/definition23.cjs +10 -11
  66. package/shared/definition23.js +1 -2
  67. package/shared/definition24.cjs +8 -8
  68. package/shared/definition24.js +3 -3
  69. package/shared/definition25.cjs +13 -14
  70. package/shared/definition25.js +1 -2
  71. package/shared/definition26.cjs +5 -6
  72. package/shared/definition26.js +1 -2
  73. package/shared/definition27.cjs +12 -13
  74. package/shared/definition27.js +2 -3
  75. package/shared/definition28.cjs +9 -10
  76. package/shared/definition28.js +2 -3
  77. package/shared/definition29.cjs +44 -45
  78. package/shared/definition29.js +3 -4
  79. package/shared/definition3.cjs +8 -9
  80. package/shared/definition3.js +1 -2
  81. package/shared/definition30.cjs +9 -10
  82. package/shared/definition30.js +2 -3
  83. package/shared/definition31.cjs +5 -5
  84. package/shared/definition31.js +2 -2
  85. package/shared/definition32.cjs +3 -4
  86. package/shared/definition32.js +1 -2
  87. package/shared/definition33.cjs +6 -7
  88. package/shared/definition33.js +2 -3
  89. package/shared/definition34.cjs +112 -45
  90. package/shared/definition34.js +73 -6
  91. package/shared/definition35.cjs +9 -209
  92. package/shared/definition35.js +4 -202
  93. package/shared/definition36.cjs +15 -16
  94. package/shared/definition36.js +1 -2
  95. package/shared/definition37.cjs +9 -9
  96. package/shared/definition37.js +1 -1
  97. package/shared/definition38.cjs +10 -10
  98. package/shared/definition38.js +1 -1
  99. package/shared/definition39.cjs +12 -13
  100. package/shared/definition39.js +1 -2
  101. package/shared/definition4.cjs +19 -20
  102. package/shared/definition4.js +2 -3
  103. package/shared/definition40.cjs +61 -13
  104. package/shared/definition40.js +52 -4
  105. package/shared/definition41.cjs +29 -30
  106. package/shared/definition41.js +1 -2
  107. package/shared/definition42.cjs +52 -53
  108. package/shared/definition42.js +3 -4
  109. package/shared/definition43.cjs +40 -40
  110. package/shared/definition43.js +6 -6
  111. package/shared/definition44.cjs +14 -15
  112. package/shared/definition44.js +1 -2
  113. package/shared/definition45.cjs +9 -10
  114. package/shared/definition45.js +1 -2
  115. package/shared/definition46.cjs +26 -27
  116. package/shared/definition46.js +1 -2
  117. package/shared/definition47.cjs +17 -18
  118. package/shared/definition47.js +2 -3
  119. package/shared/definition48.cjs +9 -10
  120. package/shared/definition48.js +1 -2
  121. package/shared/definition49.cjs +3 -4
  122. package/shared/definition49.js +1 -2
  123. package/shared/definition5.cjs +30 -31
  124. package/shared/definition5.js +1 -2
  125. package/shared/definition50.cjs +12 -13
  126. package/shared/definition50.js +2 -3
  127. package/shared/definition51.cjs +109 -72
  128. package/shared/definition51.js +78 -41
  129. package/shared/definition52.cjs +4 -5
  130. package/shared/definition52.js +1 -2
  131. package/shared/definition53.cjs +15 -16
  132. package/shared/definition53.js +2 -3
  133. package/shared/definition54.cjs +20 -21
  134. package/shared/definition54.js +1 -2
  135. package/shared/definition55.cjs +5 -5
  136. package/shared/definition55.js +1 -1
  137. package/shared/definition56.cjs +18 -19
  138. package/shared/definition56.js +1 -2
  139. package/shared/definition57.cjs +10 -11
  140. package/shared/definition57.js +1 -2
  141. package/shared/definition58.cjs +7 -8
  142. package/shared/definition58.js +1 -2
  143. package/shared/definition59.cjs +16 -17
  144. package/shared/definition59.js +3 -4
  145. package/shared/definition6.cjs +11 -12
  146. package/shared/definition6.js +1 -2
  147. package/shared/definition60.cjs +9 -10
  148. package/shared/definition60.js +2 -3
  149. package/shared/definition61.cjs +27 -30
  150. package/shared/definition61.js +17 -20
  151. package/shared/definition62.cjs +12 -9
  152. package/shared/definition62.js +8 -5
  153. package/shared/definition63.cjs +13 -14
  154. package/shared/definition63.js +1 -2
  155. package/shared/definition7.cjs +9 -10
  156. package/shared/definition7.js +2 -3
  157. package/shared/definition8.cjs +14 -15
  158. package/shared/definition8.js +2 -3
  159. package/shared/definition9.cjs +7 -7
  160. package/shared/definition9.js +1 -1
  161. package/shared/form-associated.cjs +14 -14
  162. package/shared/form-associated.js +1 -1
  163. package/shared/form-associated2.cjs +10 -10
  164. package/shared/form-associated2.js +1 -1
  165. package/shared/form-elements.cjs +13 -13
  166. package/shared/form-elements.js +1 -1
  167. package/shared/foundation/progress/base-progress.d.ts +2 -2
  168. package/shared/foundation-element.cjs +11 -11
  169. package/shared/foundation-element.js +1 -1
  170. package/shared/key-codes2.cjs +0 -56
  171. package/shared/key-codes2.js +1 -53
  172. package/shared/listbox.cjs +15 -16
  173. package/shared/listbox.js +2 -3
  174. package/shared/localized.cjs +2 -2
  175. package/shared/localized.js +1 -1
  176. package/shared/option.cjs +205 -0
  177. package/shared/option.js +202 -0
  178. package/shared/presentationDate.cjs +42 -43
  179. package/shared/presentationDate.js +1 -2
  180. package/shared/ref.cjs +2 -2
  181. package/shared/ref.js +1 -1
  182. package/shared/repeat.cjs +15 -15
  183. package/shared/repeat.js +1 -1
  184. package/shared/slider.template.cjs +4 -4
  185. package/shared/slider.template.js +1 -1
  186. package/shared/slotted.cjs +4 -4
  187. package/shared/slotted.js +1 -1
  188. package/shared/start-end.cjs +52 -0
  189. package/shared/start-end.js +50 -0
  190. package/shared/text-anchor.cjs +5 -6
  191. package/shared/text-anchor.js +3 -4
  192. package/shared/text-anchor.template.cjs +2 -2
  193. package/shared/text-anchor.template.js +1 -1
  194. package/shared/text-field2.cjs +23 -24
  195. package/shared/text-field2.js +2 -3
  196. package/shared/vivid-element.cjs +2610 -2
  197. package/shared/vivid-element.js +2591 -2
  198. package/styles/core/all.css +40 -1
  199. package/styles/core/theme.css +40 -1
  200. package/styles/core/typography.css +1 -1
  201. package/styles/tokens/theme-dark.css +25 -4
  202. package/styles/tokens/theme-light.css +25 -4
  203. package/styles/tokens/vivid-2-compat.css +1 -1
  204. package/text-anchor/index.cjs +3 -3
  205. package/text-anchor/index.js +1 -1
  206. package/lib/listbox/definition.d.ts +0 -2
  207. package/lib/listbox/listbox.d.ts +0 -14
  208. package/lib/listbox/listbox.template.d.ts +0 -2
  209. package/listbox/index.cjs +0 -54
  210. package/listbox/index.js +0 -52
  211. package/shared/aria-global2.cjs +0 -75
  212. package/shared/aria-global2.js +0 -73
  213. package/shared/defineVividComponent.cjs +0 -2612
  214. package/shared/defineVividComponent.js +0 -2592
  215. package/shared/listbox2.cjs +0 -1268
  216. package/shared/listbox2.js +0 -1265
  217. package/shared/strings2.cjs +0 -37
  218. package/shared/strings2.js +0 -33
@@ -1,1265 +0,0 @@
1
- import { h as keyArrowLeft, i as keyArrowRight } from './key-codes.js';
2
- import { _ as __decorate, F as FoundationElement } from './foundation-element.js';
3
- import { A as ARIAGlobalStatesAndProperties } from './aria-global2.js';
4
- import { S as StartEnd, g as keySpace, h as keyEscape, k as keyEnter, i as keyTab, e as keyEnd, d as keyArrowUp, c as keyArrowDown, f as keyHome } from './key-codes2.js';
5
- import { a as applyMixins } from './apply-mixins2.js';
6
- import { o as observable, a as attr, O as Observable, D as DOM, n as nullableNumberConverter } from './defineVividComponent.js';
7
- import { u as uniqueId, i as inRange } from './strings2.js';
8
-
9
- /**
10
- * Returns the index of the last element in the array where predicate is true, and -1 otherwise.
11
- *
12
- * @param array - the array to test
13
- * @param predicate - find calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLastIndex immediately returns that element index. Otherwise, findIndex returns -1.
14
- */
15
- function findLastIndex(array, predicate) {
16
- let k = array.length;
17
- while (k--) {
18
- if (predicate(array[k], k, array)) {
19
- return k;
20
- }
21
- }
22
- return -1;
23
- }
24
-
25
- /**
26
- * A test that ensures that all arguments are HTML Elements
27
- */
28
- function isHTMLElement(...args) {
29
- return args.every((arg) => arg instanceof HTMLElement);
30
- }
31
-
32
- /**
33
- * Determines if the element is a {@link (ListboxOption:class)}
34
- *
35
- * @param element - the element to test.
36
- * @public
37
- */
38
- function isListboxOption(el) {
39
- return (isHTMLElement(el) &&
40
- (el.getAttribute("role") === "option" ||
41
- el instanceof HTMLOptionElement));
42
- }
43
- /**
44
- * An Option Custom HTML Element.
45
- * Implements {@link https://www.w3.org/TR/wai-aria-1.1/#option | ARIA option }.
46
- *
47
- * @slot start - Content which can be provided before the listbox option content
48
- * @slot end - Content which can be provided after the listbox option content
49
- * @slot - The default slot for listbox option content
50
- * @csspart content - Wraps the listbox option content
51
- *
52
- * @public
53
- */
54
- class ListboxOption extends FoundationElement {
55
- constructor(text, value, defaultSelected, selected) {
56
- super();
57
- /**
58
- * The defaultSelected state of the option.
59
- * @public
60
- */
61
- this.defaultSelected = false;
62
- /**
63
- * Tracks whether the "selected" property has been changed.
64
- * @internal
65
- */
66
- this.dirtySelected = false;
67
- /**
68
- * The checked state of the control.
69
- *
70
- * @public
71
- */
72
- this.selected = this.defaultSelected;
73
- /**
74
- * Track whether the value has been changed from the initial value
75
- */
76
- this.dirtyValue = false;
77
- if (text) {
78
- this.textContent = text;
79
- }
80
- if (value) {
81
- this.initialValue = value;
82
- }
83
- if (defaultSelected) {
84
- this.defaultSelected = defaultSelected;
85
- }
86
- if (selected) {
87
- this.selected = selected;
88
- }
89
- this.proxy = new Option(`${this.textContent}`, this.initialValue, this.defaultSelected, this.selected);
90
- this.proxy.disabled = this.disabled;
91
- }
92
- /**
93
- * Updates the ariaChecked property when the checked property changes.
94
- *
95
- * @param prev - the previous checked value
96
- * @param next - the current checked value
97
- *
98
- * @public
99
- */
100
- checkedChanged(prev, next) {
101
- if (typeof next === "boolean") {
102
- this.ariaChecked = next ? "true" : "false";
103
- return;
104
- }
105
- this.ariaChecked = null;
106
- }
107
- /**
108
- * Updates the proxy's text content when the default slot changes.
109
- * @param prev - the previous content value
110
- * @param next - the current content value
111
- *
112
- * @internal
113
- */
114
- contentChanged(prev, next) {
115
- if (this.proxy instanceof HTMLOptionElement) {
116
- this.proxy.textContent = this.textContent;
117
- }
118
- this.$emit("contentchange", null, { bubbles: true });
119
- }
120
- defaultSelectedChanged() {
121
- if (!this.dirtySelected) {
122
- this.selected = this.defaultSelected;
123
- if (this.proxy instanceof HTMLOptionElement) {
124
- this.proxy.selected = this.defaultSelected;
125
- }
126
- }
127
- }
128
- disabledChanged(prev, next) {
129
- this.ariaDisabled = this.disabled ? "true" : "false";
130
- if (this.proxy instanceof HTMLOptionElement) {
131
- this.proxy.disabled = this.disabled;
132
- }
133
- }
134
- selectedAttributeChanged() {
135
- this.defaultSelected = this.selectedAttribute;
136
- if (this.proxy instanceof HTMLOptionElement) {
137
- this.proxy.defaultSelected = this.defaultSelected;
138
- }
139
- }
140
- selectedChanged() {
141
- this.ariaSelected = this.selected ? "true" : "false";
142
- if (!this.dirtySelected) {
143
- this.dirtySelected = true;
144
- }
145
- if (this.proxy instanceof HTMLOptionElement) {
146
- this.proxy.selected = this.selected;
147
- }
148
- }
149
- initialValueChanged(previous, next) {
150
- // If the value is clean and the component is connected to the DOM
151
- // then set value equal to the attribute value.
152
- if (!this.dirtyValue) {
153
- this.value = this.initialValue;
154
- this.dirtyValue = false;
155
- }
156
- }
157
- get label() {
158
- var _a;
159
- return (_a = this.value) !== null && _a !== void 0 ? _a : this.text;
160
- }
161
- get text() {
162
- var _a, _b;
163
- return (_b = (_a = this.textContent) === null || _a === void 0 ? void 0 : _a.replace(/\s+/g, " ").trim()) !== null && _b !== void 0 ? _b : "";
164
- }
165
- set value(next) {
166
- const newValue = `${next !== null && next !== void 0 ? next : ""}`;
167
- this._value = newValue;
168
- this.dirtyValue = true;
169
- if (this.proxy instanceof HTMLOptionElement) {
170
- this.proxy.value = newValue;
171
- }
172
- Observable.notify(this, "value");
173
- }
174
- get value() {
175
- var _a;
176
- Observable.track(this, "value");
177
- return (_a = this._value) !== null && _a !== void 0 ? _a : this.text;
178
- }
179
- get form() {
180
- return this.proxy ? this.proxy.form : null;
181
- }
182
- }
183
- __decorate([
184
- observable
185
- ], ListboxOption.prototype, "checked", void 0);
186
- __decorate([
187
- observable
188
- ], ListboxOption.prototype, "content", void 0);
189
- __decorate([
190
- observable
191
- ], ListboxOption.prototype, "defaultSelected", void 0);
192
- __decorate([
193
- attr({ mode: "boolean" })
194
- ], ListboxOption.prototype, "disabled", void 0);
195
- __decorate([
196
- attr({ attribute: "selected", mode: "boolean" })
197
- ], ListboxOption.prototype, "selectedAttribute", void 0);
198
- __decorate([
199
- observable
200
- ], ListboxOption.prototype, "selected", void 0);
201
- __decorate([
202
- attr({ attribute: "value", mode: "fromView" })
203
- ], ListboxOption.prototype, "initialValue", void 0);
204
- /**
205
- * States and properties relating to the ARIA `option` role.
206
- *
207
- * @public
208
- */
209
- class DelegatesARIAListboxOption {
210
- }
211
- __decorate([
212
- observable
213
- ], DelegatesARIAListboxOption.prototype, "ariaChecked", void 0);
214
- __decorate([
215
- observable
216
- ], DelegatesARIAListboxOption.prototype, "ariaPosInSet", void 0);
217
- __decorate([
218
- observable
219
- ], DelegatesARIAListboxOption.prototype, "ariaSelected", void 0);
220
- __decorate([
221
- observable
222
- ], DelegatesARIAListboxOption.prototype, "ariaSetSize", void 0);
223
- applyMixins(DelegatesARIAListboxOption, ARIAGlobalStatesAndProperties);
224
- applyMixins(ListboxOption, StartEnd, DelegatesARIAListboxOption);
225
-
226
- /**
227
- * A Listbox Custom HTML Element.
228
- * Implements the {@link https://www.w3.org/TR/wai-aria-1.1/#listbox | ARIA listbox }.
229
- *
230
- * @slot - The default slot for the listbox options
231
- *
232
- * @public
233
- */
234
- let Listbox$1 = class Listbox extends FoundationElement {
235
- constructor() {
236
- super(...arguments);
237
- /**
238
- * The internal unfiltered list of selectable options.
239
- *
240
- * @internal
241
- */
242
- this._options = [];
243
- /**
244
- * The index of the selected option.
245
- *
246
- * @public
247
- */
248
- this.selectedIndex = -1;
249
- /**
250
- * A collection of the selected options.
251
- *
252
- * @public
253
- */
254
- this.selectedOptions = [];
255
- /**
256
- * A standard `click` event creates a `focus` event before firing, so a
257
- * `mousedown` event is used to skip that initial focus.
258
- *
259
- * @internal
260
- */
261
- this.shouldSkipFocus = false;
262
- /**
263
- * The current typeahead buffer string.
264
- *
265
- * @internal
266
- */
267
- this.typeaheadBuffer = "";
268
- /**
269
- * Flag for the typeahead timeout expiration.
270
- *
271
- * @internal
272
- */
273
- this.typeaheadExpired = true;
274
- /**
275
- * The timeout ID for the typeahead handler.
276
- *
277
- * @internal
278
- */
279
- this.typeaheadTimeout = -1;
280
- }
281
- /**
282
- * The first selected option.
283
- *
284
- * @internal
285
- */
286
- get firstSelectedOption() {
287
- var _a;
288
- return (_a = this.selectedOptions[0]) !== null && _a !== void 0 ? _a : null;
289
- }
290
- /**
291
- * Returns true if there is one or more selectable option.
292
- *
293
- * @internal
294
- */
295
- get hasSelectableOptions() {
296
- return this.options.length > 0 && !this.options.every(o => o.disabled);
297
- }
298
- /**
299
- * The number of options.
300
- *
301
- * @public
302
- */
303
- get length() {
304
- var _a, _b;
305
- return (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
306
- }
307
- /**
308
- * The list of options.
309
- *
310
- * @public
311
- */
312
- get options() {
313
- Observable.track(this, "options");
314
- return this._options;
315
- }
316
- set options(value) {
317
- this._options = value;
318
- Observable.notify(this, "options");
319
- }
320
- /**
321
- * Flag for the typeahead timeout expiration.
322
- *
323
- * @deprecated use `Listbox.typeaheadExpired`
324
- * @internal
325
- */
326
- get typeAheadExpired() {
327
- return this.typeaheadExpired;
328
- }
329
- set typeAheadExpired(value) {
330
- this.typeaheadExpired = value;
331
- }
332
- /**
333
- * Handle click events for listbox options.
334
- *
335
- * @internal
336
- */
337
- clickHandler(e) {
338
- const captured = e.target.closest(`option,[role=option]`);
339
- if (captured && !captured.disabled) {
340
- this.selectedIndex = this.options.indexOf(captured);
341
- return true;
342
- }
343
- }
344
- /**
345
- * Ensures that the provided option is focused and scrolled into view.
346
- *
347
- * @param optionToFocus - The option to focus
348
- * @internal
349
- */
350
- focusAndScrollOptionIntoView(optionToFocus = this.firstSelectedOption) {
351
- // To ensure that the browser handles both `focus()` and `scrollIntoView()`, the
352
- // timing here needs to guarantee that they happen on different frames. Since this
353
- // function is typically called from the `openChanged` observer, `DOM.queueUpdate`
354
- // causes the calls to be grouped into the same frame. To prevent this,
355
- // `requestAnimationFrame` is used instead of `DOM.queueUpdate`.
356
- if (this.contains(document.activeElement) && optionToFocus !== null) {
357
- optionToFocus.focus();
358
- requestAnimationFrame(() => {
359
- optionToFocus.scrollIntoView({ block: "nearest" });
360
- });
361
- }
362
- }
363
- /**
364
- * Handles `focusin` actions for the component. When the component receives focus,
365
- * the list of selected options is refreshed and the first selected option is scrolled
366
- * into view.
367
- *
368
- * @internal
369
- */
370
- focusinHandler(e) {
371
- if (!this.shouldSkipFocus && e.target === e.currentTarget) {
372
- this.setSelectedOptions();
373
- this.focusAndScrollOptionIntoView();
374
- }
375
- this.shouldSkipFocus = false;
376
- }
377
- /**
378
- * Returns the options which match the current typeahead buffer.
379
- *
380
- * @internal
381
- */
382
- getTypeaheadMatches() {
383
- const pattern = this.typeaheadBuffer.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
384
- const re = new RegExp(`^${pattern}`, "gi");
385
- return this.options.filter((o) => o.text.trim().match(re));
386
- }
387
- /**
388
- * Determines the index of the next option which is selectable, if any.
389
- *
390
- * @param prev - the previous selected index
391
- * @param next - the next index to select
392
- *
393
- * @internal
394
- */
395
- getSelectableIndex(prev = this.selectedIndex, next) {
396
- const direction = prev > next ? -1 : prev < next ? 1 : 0;
397
- const potentialDirection = prev + direction;
398
- let nextSelectableOption = null;
399
- switch (direction) {
400
- case -1: {
401
- nextSelectableOption = this.options.reduceRight((nextSelectableOption, thisOption, index) => !nextSelectableOption &&
402
- !thisOption.disabled &&
403
- index < potentialDirection
404
- ? thisOption
405
- : nextSelectableOption, nextSelectableOption);
406
- break;
407
- }
408
- case 1: {
409
- nextSelectableOption = this.options.reduce((nextSelectableOption, thisOption, index) => !nextSelectableOption &&
410
- !thisOption.disabled &&
411
- index > potentialDirection
412
- ? thisOption
413
- : nextSelectableOption, nextSelectableOption);
414
- break;
415
- }
416
- }
417
- return this.options.indexOf(nextSelectableOption);
418
- }
419
- /**
420
- * Handles external changes to child options.
421
- *
422
- * @param source - the source object
423
- * @param propertyName - the property
424
- *
425
- * @internal
426
- */
427
- handleChange(source, propertyName) {
428
- switch (propertyName) {
429
- case "selected": {
430
- if (Listbox.slottedOptionFilter(source)) {
431
- this.selectedIndex = this.options.indexOf(source);
432
- }
433
- this.setSelectedOptions();
434
- break;
435
- }
436
- }
437
- }
438
- /**
439
- * Moves focus to an option whose label matches characters typed by the user.
440
- * Consecutive keystrokes are batched into a buffer of search text used
441
- * to match against the set of options. If `TYPE_AHEAD_TIMEOUT_MS` passes
442
- * between consecutive keystrokes, the search restarts.
443
- *
444
- * @param key - the key to be evaluated
445
- *
446
- * @internal
447
- */
448
- handleTypeAhead(key) {
449
- if (this.typeaheadTimeout) {
450
- window.clearTimeout(this.typeaheadTimeout);
451
- }
452
- this.typeaheadTimeout = window.setTimeout(() => (this.typeaheadExpired = true), Listbox.TYPE_AHEAD_TIMEOUT_MS);
453
- if (key.length > 1) {
454
- return;
455
- }
456
- this.typeaheadBuffer = `${this.typeaheadExpired ? "" : this.typeaheadBuffer}${key}`;
457
- }
458
- /**
459
- * Handles `keydown` actions for listbox navigation and typeahead.
460
- *
461
- * @internal
462
- */
463
- keydownHandler(e) {
464
- if (this.disabled) {
465
- return true;
466
- }
467
- this.shouldSkipFocus = false;
468
- const key = e.key;
469
- switch (key) {
470
- // Select the first available option
471
- case keyHome: {
472
- if (!e.shiftKey) {
473
- e.preventDefault();
474
- this.selectFirstOption();
475
- }
476
- break;
477
- }
478
- // Select the next selectable option
479
- case keyArrowDown: {
480
- if (!e.shiftKey) {
481
- e.preventDefault();
482
- this.selectNextOption();
483
- }
484
- break;
485
- }
486
- // Select the previous selectable option
487
- case keyArrowUp: {
488
- if (!e.shiftKey) {
489
- e.preventDefault();
490
- this.selectPreviousOption();
491
- }
492
- break;
493
- }
494
- // Select the last available option
495
- case keyEnd: {
496
- e.preventDefault();
497
- this.selectLastOption();
498
- break;
499
- }
500
- case keyTab: {
501
- this.focusAndScrollOptionIntoView();
502
- return true;
503
- }
504
- case keyEnter:
505
- case keyEscape: {
506
- return true;
507
- }
508
- case keySpace: {
509
- if (this.typeaheadExpired) {
510
- return true;
511
- }
512
- }
513
- // Send key to Typeahead handler
514
- default: {
515
- if (key.length === 1) {
516
- this.handleTypeAhead(`${key}`);
517
- }
518
- return true;
519
- }
520
- }
521
- }
522
- /**
523
- * Prevents `focusin` events from firing before `click` events when the
524
- * element is unfocused.
525
- *
526
- * @internal
527
- */
528
- mousedownHandler(e) {
529
- this.shouldSkipFocus = !this.contains(document.activeElement);
530
- return true;
531
- }
532
- /**
533
- * Switches between single-selection and multi-selection mode.
534
- *
535
- * @param prev - the previous value of the `multiple` attribute
536
- * @param next - the next value of the `multiple` attribute
537
- *
538
- * @internal
539
- */
540
- multipleChanged(prev, next) {
541
- this.ariaMultiSelectable = next ? "true" : null;
542
- }
543
- /**
544
- * Updates the list of selected options when the `selectedIndex` changes.
545
- *
546
- * @param prev - the previous selected index value
547
- * @param next - the current selected index value
548
- *
549
- * @internal
550
- */
551
- selectedIndexChanged(prev, next) {
552
- var _a;
553
- if (!this.hasSelectableOptions) {
554
- this.selectedIndex = -1;
555
- return;
556
- }
557
- if (((_a = this.options[this.selectedIndex]) === null || _a === void 0 ? void 0 : _a.disabled) && typeof prev === "number") {
558
- const selectableIndex = this.getSelectableIndex(prev, next);
559
- const newNext = selectableIndex > -1 ? selectableIndex : prev;
560
- this.selectedIndex = newNext;
561
- if (next === newNext) {
562
- this.selectedIndexChanged(next, newNext);
563
- }
564
- return;
565
- }
566
- this.setSelectedOptions();
567
- }
568
- /**
569
- * Updates the selectedness of each option when the list of selected options changes.
570
- *
571
- * @param prev - the previous list of selected options
572
- * @param next - the current list of selected options
573
- *
574
- * @internal
575
- */
576
- selectedOptionsChanged(prev, next) {
577
- var _a;
578
- const filteredNext = next.filter(Listbox.slottedOptionFilter);
579
- (_a = this.options) === null || _a === void 0 ? void 0 : _a.forEach(o => {
580
- const notifier = Observable.getNotifier(o);
581
- notifier.unsubscribe(this, "selected");
582
- o.selected = filteredNext.includes(o);
583
- notifier.subscribe(this, "selected");
584
- });
585
- }
586
- /**
587
- * Moves focus to the first selectable option.
588
- *
589
- * @public
590
- */
591
- selectFirstOption() {
592
- var _a, _b;
593
- if (!this.disabled) {
594
- this.selectedIndex = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.findIndex(o => !o.disabled)) !== null && _b !== void 0 ? _b : -1;
595
- }
596
- }
597
- /**
598
- * Moves focus to the last selectable option.
599
- *
600
- * @internal
601
- */
602
- selectLastOption() {
603
- if (!this.disabled) {
604
- this.selectedIndex = findLastIndex(this.options, o => !o.disabled);
605
- }
606
- }
607
- /**
608
- * Moves focus to the next selectable option.
609
- *
610
- * @internal
611
- */
612
- selectNextOption() {
613
- if (!this.disabled && this.selectedIndex < this.options.length - 1) {
614
- this.selectedIndex += 1;
615
- }
616
- }
617
- /**
618
- * Moves focus to the previous selectable option.
619
- *
620
- * @internal
621
- */
622
- selectPreviousOption() {
623
- if (!this.disabled && this.selectedIndex > 0) {
624
- this.selectedIndex = this.selectedIndex - 1;
625
- }
626
- }
627
- /**
628
- * Updates the selected index to match the first selected option.
629
- *
630
- * @internal
631
- */
632
- setDefaultSelectedOption() {
633
- var _a, _b;
634
- this.selectedIndex = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.findIndex(el => el.defaultSelected)) !== null && _b !== void 0 ? _b : -1;
635
- }
636
- /**
637
- * Sets an option as selected and gives it focus.
638
- *
639
- * @public
640
- */
641
- setSelectedOptions() {
642
- var _a, _b, _c;
643
- if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.length) {
644
- this.selectedOptions = [this.options[this.selectedIndex]];
645
- this.ariaActiveDescendant = (_c = (_b = this.firstSelectedOption) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : "";
646
- this.focusAndScrollOptionIntoView();
647
- }
648
- }
649
- /**
650
- * Updates the list of options and resets the selected option when the slotted option content changes.
651
- *
652
- * @param prev - the previous list of slotted options
653
- * @param next - the current list of slotted options
654
- *
655
- * @internal
656
- */
657
- slottedOptionsChanged(prev, next) {
658
- this.options = next.reduce((options, item) => {
659
- if (isListboxOption(item)) {
660
- options.push(item);
661
- }
662
- return options;
663
- }, []);
664
- const setSize = `${this.options.length}`;
665
- this.options.forEach((option, index) => {
666
- if (!option.id) {
667
- option.id = uniqueId("option-");
668
- }
669
- option.ariaPosInSet = `${index + 1}`;
670
- option.ariaSetSize = setSize;
671
- });
672
- if (this.$fastController.isConnected) {
673
- this.setSelectedOptions();
674
- this.setDefaultSelectedOption();
675
- }
676
- }
677
- /**
678
- * Updates the filtered list of options when the typeahead buffer changes.
679
- *
680
- * @param prev - the previous typeahead buffer value
681
- * @param next - the current typeahead buffer value
682
- *
683
- * @internal
684
- */
685
- typeaheadBufferChanged(prev, next) {
686
- if (this.$fastController.isConnected) {
687
- const typeaheadMatches = this.getTypeaheadMatches();
688
- if (typeaheadMatches.length) {
689
- const selectedIndex = this.options.indexOf(typeaheadMatches[0]);
690
- if (selectedIndex > -1) {
691
- this.selectedIndex = selectedIndex;
692
- }
693
- }
694
- this.typeaheadExpired = false;
695
- }
696
- }
697
- };
698
- /**
699
- * A static filter to include only selectable options.
700
- *
701
- * @param n - element to filter
702
- * @public
703
- */
704
- Listbox$1.slottedOptionFilter = (n) => isListboxOption(n) && !n.hidden;
705
- /**
706
- * Typeahead timeout in milliseconds.
707
- *
708
- * @internal
709
- */
710
- Listbox$1.TYPE_AHEAD_TIMEOUT_MS = 1000;
711
- __decorate([
712
- attr({ mode: "boolean" })
713
- ], Listbox$1.prototype, "disabled", void 0);
714
- __decorate([
715
- observable
716
- ], Listbox$1.prototype, "selectedIndex", void 0);
717
- __decorate([
718
- observable
719
- ], Listbox$1.prototype, "selectedOptions", void 0);
720
- __decorate([
721
- observable
722
- ], Listbox$1.prototype, "slottedOptions", void 0);
723
- __decorate([
724
- observable
725
- ], Listbox$1.prototype, "typeaheadBuffer", void 0);
726
- /**
727
- * Includes ARIA states and properties relating to the ARIA listbox role
728
- *
729
- * @public
730
- */
731
- class DelegatesARIAListbox {
732
- }
733
- __decorate([
734
- observable
735
- ], DelegatesARIAListbox.prototype, "ariaActiveDescendant", void 0);
736
- __decorate([
737
- observable
738
- ], DelegatesARIAListbox.prototype, "ariaDisabled", void 0);
739
- __decorate([
740
- observable
741
- ], DelegatesARIAListbox.prototype, "ariaExpanded", void 0);
742
- __decorate([
743
- observable
744
- ], DelegatesARIAListbox.prototype, "ariaMultiSelectable", void 0);
745
- applyMixins(DelegatesARIAListbox, ARIAGlobalStatesAndProperties);
746
- applyMixins(Listbox$1, DelegatesARIAListbox);
747
-
748
- /**
749
- * A Listbox Custom HTML Element.
750
- * Implements the {@link https://w3c.github.io/aria/#listbox | ARIA listbox }.
751
- *
752
- * @public
753
- */
754
- class ListboxElement extends Listbox$1 {
755
- constructor() {
756
- super(...arguments);
757
- /**
758
- * The index of the most recently checked option.
759
- *
760
- * @internal
761
- * @remarks
762
- * Multiple-selection mode only.
763
- */
764
- this.activeIndex = -1;
765
- /**
766
- * The start index when checking a range of options.
767
- *
768
- * @internal
769
- */
770
- this.rangeStartIndex = -1;
771
- }
772
- /**
773
- * Returns the last checked option.
774
- *
775
- * @internal
776
- */
777
- get activeOption() {
778
- return this.options[this.activeIndex];
779
- }
780
- /**
781
- * Returns the list of checked options.
782
- *
783
- * @internal
784
- */
785
- get checkedOptions() {
786
- var _a;
787
- return (_a = this.options) === null || _a === void 0 ? void 0 : _a.filter(o => o.checked);
788
- }
789
- /**
790
- * Returns the index of the first selected option.
791
- *
792
- * @internal
793
- */
794
- get firstSelectedOptionIndex() {
795
- return this.options.indexOf(this.firstSelectedOption);
796
- }
797
- /**
798
- * Updates the `ariaActiveDescendant` property when the active index changes.
799
- *
800
- * @param prev - the previous active index
801
- * @param next - the next active index
802
- *
803
- * @internal
804
- */
805
- activeIndexChanged(prev, next) {
806
- var _a, _b;
807
- this.ariaActiveDescendant = (_b = (_a = this.options[next]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : "";
808
- this.focusAndScrollOptionIntoView();
809
- }
810
- /**
811
- * Toggles the checked state for the currently active option.
812
- *
813
- * @remarks
814
- * Multiple-selection mode only.
815
- *
816
- * @internal
817
- */
818
- checkActiveIndex() {
819
- if (!this.multiple) {
820
- return;
821
- }
822
- const activeItem = this.activeOption;
823
- if (activeItem) {
824
- activeItem.checked = true;
825
- }
826
- }
827
- /**
828
- * Sets the active index to the first option and marks it as checked.
829
- *
830
- * @remarks
831
- * Multi-selection mode only.
832
- *
833
- * @param preserveChecked - mark all options unchecked before changing the active index
834
- *
835
- * @internal
836
- */
837
- checkFirstOption(preserveChecked = false) {
838
- if (preserveChecked) {
839
- if (this.rangeStartIndex === -1) {
840
- this.rangeStartIndex = this.activeIndex + 1;
841
- }
842
- this.options.forEach((o, i) => {
843
- o.checked = inRange(i, this.rangeStartIndex);
844
- });
845
- }
846
- else {
847
- this.uncheckAllOptions();
848
- }
849
- this.activeIndex = 0;
850
- this.checkActiveIndex();
851
- }
852
- /**
853
- * Decrements the active index and sets the matching option as checked.
854
- *
855
- * @remarks
856
- * Multi-selection mode only.
857
- *
858
- * @param preserveChecked - mark all options unchecked before changing the active index
859
- *
860
- * @internal
861
- */
862
- checkLastOption(preserveChecked = false) {
863
- if (preserveChecked) {
864
- if (this.rangeStartIndex === -1) {
865
- this.rangeStartIndex = this.activeIndex;
866
- }
867
- this.options.forEach((o, i) => {
868
- o.checked = inRange(i, this.rangeStartIndex, this.options.length);
869
- });
870
- }
871
- else {
872
- this.uncheckAllOptions();
873
- }
874
- this.activeIndex = this.options.length - 1;
875
- this.checkActiveIndex();
876
- }
877
- /**
878
- * @override
879
- * @internal
880
- */
881
- connectedCallback() {
882
- super.connectedCallback();
883
- this.addEventListener("focusout", this.focusoutHandler);
884
- }
885
- /**
886
- * @override
887
- * @internal
888
- */
889
- disconnectedCallback() {
890
- this.removeEventListener("focusout", this.focusoutHandler);
891
- super.disconnectedCallback();
892
- }
893
- /**
894
- * Increments the active index and marks the matching option as checked.
895
- *
896
- * @remarks
897
- * Multiple-selection mode only.
898
- *
899
- * @param preserveChecked - mark all options unchecked before changing the active index
900
- *
901
- * @internal
902
- */
903
- checkNextOption(preserveChecked = false) {
904
- if (preserveChecked) {
905
- if (this.rangeStartIndex === -1) {
906
- this.rangeStartIndex = this.activeIndex;
907
- }
908
- this.options.forEach((o, i) => {
909
- o.checked = inRange(i, this.rangeStartIndex, this.activeIndex + 1);
910
- });
911
- }
912
- else {
913
- this.uncheckAllOptions();
914
- }
915
- this.activeIndex += this.activeIndex < this.options.length - 1 ? 1 : 0;
916
- this.checkActiveIndex();
917
- }
918
- /**
919
- * Decrements the active index and marks the matching option as checked.
920
- *
921
- * @remarks
922
- * Multiple-selection mode only.
923
- *
924
- * @param preserveChecked - mark all options unchecked before changing the active index
925
- *
926
- * @internal
927
- */
928
- checkPreviousOption(preserveChecked = false) {
929
- if (preserveChecked) {
930
- if (this.rangeStartIndex === -1) {
931
- this.rangeStartIndex = this.activeIndex;
932
- }
933
- if (this.checkedOptions.length === 1) {
934
- this.rangeStartIndex += 1;
935
- }
936
- this.options.forEach((o, i) => {
937
- o.checked = inRange(i, this.activeIndex, this.rangeStartIndex);
938
- });
939
- }
940
- else {
941
- this.uncheckAllOptions();
942
- }
943
- this.activeIndex -= this.activeIndex > 0 ? 1 : 0;
944
- this.checkActiveIndex();
945
- }
946
- /**
947
- * Handles click events for listbox options.
948
- *
949
- * @param e - the event object
950
- *
951
- * @override
952
- * @internal
953
- */
954
- clickHandler(e) {
955
- var _a;
956
- if (!this.multiple) {
957
- return super.clickHandler(e);
958
- }
959
- const captured = (_a = e.target) === null || _a === void 0 ? void 0 : _a.closest(`[role=option]`);
960
- if (!captured || captured.disabled) {
961
- return;
962
- }
963
- this.uncheckAllOptions();
964
- this.activeIndex = this.options.indexOf(captured);
965
- this.checkActiveIndex();
966
- this.toggleSelectedForAllCheckedOptions();
967
- return true;
968
- }
969
- /**
970
- * @override
971
- * @internal
972
- */
973
- focusAndScrollOptionIntoView() {
974
- super.focusAndScrollOptionIntoView(this.activeOption);
975
- }
976
- /**
977
- * In multiple-selection mode:
978
- * If any options are selected, the first selected option is checked when
979
- * the listbox receives focus. If no options are selected, the first
980
- * selectable option is checked.
981
- *
982
- * @override
983
- * @internal
984
- */
985
- focusinHandler(e) {
986
- if (!this.multiple) {
987
- return super.focusinHandler(e);
988
- }
989
- if (!this.shouldSkipFocus && e.target === e.currentTarget) {
990
- this.uncheckAllOptions();
991
- if (this.activeIndex === -1) {
992
- this.activeIndex =
993
- this.firstSelectedOptionIndex !== -1
994
- ? this.firstSelectedOptionIndex
995
- : 0;
996
- }
997
- this.checkActiveIndex();
998
- this.setSelectedOptions();
999
- this.focusAndScrollOptionIntoView();
1000
- }
1001
- this.shouldSkipFocus = false;
1002
- }
1003
- /**
1004
- * Unchecks all options when the listbox loses focus.
1005
- *
1006
- * @internal
1007
- */
1008
- focusoutHandler(e) {
1009
- if (this.multiple) {
1010
- this.uncheckAllOptions();
1011
- }
1012
- }
1013
- /**
1014
- * Handles keydown actions for listbox navigation and typeahead
1015
- *
1016
- * @override
1017
- * @internal
1018
- */
1019
- keydownHandler(e) {
1020
- if (!this.multiple) {
1021
- return super.keydownHandler(e);
1022
- }
1023
- if (this.disabled) {
1024
- return true;
1025
- }
1026
- const { key, shiftKey } = e;
1027
- this.shouldSkipFocus = false;
1028
- switch (key) {
1029
- // Select the first available option
1030
- case keyHome: {
1031
- this.checkFirstOption(shiftKey);
1032
- return;
1033
- }
1034
- // Select the next selectable option
1035
- case keyArrowDown: {
1036
- this.checkNextOption(shiftKey);
1037
- return;
1038
- }
1039
- // Select the previous selectable option
1040
- case keyArrowUp: {
1041
- this.checkPreviousOption(shiftKey);
1042
- return;
1043
- }
1044
- // Select the last available option
1045
- case keyEnd: {
1046
- this.checkLastOption(shiftKey);
1047
- return;
1048
- }
1049
- case keyTab: {
1050
- this.focusAndScrollOptionIntoView();
1051
- return true;
1052
- }
1053
- case keyEscape: {
1054
- this.uncheckAllOptions();
1055
- this.checkActiveIndex();
1056
- return true;
1057
- }
1058
- case keySpace: {
1059
- e.preventDefault();
1060
- if (this.typeAheadExpired) {
1061
- this.toggleSelectedForAllCheckedOptions();
1062
- return;
1063
- }
1064
- }
1065
- // Send key to Typeahead handler
1066
- default: {
1067
- if (key.length === 1) {
1068
- this.handleTypeAhead(`${key}`);
1069
- }
1070
- return true;
1071
- }
1072
- }
1073
- }
1074
- /**
1075
- * Prevents `focusin` events from firing before `click` events when the
1076
- * element is unfocused.
1077
- *
1078
- * @override
1079
- * @internal
1080
- */
1081
- mousedownHandler(e) {
1082
- if (e.offsetX >= 0 && e.offsetX <= this.scrollWidth) {
1083
- return super.mousedownHandler(e);
1084
- }
1085
- }
1086
- /**
1087
- * Switches between single-selection and multi-selection mode.
1088
- *
1089
- * @internal
1090
- */
1091
- multipleChanged(prev, next) {
1092
- var _a;
1093
- this.ariaMultiSelectable = next ? "true" : null;
1094
- (_a = this.options) === null || _a === void 0 ? void 0 : _a.forEach(o => {
1095
- o.checked = next ? false : undefined;
1096
- });
1097
- this.setSelectedOptions();
1098
- }
1099
- /**
1100
- * Sets an option as selected and gives it focus.
1101
- *
1102
- * @override
1103
- * @public
1104
- */
1105
- setSelectedOptions() {
1106
- if (!this.multiple) {
1107
- super.setSelectedOptions();
1108
- return;
1109
- }
1110
- if (this.$fastController.isConnected && this.options) {
1111
- this.selectedOptions = this.options.filter(o => o.selected);
1112
- this.focusAndScrollOptionIntoView();
1113
- }
1114
- }
1115
- /**
1116
- * Ensures the size is a positive integer when the property is updated.
1117
- *
1118
- * @param prev - the previous size value
1119
- * @param next - the current size value
1120
- *
1121
- * @internal
1122
- */
1123
- sizeChanged(prev, next) {
1124
- var _a;
1125
- const size = Math.max(0, parseInt((_a = next === null || next === void 0 ? void 0 : next.toFixed()) !== null && _a !== void 0 ? _a : "", 10));
1126
- if (size !== next) {
1127
- DOM.queueUpdate(() => {
1128
- this.size = size;
1129
- });
1130
- }
1131
- }
1132
- /**
1133
- * Toggles the selected state of the provided options. If any provided items
1134
- * are in an unselected state, all items are set to selected. If every
1135
- * provided item is selected, they are all unselected.
1136
- *
1137
- * @internal
1138
- */
1139
- toggleSelectedForAllCheckedOptions() {
1140
- const enabledCheckedOptions = this.checkedOptions.filter(o => !o.disabled);
1141
- const force = !enabledCheckedOptions.every(o => o.selected);
1142
- enabledCheckedOptions.forEach(o => (o.selected = force));
1143
- this.selectedIndex = this.options.indexOf(enabledCheckedOptions[enabledCheckedOptions.length - 1]);
1144
- this.setSelectedOptions();
1145
- }
1146
- /**
1147
- * @override
1148
- * @internal
1149
- */
1150
- typeaheadBufferChanged(prev, next) {
1151
- if (!this.multiple) {
1152
- super.typeaheadBufferChanged(prev, next);
1153
- return;
1154
- }
1155
- if (this.$fastController.isConnected) {
1156
- const typeaheadMatches = this.getTypeaheadMatches();
1157
- const activeIndex = this.options.indexOf(typeaheadMatches[0]);
1158
- if (activeIndex > -1) {
1159
- this.activeIndex = activeIndex;
1160
- this.uncheckAllOptions();
1161
- this.checkActiveIndex();
1162
- }
1163
- this.typeAheadExpired = false;
1164
- }
1165
- }
1166
- /**
1167
- * Unchecks all options.
1168
- *
1169
- * @remarks
1170
- * Multiple-selection mode only.
1171
- *
1172
- * @param preserveChecked - reset the rangeStartIndex
1173
- *
1174
- * @internal
1175
- */
1176
- uncheckAllOptions(preserveChecked = false) {
1177
- this.options.forEach(o => (o.checked = this.multiple ? false : undefined));
1178
- if (!preserveChecked) {
1179
- this.rangeStartIndex = -1;
1180
- }
1181
- }
1182
- }
1183
- __decorate([
1184
- observable
1185
- ], ListboxElement.prototype, "activeIndex", void 0);
1186
- __decorate([
1187
- attr({ mode: "boolean" })
1188
- ], ListboxElement.prototype, "multiple", void 0);
1189
- __decorate([
1190
- attr({ converter: nullableNumberConverter })
1191
- ], ListboxElement.prototype, "size", void 0);
1192
-
1193
- var __defProp = Object.defineProperty;
1194
- var __decorateClass = (decorators, target, key, kind) => {
1195
- var result = void 0 ;
1196
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
1197
- if (decorator = decorators[i])
1198
- result = (decorator(target, key, result) ) || result;
1199
- if (result) __defProp(target, key, result);
1200
- return result;
1201
- };
1202
- class Listbox extends ListboxElement {
1203
- orientationChanged() {
1204
- if (this.orientation === "horizontal") {
1205
- this.addEventListener("keydown", this.#horizontalKeydownHandler);
1206
- } else {
1207
- this.removeEventListener("keydown", this.#horizontalKeydownHandler);
1208
- }
1209
- }
1210
- /**
1211
- * Handles `keydown` actions for horizontal listbox navigation and typeahead.
1212
- *
1213
- * @internal
1214
- */
1215
- #horizontalKeydownHandler(e) {
1216
- if (this.disabled) {
1217
- return true;
1218
- }
1219
- const key = e.key;
1220
- switch (key) {
1221
- case keyArrowRight: {
1222
- if (!e.shiftKey) {
1223
- e.preventDefault();
1224
- this.selectNextOption();
1225
- }
1226
- break;
1227
- }
1228
- case keyArrowLeft: {
1229
- if (!e.shiftKey) {
1230
- e.preventDefault();
1231
- this.selectPreviousOption();
1232
- }
1233
- break;
1234
- }
1235
- }
1236
- }
1237
- slottedOptionsChanged(prev, next) {
1238
- super.slottedOptionsChanged(prev, next);
1239
- this.#disableSlottedChildren();
1240
- }
1241
- attributeChangedCallback(name, oldValue, newValue) {
1242
- super.attributeChangedCallback(name, oldValue, newValue);
1243
- if (name === "disabled") {
1244
- this.#disableSlottedChildren();
1245
- }
1246
- }
1247
- #disableSlottedChildren() {
1248
- this.options.forEach((optionElement) => {
1249
- if (!optionElement.disabled) {
1250
- optionElement.disabled = this.disabled;
1251
- }
1252
- });
1253
- }
1254
- }
1255
- __decorateClass([
1256
- attr
1257
- ], Listbox.prototype, "appearance");
1258
- __decorateClass([
1259
- attr
1260
- ], Listbox.prototype, "orientation");
1261
- __decorateClass([
1262
- attr
1263
- ], Listbox.prototype, "shape");
1264
-
1265
- export { ListboxElement as L, Listbox as a };