@universal-material/web 3.6.10 → 3.6.12
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/app-bar/top-app-bar.js +1 -1
- package/app-bar/top-app-bar.js.map +1 -1
- package/button-field/button-field.js +1 -1
- package/button-field/button-field.js.map +1 -1
- package/custom-elements.json +5918 -6387
- package/dialog/dialog.js +4 -4
- package/dialog/dialog.js.map +1 -1
- package/index.d.ts +0 -2
- package/index.d.ts.map +1 -1
- package/index.js +0 -2
- package/index.js.map +1 -1
- package/overflow-menu/overflow-menu-item.d.ts +2 -1
- package/overflow-menu/overflow-menu-item.d.ts.map +1 -1
- package/overflow-menu/overflow-menu-item.js +10 -5
- package/overflow-menu/overflow-menu-item.js.map +1 -1
- package/overflow-menu/overflow-menu.d.ts +1 -1
- package/overflow-menu/overflow-menu.d.ts.map +1 -1
- package/overflow-menu/overflow-menu.js +17 -12
- package/overflow-menu/overflow-menu.js.map +1 -1
- package/overflow-menu/overflow-menu.styles.d.ts.map +1 -1
- package/overflow-menu/overflow-menu.styles.js +2 -1
- package/overflow-menu/overflow-menu.styles.js.map +1 -1
- package/package.json +3 -7
- package/select/option.d.ts +6 -6
- package/select/option.d.ts.map +1 -1
- package/select/option.js +46 -69
- package/select/option.js.map +1 -1
- package/select/option.styles.js +4 -4
- package/select/option.styles.js.map +1 -1
- package/select/select-navigation-controller.js +14 -14
- package/select/select-navigation-controller.js.map +1 -1
- package/select/select.d.ts +3 -3
- package/select/select.d.ts.map +1 -1
- package/select/select.js +40 -99
- package/select/select.js.map +1 -1
- package/shared/button-wrapper.d.ts.map +1 -1
- package/shared/button-wrapper.js +1 -1
- package/shared/button-wrapper.js.map +1 -1
- package/shared/menu-field/menu-field-navigation-controller.d.ts +1 -1
- package/shared/menu-field/menu-field-navigation-controller.d.ts.map +1 -1
- package/shared/menu-field/menu-field-navigation-controller.js +9 -9
- package/shared/menu-field/menu-field-navigation-controller.js.map +1 -1
- package/vscode.html-custom-data.json +332 -362
- package/grid/custom-swap.d.ts +0 -15
- package/grid/custom-swap.d.ts.map +0 -1
- package/grid/custom-swap.js +0 -62
- package/grid/custom-swap.js.map +0 -1
- package/grid/grid-column.d.ts +0 -11
- package/grid/grid-column.d.ts.map +0 -1
- package/grid/grid-column.js +0 -22
- package/grid/grid-column.js.map +0 -1
- package/grid/grid.d.ts +0 -23
- package/grid/grid.d.ts.map +0 -1
- package/grid/grid.js +0 -231
- package/grid/grid.js.map +0 -1
- package/grid/grid.styles.d.ts +0 -2
- package/grid/grid.styles.d.ts.map +0 -1
- package/grid/grid.styles.js +0 -134
- package/grid/grid.styles.js.map +0 -1
- package/select/extended-option.d.ts +0 -5
- package/select/extended-option.d.ts.map +0 -1
- package/select/extended-option.js +0 -2
- package/select/extended-option.js.map +0 -1
- package/select/extended-select.d.ts +0 -6
- package/select/extended-select.d.ts.map +0 -1
- package/select/extended-select.js +0 -2
- package/select/extended-select.js.map +0 -1
package/select/option.js
CHANGED
|
@@ -1,49 +1,48 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { svg } from 'lit';
|
|
3
|
-
import { customElement, property
|
|
3
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
4
4
|
import { UmMenuItem } from '../menu/menu-item.js';
|
|
5
5
|
import { styles } from './option.styles.js';
|
|
6
|
-
import { UmSelect } from './select.js';
|
|
7
6
|
import './select.js';
|
|
8
7
|
let UmOption = class UmOption extends UmMenuItem {
|
|
9
8
|
constructor() {
|
|
10
9
|
super(...arguments);
|
|
11
|
-
this
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
option.setAttribute('selected', '');
|
|
16
|
-
}
|
|
17
|
-
option.textContent = this.textContent;
|
|
18
|
-
return option;
|
|
19
|
-
})();
|
|
10
|
+
this.#mutationObserver = new MutationObserver(() => this.#updateContent());
|
|
11
|
+
this.#value = '';
|
|
12
|
+
this.#selected = false;
|
|
13
|
+
this._nativeOption = null;
|
|
20
14
|
}
|
|
21
15
|
static { this.styles = [UmMenuItem.styles, styles]; }
|
|
16
|
+
#mutationObserver;
|
|
17
|
+
#value;
|
|
18
|
+
#selected;
|
|
22
19
|
get value() {
|
|
23
|
-
return this
|
|
20
|
+
return this.#value;
|
|
24
21
|
}
|
|
25
22
|
set value(value) {
|
|
26
|
-
this
|
|
23
|
+
this.#value = value;
|
|
24
|
+
if (this._nativeOption) {
|
|
25
|
+
this._nativeOption.value = value;
|
|
26
|
+
}
|
|
27
27
|
}
|
|
28
28
|
get selected() {
|
|
29
|
-
return this
|
|
29
|
+
return this.#selected;
|
|
30
30
|
}
|
|
31
31
|
set selected(selected) {
|
|
32
|
-
if (this
|
|
32
|
+
if (this.#selected === selected) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
|
-
this
|
|
36
|
-
if (
|
|
37
|
-
this.
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this.classList.remove('selected');
|
|
41
|
-
}
|
|
42
|
-
if (!this._select) {
|
|
43
|
-
return;
|
|
35
|
+
this.#selected = selected;
|
|
36
|
+
if (this._nativeOption) {
|
|
37
|
+
this._nativeOption.selected = selected;
|
|
44
38
|
}
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
this._select?._updateEmpty();
|
|
40
|
+
}
|
|
41
|
+
_getContainerClasses() {
|
|
42
|
+
return {
|
|
43
|
+
...super._getContainerClasses(),
|
|
44
|
+
selected: this.selected,
|
|
45
|
+
};
|
|
47
46
|
}
|
|
48
47
|
_renderDefaultTrailingIcon() {
|
|
49
48
|
return svg `
|
|
@@ -51,80 +50,58 @@ let UmOption = class UmOption extends UmMenuItem {
|
|
|
51
50
|
<path d="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z"/>
|
|
52
51
|
</svg>`;
|
|
53
52
|
}
|
|
54
|
-
get
|
|
55
|
-
return this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
set _selectedAttribute(selected) {
|
|
59
|
-
if (selected) {
|
|
60
|
-
this._nativeOption.setAttribute('selected', '');
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
this._nativeOption.removeAttribute('selected');
|
|
53
|
+
get _select() {
|
|
54
|
+
return this.parentElement?.tagName === 'U-SELECT'
|
|
55
|
+
? this.parentElement
|
|
56
|
+
: null;
|
|
64
57
|
}
|
|
65
58
|
connectedCallback() {
|
|
66
59
|
super.connectedCallback();
|
|
67
60
|
this.addEventListener('click', this.#handleClick);
|
|
68
61
|
this.setAttribute('tabindex', '-1');
|
|
69
|
-
this.#
|
|
62
|
+
this.#mutationObserver.observe(this, {
|
|
63
|
+
subtree: true,
|
|
64
|
+
characterData: true,
|
|
65
|
+
childList: true,
|
|
66
|
+
});
|
|
67
|
+
this.#updateContent();
|
|
70
68
|
}
|
|
71
69
|
disconnectedCallback() {
|
|
72
70
|
super.disconnectedCallback();
|
|
73
71
|
this.removeEventListener('click', this.#handleClick);
|
|
74
|
-
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
this._nativeOption.remove();
|
|
78
|
-
if (!this._select) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
this._select.value = this._select.value;
|
|
82
|
-
this._select = null;
|
|
83
|
-
}
|
|
84
|
-
async #attach() {
|
|
85
|
-
if (this._select === this.parentElement) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
this._select = this.parentElement instanceof UmSelect ? this.parentElement : null;
|
|
89
|
-
await this.#setNativeOption();
|
|
72
|
+
this.#mutationObserver.disconnect();
|
|
90
73
|
}
|
|
91
74
|
#handleClick(e) {
|
|
92
75
|
if (!this._select) {
|
|
93
76
|
return;
|
|
94
77
|
}
|
|
95
78
|
e.stopPropagation();
|
|
96
|
-
this.
|
|
79
|
+
this._setSelectedByUser();
|
|
97
80
|
}
|
|
98
|
-
|
|
81
|
+
_setSelectedByUser() {
|
|
82
|
+
this.selected = true;
|
|
99
83
|
if (!this._select) {
|
|
100
84
|
return;
|
|
101
85
|
}
|
|
102
|
-
this._select.selectedOptions[0]?.classList.remove('selected');
|
|
103
|
-
this.selected = true;
|
|
104
|
-
this._select.value = this._select.value;
|
|
105
86
|
this._select.dispatchEvent(new InputEvent('input', { bubbles: true, composed: true }));
|
|
106
87
|
this._select.dispatchEvent(new Event('change', { bubbles: true }));
|
|
88
|
+
this._select._updateEmpty();
|
|
89
|
+
this._select._syncSelectedOptions();
|
|
107
90
|
this._select._menu?.close();
|
|
108
91
|
}
|
|
109
92
|
#updateContent() {
|
|
110
|
-
this._nativeOption
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.#updateContent();
|
|
115
|
-
this._select?._updateOptions();
|
|
93
|
+
if (this._nativeOption) {
|
|
94
|
+
this._nativeOption.textContent = this.textContent;
|
|
95
|
+
}
|
|
96
|
+
this._select?._updateEmpty();
|
|
116
97
|
}
|
|
117
98
|
};
|
|
118
99
|
__decorate([
|
|
119
100
|
property({ reflect: true })
|
|
120
101
|
], UmOption.prototype, "value", null);
|
|
121
102
|
__decorate([
|
|
122
|
-
|
|
103
|
+
property({ type: Boolean })
|
|
123
104
|
], UmOption.prototype, "selected", null);
|
|
124
|
-
__decorate([
|
|
125
|
-
property({ type: Boolean, attribute: 'selected' })
|
|
126
|
-
// @ts-ignore
|
|
127
|
-
], UmOption.prototype, "_selectedAttribute", null);
|
|
128
105
|
UmOption = __decorate([
|
|
129
106
|
customElement('u-option')
|
|
130
107
|
], UmOption);
|
package/select/option.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option.js","sourceRoot":"","sources":["../../src/select/option.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAkB,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"option.js","sourceRoot":"","sources":["../../src/select/option.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAkB,MAAM,KAAK,CAAC;AAC1C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CAAC;QAED,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACvF,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAEnE,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC5B,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;QACpC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;IAED,cAAc;QAEZ,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,IAAI,CAAC,aAAa,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpD,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC;IAC/B,CAAC;;AAxGD;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;qCAG3B;AAWD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;wCAG3B;AAzBU,QAAQ;IADpB,aAAa,CAAC,UAAU,CAAC;GACb,QAAQ,CAmHpB","sourcesContent":["import { svg, TemplateResult } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\n\nimport { UmMenuItem } from '../menu/menu-item.js';\nimport { styles } from './option.styles.js';\nimport { UmSelect } from './select.js';\n\nimport './select.js';\n\n@customElement('u-option')\nexport class UmOption extends UmMenuItem {\n static override styles = [UmMenuItem.styles, styles];\n\n readonly #mutationObserver = new MutationObserver(() => this.#updateContent());\n\n #value = '';\n #selected = false;\n _nativeOption: HTMLOptionElement | null = null;\n\n @property({ reflect: true })\n get value(): string {\n return this.#value;\n }\n\n set value(value: string) {\n this.#value = value;\n\n if (this._nativeOption) {\n this._nativeOption.value = value;\n }\n }\n\n @property({ type: Boolean })\n get selected(): boolean {\n return this.#selected;\n }\n\n set selected(selected: boolean) {\n if (this.#selected === selected) {\n return;\n }\n\n this.#selected = selected;\n\n if (this._nativeOption) {\n this._nativeOption.selected = selected;\n }\n\n this._select?._updateEmpty();\n }\n\n protected override _getContainerClasses() {\n return {\n ...super._getContainerClasses(),\n selected: this.selected,\n };\n }\n\n protected override _renderDefaultTrailingIcon(): TemplateResult {\n return svg`\n <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"1em\" viewBox=\"0 -960 960 960\" width=\"1em\" fill=\"currentColor\">\n <path d=\"M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z\"/>\n </svg>`;\n }\n\n get _select(): UmSelect | null {\n return this.parentElement?.tagName === 'U-SELECT'\n ? this.parentElement as UmSelect\n : null;\n }\n\n override connectedCallback() {\n super.connectedCallback();\n this.addEventListener('click', this.#handleClick);\n this.setAttribute('tabindex', '-1');\n\n this.#mutationObserver.observe(this, {\n subtree: true,\n characterData: true,\n childList: true,\n });\n\n this.#updateContent();\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n this.removeEventListener('click', this.#handleClick);\n this.#mutationObserver.disconnect();\n }\n\n #handleClick(e: Event) {\n if (!this._select) {\n return;\n }\n\n e.stopPropagation();\n\n this._setSelectedByUser();\n }\n\n _setSelectedByUser() {\n\n this.selected = true;\n\n if (!this._select) {\n return;\n }\n\n this._select.dispatchEvent(new InputEvent('input', { bubbles: true, composed: true }));\n this._select.dispatchEvent(new Event('change', { bubbles: true }));\n\n this._select._updateEmpty();\n this._select._syncSelectedOptions();\n this._select._menu?.close();\n }\n\n #updateContent() {\n\n if (this._nativeOption) {\n this._nativeOption.textContent = this.textContent;\n }\n\n this._select?._updateEmpty();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'u-option': UmOption;\n }\n}\n"]}
|
package/select/option.styles.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { css } from 'lit';
|
|
2
2
|
export const styles = css `
|
|
3
|
-
|
|
3
|
+
.selected {
|
|
4
4
|
background-color: var(--u-select-option-selected-bg-color, color-mix(in srgb, var(--u-color-primary, rgb(103, 80, 164)) 12%, transparent));
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
.selected .icon,
|
|
7
|
+
.selected .content {
|
|
8
8
|
color: var(--u-select-option-selected-text-color, var(--u-color-primary, rgb(103, 80, 164)));
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
:
|
|
11
|
+
.container:not(.selected):not(.trailing-icon) .trailing {
|
|
12
12
|
display: none;
|
|
13
13
|
}
|
|
14
14
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option.styles.js","sourceRoot":"","sources":["../../src/select/option.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAC;;;;;;;;;;;;CAYzB,CAAC","sourcesContent":["import { css } from 'lit';\n\nexport const styles = css `\n
|
|
1
|
+
{"version":3,"file":"option.styles.js","sourceRoot":"","sources":["../../src/select/option.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAC;;;;;;;;;;;;CAYzB,CAAC","sourcesContent":["import { css } from 'lit';\n\nexport const styles = css `\n .selected {\n background-color: var(--u-select-option-selected-bg-color, color-mix(in srgb, var(--u-color-primary, rgb(103, 80, 164)) 12%, transparent));\n }\n .selected .icon,\n .selected .content {\n color: var(--u-select-option-selected-text-color, var(--u-color-primary, rgb(103, 80, 164)));\n }\n\n .container:not(.selected):not(.trailing-icon) .trailing {\n display: none;\n }\n`;\n"]}
|
|
@@ -9,7 +9,7 @@ const getCleanTypeaheadStatus = () => ({
|
|
|
9
9
|
export class SelectNavigationController extends MenuFieldNavigationController {
|
|
10
10
|
#typeaheadStatus = getCleanTypeaheadStatus();
|
|
11
11
|
handleKeyDown(event) {
|
|
12
|
-
if (this.
|
|
12
|
+
if (this.getHost()._menu.open) {
|
|
13
13
|
const handled = super.handleKeyDown(event);
|
|
14
14
|
return handled || this.handleType(event);
|
|
15
15
|
}
|
|
@@ -19,32 +19,32 @@ export class SelectNavigationController extends MenuFieldNavigationController {
|
|
|
19
19
|
return this.handleType(event);
|
|
20
20
|
}
|
|
21
21
|
event.preventDefault();
|
|
22
|
-
this.
|
|
23
|
-
if (!this.
|
|
22
|
+
this.getHost()._menu.show();
|
|
23
|
+
if (!this.getHost().selectedOptions.length) {
|
|
24
24
|
return true;
|
|
25
25
|
}
|
|
26
|
-
const option = this.
|
|
27
|
-
this.navigateTo(event, option, this.
|
|
26
|
+
const option = this.getHost().selectedOptions[0];
|
|
27
|
+
this.navigateTo(event, option, this.getHost()._menuItems.indexOf(option));
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
30
|
attach(element) {
|
|
31
31
|
super.attach(element);
|
|
32
|
-
this.
|
|
32
|
+
this.getHost()._menu.addEventListener('menu-item-mouseenter', this.#handleMouseFocus);
|
|
33
33
|
}
|
|
34
34
|
detach() {
|
|
35
35
|
super.detach();
|
|
36
|
-
this.
|
|
36
|
+
this.getHost()._menu.removeEventListener('menu-item-mouseenter', this.#handleMouseFocus);
|
|
37
37
|
}
|
|
38
38
|
#handleMouseFocus = (e) => {
|
|
39
39
|
this.blurMenu();
|
|
40
40
|
const option = e.target;
|
|
41
|
-
this.focusMenu(option, this.
|
|
41
|
+
this.focusMenu(option, this.getHost()._menuItems.indexOf(option), false, false);
|
|
42
42
|
};
|
|
43
43
|
afterFocus(_, index) {
|
|
44
|
-
this.
|
|
44
|
+
this.getHost()._button.setAttribute('aria-activedescendant', `item-${index + 1}`);
|
|
45
45
|
}
|
|
46
46
|
afterBlur() {
|
|
47
|
-
this.
|
|
47
|
+
this.getHost()._button.removeAttribute('aria-activedescendant');
|
|
48
48
|
}
|
|
49
49
|
handleType(event) {
|
|
50
50
|
if (event.key.length > 1) {
|
|
@@ -61,9 +61,9 @@ export class SelectNavigationController extends MenuFieldNavigationController {
|
|
|
61
61
|
return true;
|
|
62
62
|
}
|
|
63
63
|
findNextElementByTerm(term, lastFocusedMenu) {
|
|
64
|
-
const options = this.
|
|
64
|
+
const options = this.getHost()._options;
|
|
65
65
|
const lastFocusedMenuIndex = lastFocusedMenu ? options.indexOf(lastFocusedMenu) : -1;
|
|
66
|
-
let nextMenu = lastFocusedMenuIndex > -1 ? this.
|
|
66
|
+
let nextMenu = lastFocusedMenuIndex > -1 ? this.getHost()._options[lastFocusedMenuIndex + 1] : null;
|
|
67
67
|
if (!nextMenu || !normalizedStartsWith(nextMenu.textContent, term)) {
|
|
68
68
|
nextMenu = options.find(o => normalizedStartsWith(o.textContent, term));
|
|
69
69
|
}
|
|
@@ -71,12 +71,12 @@ export class SelectNavigationController extends MenuFieldNavigationController {
|
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
const nextMenuIndex = options.indexOf(nextMenu);
|
|
74
|
-
if (this.
|
|
74
|
+
if (this.getHost()._menu.open) {
|
|
75
75
|
this.blurMenu();
|
|
76
76
|
this.focusMenu(nextMenu, nextMenuIndex);
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
|
-
nextMenu.
|
|
79
|
+
nextMenu._setSelectedByUser();
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
//# sourceMappingURL=select-navigation-controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-navigation-controller.js","sourceRoot":"","sources":["../../src/select/select-navigation-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0DAA0D,CAAC;AAIzG,MAAM,uBAAuB,GAAG,GAAG,EAAE,CAAC,CAAC;IACrC,MAAM,EAAE,KAAK;IACb,SAAS,EAAE,KAAK;IAChB,MAAM,EAAE,EAAE;IACV,SAAS,EAAE,CAAC;CACb,CAAC,CAAC;AAEH,MAAM,OAAO,0BAA2B,SAAQ,6BAAiD;IAC/F,gBAAgB,GAAG,uBAAuB,EAAE,CAAC;IAE1B,aAAa,CAAC,KAAoB;QACnD,IAAI,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"select-navigation-controller.js","sourceRoot":"","sources":["../../src/select/select-navigation-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0DAA0D,CAAC;AAIzG,MAAM,uBAAuB,GAAG,GAAG,EAAE,CAAC,CAAC;IACrC,MAAM,EAAE,KAAK;IACb,SAAS,EAAE,KAAK;IAChB,MAAM,EAAE,EAAE;IACV,SAAS,EAAE,CAAC;CACb,CAAC,CAAC;AAEH,MAAM,OAAO,0BAA2B,SAAQ,6BAAiD;IAC/F,gBAAgB,GAAG,uBAAuB,EAAE,CAAC;IAE1B,aAAa,CAAC,KAAoB;QACnD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAE3C,OAAO,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC3C,CAAC;QAED,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,KAAK,WAAW,CAAC;QACzC,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,SAAS,CAAC;QAErC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;QAED,KAAK,CAAC,cAAc,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,EAAE,CAAC,K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,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,oBAAoB,GAAG,CAAC,CAAyB,CAAC,CAAC,CAAC,IAAI,CAAC;QAE/G,IAAI,CAAC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC;YACnE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;QAC1E,CAAC;QAED,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO;QACT,CAAC;QAED,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAEhD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAC9B,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;YACxC,OAAO;QACT,CAAC;QAED,QAAQ,CAAC,kBAAkB,EAAE,CAAC;IAChC,CAAC;CACF","sourcesContent":["import { normalizedStartsWith } from '../shared/compare-text.js';\nimport { MenuFieldNavigationController } from '../shared/menu-field/menu-field-navigation-controller.js';\nimport { UmOption } from './option.js';\nimport { UmSelect } from './select.js';\n\nconst getCleanTypeaheadStatus = () => ({\n typing: false,\n repeating: false,\n buffer: '',\n timeoutId: 0,\n});\n\nexport class SelectNavigationController extends MenuFieldNavigationController<UmSelect, UmOption> {\n #typeaheadStatus = getCleanTypeaheadStatus();\n\n protected override handleKeyDown(event: KeyboardEvent): boolean {\n if (this.getHost()._menu.open) {\n const handled = super.handleKeyDown(event);\n\n return handled || this.handleType(event);\n }\n\n const isDown = event.key === 'ArrowDown';\n const isUp = event.key === 'ArrowUp';\n\n if (!isDown && !isUp) {\n return this.handleType(event);\n }\n\n event.preventDefault();\n this.getHost()._menu.show();\n\n if (!this.getHost().selectedOptions.length) {\n return true;\n }\n\n const option = this.getHost().selectedOptions[0];\n this.navigateTo(event, option, this.getHost()._menuItems.indexOf(option));\n return true;\n }\n\n override attach(element: HTMLElement) {\n super.attach(element);\n this.getHost()._menu.addEventListener('menu-item-mouseenter', this.#handleMouseFocus);\n }\n\n override detach() {\n super.detach();\n this.getHost()._menu.removeEventListener('menu-item-mouseenter', this.#handleMouseFocus);\n }\n\n readonly #handleMouseFocus = (e: Event) => {\n this.blurMenu();\n const option = e.target as UmOption;\n this.focusMenu(option, this.getHost()._menuItems.indexOf(option), false, false);\n };\n\n protected override afterFocus(_: UmOption, index: number) {\n this.getHost()._button.setAttribute('aria-activedescendant', `item-${index + 1}`);\n }\n\n protected override afterBlur() {\n this.getHost()._button.removeAttribute('aria-activedescendant');\n }\n\n private handleType(event: KeyboardEvent) {\n if (event.key.length > 1) {\n return false;\n }\n\n if (this.#typeaheadStatus.timeoutId) {\n clearTimeout(this.#typeaheadStatus.timeoutId);\n }\n\n const lastFocusedMenu = this.focusedMenu;\n\n this.#typeaheadStatus.buffer += event.key;\n\n this.#typeaheadStatus.timeoutId = setTimeout(() => this.#typeaheadStatus = getCleanTypeaheadStatus(), 1000);\n\n const term =\n this.#typeaheadStatus.buffer.replaceAll(event.key, '') === '' ? event.key : this.#typeaheadStatus.buffer;\n this.findNextElementByTerm(term, lastFocusedMenu);\n\n return true;\n }\n\n private findNextElementByTerm(term: string, lastFocusedMenu: UmOption | null): void {\n const options = this.getHost()._options;\n const lastFocusedMenuIndex = lastFocusedMenu ? options.indexOf(lastFocusedMenu) : -1;\n\n let nextMenu =\n lastFocusedMenuIndex > -1 ? this.getHost()._options[lastFocusedMenuIndex + 1] as UmOption | undefined : null;\n\n if (!nextMenu || !normalizedStartsWith(nextMenu.textContent, term)) {\n nextMenu = options.find(o => normalizedStartsWith(o.textContent, term));\n }\n\n if (!nextMenu) {\n return;\n }\n\n const nextMenuIndex = options.indexOf(nextMenu);\n\n if (this.getHost()._menu.open) {\n this.blurMenu();\n this.focusMenu(nextMenu, nextMenuIndex);\n return;\n }\n\n nextMenu._setSelectedByUser();\n }\n}\n"]}
|
package/select/select.d.ts
CHANGED
|
@@ -3,13 +3,12 @@ import { TemplateResult } from 'lit';
|
|
|
3
3
|
import { UmMenu } from '../menu/menu.js';
|
|
4
4
|
import { UmMenuField } from '../shared/menu-field/menu-field.js';
|
|
5
5
|
import { UmTextFieldBase } from '../shared/text-field-base/text-field-base.js';
|
|
6
|
-
import { ExtendedSelect } from './extended-select.js';
|
|
7
6
|
import { UmOption } from './option.js';
|
|
8
7
|
import './option.js';
|
|
9
8
|
export declare class UmSelect extends UmTextFieldBase implements UmMenuField {
|
|
10
9
|
#private;
|
|
11
10
|
static styles: import("lit").CSSResultGroup[];
|
|
12
|
-
_nativeSelect:
|
|
11
|
+
_nativeSelect: HTMLSelectElement;
|
|
13
12
|
/**
|
|
14
13
|
* The `value` of the selected option
|
|
15
14
|
*/
|
|
@@ -30,7 +29,6 @@ export declare class UmSelect extends UmTextFieldBase implements UmMenuField {
|
|
|
30
29
|
get selectedOptions(): UmOption[];
|
|
31
30
|
get _options(): UmOption[];
|
|
32
31
|
constructor();
|
|
33
|
-
_updateOptions(): void;
|
|
34
32
|
protected renderControl(): TemplateResult;
|
|
35
33
|
protected renderAfterContent(): TemplateResult;
|
|
36
34
|
protected renderDefaultTrailingIcon(): TemplateResult;
|
|
@@ -38,7 +36,9 @@ export declare class UmSelect extends UmTextFieldBase implements UmMenuField {
|
|
|
38
36
|
attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
|
|
39
37
|
connectedCallback(): void;
|
|
40
38
|
disconnectedCallback(): void;
|
|
39
|
+
_updateEmpty(): void;
|
|
41
40
|
get _menuItems(): UmOption[];
|
|
41
|
+
_syncSelectedOptions(): void;
|
|
42
42
|
}
|
|
43
43
|
declare global {
|
|
44
44
|
interface HTMLElementTagNameMap {
|
package/select/select.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/select/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/select/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAqB,cAAc,EAAE,MAAM,KAAK,CAAC;AAKxD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIvC,OAAO,aAAa,CAAC;AAErB,qBACa,QAAS,SAAQ,eAAgB,YAAW,WAAW;;IAClE,OAAgB,MAAM,iCAAoC;IAE1D,aAAa,oBAAoC;IAejD;;OAEG;IACH,IACI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAQtB;IAEsB,KAAK,EAAG,MAAM,CAAC;IACd,OAAO,EAAG,iBAAiB,CAAC;IAC7B,MAAM,EAAG,WAAW,CAAC;IAEgB,eAAe,EAAE,UAAU,GAAG,OAAO,CAAc;IAE/G;;OAEG;IACH,IACI,aAAa,IAAI,MAAM,CAE1B;IAED,IAAI,aAAa,CAAC,KAAK,EAAE,MAAM,EAE9B;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,QAAQ,EAAE,CAIhC;IAED,IAAI,QAAQ,IAAI,QAAQ,EAAE,CAIzB;;cAakB,aAAa,IAAI,cAAc;cAW/B,kBAAkB,IAAI,cAAc;cAQpC,yBAAyB,IAAI,cAAc;cAO3C,OAAO,CAAC,iBAAiB,EAAE,cAAc;IAMnD,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAUhF,iBAAiB;IAOjB,oBAAoB;IA+E7B,YAAY,IAAI,IAAI;IAIpB,IAAI,UAAU,IAAI,QAAQ,EAAE,CAE3B;IAoBD,oBAAoB;CASrB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,UAAU,EAAE,QAAQ,CAAC;KACtB;CACF"}
|
package/select/select.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { html, svg } from 'lit';
|
|
2
|
+
import { html, render, svg } from 'lit';
|
|
3
3
|
import { customElement, property, query, state } from 'lit/decorators.js';
|
|
4
|
+
import { map } from 'lit/directives/map.js';
|
|
4
5
|
import { html as staticHtml } from 'lit/static-html.js';
|
|
5
6
|
import { UmTextFieldBase } from '../shared/text-field-base/text-field-base.js';
|
|
6
7
|
import { UmOption } from './option.js';
|
|
@@ -12,7 +13,6 @@ let UmSelect = class UmSelect extends UmTextFieldBase {
|
|
|
12
13
|
#list;
|
|
13
14
|
#navigationController;
|
|
14
15
|
#resizeObserver;
|
|
15
|
-
#mutationObserver;
|
|
16
16
|
#connected;
|
|
17
17
|
/**
|
|
18
18
|
* The `value` of the selected option
|
|
@@ -40,7 +40,9 @@ let UmSelect = class UmSelect extends UmTextFieldBase {
|
|
|
40
40
|
* An `Array` containing the selected `UmOption` or empty if there's no selected option. Multiple selection is not supported.
|
|
41
41
|
*/
|
|
42
42
|
get selectedOptions() {
|
|
43
|
-
return this._nativeSelect.selectedOptions.length
|
|
43
|
+
return this._nativeSelect.selectedOptions.length
|
|
44
|
+
? [this._options[this._nativeSelect.selectedIndex]]
|
|
45
|
+
: [];
|
|
44
46
|
}
|
|
45
47
|
get _options() {
|
|
46
48
|
const options = Array.from(this.querySelectorAll('u-option'));
|
|
@@ -48,12 +50,7 @@ let UmSelect = class UmSelect extends UmTextFieldBase {
|
|
|
48
50
|
}
|
|
49
51
|
constructor() {
|
|
50
52
|
super();
|
|
51
|
-
this._nativeSelect = (
|
|
52
|
-
const select = document.createElement('select');
|
|
53
|
-
select.setAttribute('tabindex', '-1');
|
|
54
|
-
select.setAttribute('part', 'select');
|
|
55
|
-
return select;
|
|
56
|
-
})();
|
|
53
|
+
this._nativeSelect = document.createElement('select');
|
|
57
54
|
this.#list = (() => {
|
|
58
55
|
const list = document.createElement('div');
|
|
59
56
|
list.role = 'listbox';
|
|
@@ -62,6 +59,7 @@ let UmSelect = class UmSelect extends UmTextFieldBase {
|
|
|
62
59
|
return list;
|
|
63
60
|
})();
|
|
64
61
|
this.#navigationController = new SelectNavigationController(this);
|
|
62
|
+
this.#resizeObserver = new ResizeObserver(() => this.#setMenuWidthProperty());
|
|
65
63
|
this.#connected = false;
|
|
66
64
|
this.menuPositioning = 'relative';
|
|
67
65
|
this.#handleClick = (e) => {
|
|
@@ -73,7 +71,6 @@ let UmSelect = class UmSelect extends UmTextFieldBase {
|
|
|
73
71
|
};
|
|
74
72
|
this.#handleMenuOpen = () => {
|
|
75
73
|
this._button.setAttribute('aria-expanded', 'true');
|
|
76
|
-
this.#setSelectedOption();
|
|
77
74
|
};
|
|
78
75
|
this.#handleMenuOpened = () => {
|
|
79
76
|
if (!this.selectedOptions.length) {
|
|
@@ -86,92 +83,12 @@ let UmSelect = class UmSelect extends UmTextFieldBase {
|
|
|
86
83
|
this._button.setAttribute('aria-expanded', 'false');
|
|
87
84
|
this.#navigationController.blurMenu();
|
|
88
85
|
};
|
|
89
|
-
this
|
|
90
|
-
this
|
|
91
|
-
this.#mutationObserver = new MutationObserver(() => this._updateOptions());
|
|
92
|
-
this.#mutationObserver.observe(this, {
|
|
93
|
-
characterData: true,
|
|
94
|
-
childList: true,
|
|
95
|
-
subtree: true,
|
|
96
|
-
});
|
|
86
|
+
this._nativeSelect.setAttribute('tabindex', '-1');
|
|
87
|
+
this._nativeSelect.setAttribute('part', 'select');
|
|
97
88
|
}
|
|
98
89
|
#setMenuWidthProperty() {
|
|
99
90
|
this.style.setProperty('--_menu-width', `${this.clientWidth}px`);
|
|
100
91
|
}
|
|
101
|
-
_updateOptions() {
|
|
102
|
-
const options = this._options;
|
|
103
|
-
for (const option of options) {
|
|
104
|
-
option._select = this;
|
|
105
|
-
}
|
|
106
|
-
this.#updateOptions(options);
|
|
107
|
-
this.#updateAccessibilityList(options);
|
|
108
|
-
const selectedOption = this.selectedOptions[0];
|
|
109
|
-
if (!selectedOption) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
selectedOption.selected = selectedOption.selected;
|
|
113
|
-
this.empty = !selectedOption.textContent?.trim();
|
|
114
|
-
// this._button.setAttribute('aria-labelledby', selectedOption._listItem.id);
|
|
115
|
-
}
|
|
116
|
-
#updateOptions(options) {
|
|
117
|
-
const maxLength = Math.max(options.length, this._nativeSelect.children.length);
|
|
118
|
-
for (let i = 0; i < maxLength; i++) {
|
|
119
|
-
const option = options[i];
|
|
120
|
-
const nativeOption = this._nativeSelect.children[i];
|
|
121
|
-
if (!option) {
|
|
122
|
-
nativeOption?.remove();
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
option._nativeOption.textContent = option.textContent;
|
|
126
|
-
if (!nativeOption) {
|
|
127
|
-
this._nativeSelect.appendChild(option._nativeOption);
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
nativeOption.insertAdjacentElement('beforebegin', option._nativeOption);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
#updateAccessibilityList(options) {
|
|
134
|
-
const maxLength = Math.max(options.length, this.#list.children.length);
|
|
135
|
-
for (let i = 0; i < maxLength; i++) {
|
|
136
|
-
const option = options[i];
|
|
137
|
-
let item = this.#list.children[i];
|
|
138
|
-
if (!option) {
|
|
139
|
-
item?.remove();
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
if (!item) {
|
|
143
|
-
item = this.#createListItem(`item-${i + 1}`);
|
|
144
|
-
this.#list.appendChild(item);
|
|
145
|
-
}
|
|
146
|
-
item.textContent = option.textContent;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
#createListItem(id) {
|
|
150
|
-
const item = document.createElement('div');
|
|
151
|
-
item.role = 'option';
|
|
152
|
-
item.id = id;
|
|
153
|
-
item.textContent = this.textContent;
|
|
154
|
-
return item;
|
|
155
|
-
}
|
|
156
|
-
#setSelectedOption() {
|
|
157
|
-
const options = this._options;
|
|
158
|
-
const selectedClassOptions = options.filter(o => o.classList.contains('selected'));
|
|
159
|
-
let found = false;
|
|
160
|
-
for (const option of selectedClassOptions) {
|
|
161
|
-
if (option.selected) {
|
|
162
|
-
found = true;
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
option.classList.remove('selected');
|
|
166
|
-
}
|
|
167
|
-
if (found) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
const selectedOption = this.selectedOptions[0];
|
|
171
|
-
if (selectedOption) {
|
|
172
|
-
selectedOption.classList.add('selected');
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
92
|
renderControl() {
|
|
176
93
|
return staticHtml `
|
|
177
94
|
<button
|
|
@@ -185,7 +102,7 @@ let UmSelect = class UmSelect extends UmTextFieldBase {
|
|
|
185
102
|
renderAfterContent() {
|
|
186
103
|
return html `
|
|
187
104
|
<u-menu positioning="${this.menuPositioning}">
|
|
188
|
-
<slot></slot>
|
|
105
|
+
<slot @slotchange=${this.#renderOptionRelatedElements}></slot>
|
|
189
106
|
</u-menu>
|
|
190
107
|
`;
|
|
191
108
|
}
|
|
@@ -224,13 +141,12 @@ let UmSelect = class UmSelect extends UmTextFieldBase {
|
|
|
224
141
|
#handleMenuOpened;
|
|
225
142
|
#handleMenuClose;
|
|
226
143
|
async #attach() {
|
|
144
|
+
this.#resizeObserver.observe(this);
|
|
145
|
+
this.#renderOptionRelatedElements();
|
|
227
146
|
await this.updateComplete;
|
|
228
147
|
this._nativeSelect.disabled = this.hasAttribute('disabled');
|
|
229
148
|
this.#navigationController.attach(this);
|
|
230
|
-
this.
|
|
231
|
-
if (this._nativeSelect.parentElement !== this._input) {
|
|
232
|
-
this._input.appendChild(this._nativeSelect);
|
|
233
|
-
}
|
|
149
|
+
this._input.appendChild(this._nativeSelect);
|
|
234
150
|
this._input.appendChild(this.#list);
|
|
235
151
|
this._button.addEventListener('click', this.#handleClick);
|
|
236
152
|
this._menu.anchorElement = this._container;
|
|
@@ -239,8 +155,10 @@ let UmSelect = class UmSelect extends UmTextFieldBase {
|
|
|
239
155
|
this._menu.addEventListener('opened', this.#handleMenuOpened);
|
|
240
156
|
this._menu.addEventListener('close', this.#handleMenuClose);
|
|
241
157
|
}
|
|
242
|
-
|
|
243
|
-
|
|
158
|
+
#detach() {
|
|
159
|
+
this.#resizeObserver.disconnect();
|
|
160
|
+
this._nativeSelect.remove();
|
|
161
|
+
this.#list.remove();
|
|
244
162
|
this.#navigationController.detach();
|
|
245
163
|
this.#connected = false;
|
|
246
164
|
this._button.removeEventListener('click', this.#handleClick);
|
|
@@ -249,9 +167,32 @@ let UmSelect = class UmSelect extends UmTextFieldBase {
|
|
|
249
167
|
this._menu.removeEventListener('opened', this.#handleMenuOpened);
|
|
250
168
|
this._menu.removeEventListener('close', this.#handleMenuClose);
|
|
251
169
|
}
|
|
170
|
+
#renderOptionRelatedElements() {
|
|
171
|
+
this.#renderNativeOptions();
|
|
172
|
+
this.#renderAccessibilityList();
|
|
173
|
+
this._updateEmpty();
|
|
174
|
+
this._syncSelectedOptions();
|
|
175
|
+
}
|
|
176
|
+
_updateEmpty() {
|
|
177
|
+
this.empty = !this.selectedOptions[0]?.textContent?.trim();
|
|
178
|
+
}
|
|
252
179
|
get _menuItems() {
|
|
253
180
|
return this._options;
|
|
254
181
|
}
|
|
182
|
+
#renderNativeOptions() {
|
|
183
|
+
render(map(this._options, option => html `<option value=${option.value} ?selected=${option.selected}>${option.textContent}</option>`), this._nativeSelect);
|
|
184
|
+
}
|
|
185
|
+
#renderAccessibilityList() {
|
|
186
|
+
render(map(this._options, (option, index) => html `<div role="option" id="${`item-${index + 1}`}">${option.textContent}</div>`), this.#list);
|
|
187
|
+
}
|
|
188
|
+
_syncSelectedOptions() {
|
|
189
|
+
for (let i = 0; i < this._options.length; i++) {
|
|
190
|
+
const option = this._options[i];
|
|
191
|
+
const nativeOption = this._nativeSelect.children[i];
|
|
192
|
+
option.selected = nativeOption.selected;
|
|
193
|
+
option._nativeOption = nativeOption;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
255
196
|
};
|
|
256
197
|
__decorate([
|
|
257
198
|
state()
|