material 3.13.0 → 3.14.0
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/README.md +28 -1
- package/dist/components/bottom-app-bar-toolbar/index.d.ts +8 -0
- package/dist/components/bottom-app-bar-toolbar/index.js +66 -0
- package/dist/components/bottom-app-bar-toolbar/structure.js +18 -0
- package/dist/components/button/features/progress.js +21 -30
- package/dist/components/button/types.d.ts +2 -0
- package/dist/components/carousel/features/slides.js +4 -2
- package/dist/components/carousel/index.d.ts +2 -1
- package/dist/components/chips/chip/chip.js +6 -4
- package/dist/components/dialog/features.js +9 -24
- package/dist/components/fab-menu/fab-menu.js +5 -6
- package/dist/components/fab-menu/index.d.ts +7 -0
- package/dist/components/listbox/index.d.ts +100 -0
- package/dist/components/listbox/index.js +1 -0
- package/dist/components/listbox/listbox.js +633 -0
- package/dist/elements/button.js +1 -0
- package/dist/elements/carousel.js +11 -1
- package/dist/elements/index.d.ts +7 -0
- package/dist/elements/preupgrade/badge.css +1 -1
- package/dist/elements/preupgrade/bottom-app-bar.css +1 -1
- package/dist/elements/preupgrade/bottom-sheet.css +1 -1
- package/dist/elements/preupgrade/button-group.css +1 -1
- package/dist/elements/preupgrade/button.css +1 -1
- package/dist/elements/preupgrade/card.css +1 -1
- package/dist/elements/preupgrade/carousel.css +1 -1
- package/dist/elements/preupgrade/checkbox.css +1 -1
- package/dist/elements/preupgrade/chips.css +1 -1
- package/dist/elements/preupgrade/datepicker.css +1 -1
- package/dist/elements/preupgrade/dialog.css +1 -1
- package/dist/elements/preupgrade/divider.css +1 -1
- package/dist/elements/preupgrade/drawer.css +1 -1
- package/dist/elements/preupgrade/extended-fab.css +1 -1
- package/dist/elements/preupgrade/fab-menu.css +1 -1
- package/dist/elements/preupgrade/fab.css +1 -1
- package/dist/elements/preupgrade/icon-button.css +1 -1
- package/dist/elements/preupgrade/list.css +1 -1
- package/dist/elements/preupgrade/loading-indicator.css +1 -1
- package/dist/elements/preupgrade/menu.css +1 -1
- package/dist/elements/preupgrade/navigation-bar.css +1 -1
- package/dist/elements/preupgrade/navigation-rail.css +1 -1
- package/dist/elements/preupgrade/progress.css +1 -1
- package/dist/elements/preupgrade/radios.css +1 -1
- package/dist/elements/preupgrade/search.css +1 -1
- package/dist/elements/preupgrade/select.css +1 -1
- package/dist/elements/preupgrade/side-sheet.css +1 -1
- package/dist/elements/preupgrade/slider.css +1 -1
- package/dist/elements/preupgrade/snackbar.css +1 -1
- package/dist/elements/preupgrade/split-button.css +1 -1
- package/dist/elements/preupgrade/switch.css +1 -1
- package/dist/elements/preupgrade/tabs.css +1 -1
- package/dist/elements/preupgrade/text-field.css +1 -1
- package/dist/elements/preupgrade/timepicker.css +1 -1
- package/dist/elements/preupgrade/toolbar.css +1 -1
- package/dist/elements/preupgrade/tooltip.css +1 -1
- package/dist/elements/preupgrade/top-app-bar.css +1 -1
- package/dist/elements/preupgrade.css +1 -1
- package/dist/styles/badge.css +1 -1
- package/dist/styles/base-elements.css +1 -1
- package/dist/styles/base-lite.css +1 -1
- package/dist/styles/base.css +1 -1
- package/dist/styles/bottom-app-bar-toolbar.css +2 -0
- package/dist/styles/bottom-app-bar-toolbar.js +2 -0
- package/dist/styles/bottom-app-bar.css +1 -1
- package/dist/styles/bottom-sheet.css +1 -1
- package/dist/styles/button-filled-small-round.css +1 -1
- package/dist/styles/button-group.css +1 -1
- package/dist/styles/button.css +1 -1
- package/dist/styles/card.css +1 -1
- package/dist/styles/carousel.css +1 -1
- package/dist/styles/checkbox.css +1 -1
- package/dist/styles/chips.css +1 -1
- package/dist/styles/contrast.css +1 -1
- package/dist/styles/datepicker.css +1 -1
- package/dist/styles/dialog.css +1 -1
- package/dist/styles/divider.css +1 -1
- package/dist/styles/drawer.css +1 -1
- package/dist/styles/extended-fab.css +1 -1
- package/dist/styles/fab-menu.css +1 -1
- package/dist/styles/fab.css +1 -1
- package/dist/styles/icon-button.css +1 -1
- package/dist/styles/list.css +1 -1
- package/dist/styles/listbox.css +2 -0
- package/dist/styles/listbox.js +2 -0
- package/dist/styles/loading-indicator.css +1 -1
- package/dist/styles/menu.css +1 -1
- package/dist/styles/navigation-bar.css +1 -1
- package/dist/styles/navigation-rail.css +1 -1
- package/dist/styles/progress.css +1 -1
- package/dist/styles/radios.css +1 -1
- package/dist/styles/search.css +1 -1
- package/dist/styles/select.css +1 -1
- package/dist/styles/side-sheet.css +1 -1
- package/dist/styles/slider.css +1 -1
- package/dist/styles/snackbar.css +1 -1
- package/dist/styles/split-button.css +1 -1
- package/dist/styles/switch.css +1 -1
- package/dist/styles/tabs.css +1 -1
- package/dist/styles/text-field.css +1 -1
- package/dist/styles/timepicker.css +1 -1
- package/dist/styles/toolbar.css +1 -1
- package/dist/styles/tooltip.css +1 -1
- package/dist/styles/top-app-bar.css +1 -1
- package/dist/styles/typography.css +1 -1
- package/dist/styles/utilities.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/themes/autumn-contrast.css +1 -1
- package/dist/themes/autumn.css +1 -1
- package/dist/themes/baseline-contrast.css +1 -1
- package/dist/themes/baseline.css +1 -1
- package/dist/themes/brownbeige-contrast.css +1 -1
- package/dist/themes/brownbeige.css +1 -1
- package/dist/themes/content-contrast.css +1 -1
- package/dist/themes/content.css +1 -1
- package/dist/themes/desert-contrast.css +1 -1
- package/dist/themes/desert.css +1 -1
- package/dist/themes/expressive-contrast.css +1 -1
- package/dist/themes/expressive.css +1 -1
- package/dist/themes/fidelity-contrast.css +1 -1
- package/dist/themes/fidelity.css +1 -1
- package/dist/themes/forest-contrast.css +1 -1
- package/dist/themes/forest.css +1 -1
- package/dist/themes/fruit-salad-contrast.css +1 -1
- package/dist/themes/fruit-salad.css +1 -1
- package/dist/themes/highcontrast-contrast.css +1 -1
- package/dist/themes/highcontrast.css +1 -1
- package/dist/themes/monochrome-contrast.css +1 -1
- package/dist/themes/monochrome.css +1 -1
- package/dist/themes/neutral-contrast.css +1 -1
- package/dist/themes/neutral.css +1 -1
- package/dist/themes/ocean-contrast.css +1 -1
- package/dist/themes/ocean.css +1 -1
- package/dist/themes/rainbow-contrast.css +1 -1
- package/dist/themes/rainbow.css +1 -1
- package/dist/themes/sageivory-contrast.css +1 -1
- package/dist/themes/sageivory.css +1 -1
- package/dist/themes/spring-contrast.css +1 -1
- package/dist/themes/spring.css +1 -1
- package/dist/themes/summer-contrast.css +1 -1
- package/dist/themes/summer.css +1 -1
- package/dist/themes/sunset-contrast.css +1 -1
- package/dist/themes/sunset.css +1 -1
- package/dist/themes/tealcaramel-contrast.css +1 -1
- package/dist/themes/tealcaramel.css +1 -1
- package/dist/themes/vibrant-contrast.css +1 -1
- package/dist/themes/vibrant.css +1 -1
- package/dist/tokens/catalogue.json +3 -3
- package/package.json +19 -1
- package/src/styles/components/_listbox.scss +95 -0
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
import { menuClosed, menuOpened } from "../menu/features/registry.js";
|
|
2
|
+
const attached = new WeakSet();
|
|
3
|
+
let instances = 0;
|
|
4
|
+
function snapshotOptions(list) {
|
|
5
|
+
if (!Array.isArray(list))
|
|
6
|
+
throw new TypeError("listbox options must be an array");
|
|
7
|
+
const seen = new Set();
|
|
8
|
+
return list.map((raw, index) => {
|
|
9
|
+
if (!raw || typeof raw !== "object")
|
|
10
|
+
throw new TypeError(`listbox option ${index} must be an object`);
|
|
11
|
+
const { id, text, disabled, data } = raw;
|
|
12
|
+
if (typeof id !== "string" || id === "")
|
|
13
|
+
throw new TypeError(`listbox option ${index} needs a nonempty string id`);
|
|
14
|
+
if (seen.has(id))
|
|
15
|
+
throw new TypeError(`listbox option id "${id}" is used twice`);
|
|
16
|
+
seen.add(id);
|
|
17
|
+
if (typeof text !== "string")
|
|
18
|
+
throw new TypeError(`listbox option "${id}" needs a string text`);
|
|
19
|
+
if (disabled !== undefined && typeof disabled !== "boolean")
|
|
20
|
+
throw new TypeError(`listbox option "${id}" disabled must be a boolean`);
|
|
21
|
+
return Object.freeze({ id, text, disabled: disabled === true, data });
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function optionSnapshot(option) {
|
|
25
|
+
return { id: option.id, text: option.text, disabled: option.disabled, data: option.data };
|
|
26
|
+
}
|
|
27
|
+
export function createListbox(config) {
|
|
28
|
+
if (!config || typeof config !== "object")
|
|
29
|
+
throw new TypeError("createListbox needs a config object");
|
|
30
|
+
const control = config.control;
|
|
31
|
+
if (!control || control.nodeType !== 1 || control.localName !== "div") {
|
|
32
|
+
throw new TypeError("listbox control must be a div, not a native input, button or select");
|
|
33
|
+
}
|
|
34
|
+
const element = control;
|
|
35
|
+
if (element.isContentEditable || element.hasAttribute("contenteditable")) {
|
|
36
|
+
throw new TypeError("listbox control must not be editable");
|
|
37
|
+
}
|
|
38
|
+
const interactive = element.querySelector("a[href],button,input,select,textarea,audio[controls],video[controls],summary,[tabindex],[contenteditable]");
|
|
39
|
+
if (interactive)
|
|
40
|
+
throw new TypeError(`listbox control contains an interactive ${interactive.localName} element`);
|
|
41
|
+
const role = element.getAttribute("role");
|
|
42
|
+
if (role && role !== "combobox" && role !== "none" && role !== "presentation") {
|
|
43
|
+
throw new TypeError(`listbox control has the conflicting role "${role}"`);
|
|
44
|
+
}
|
|
45
|
+
if (attached.has(element))
|
|
46
|
+
throw new TypeError("this control already has a listbox");
|
|
47
|
+
if (!element.isConnected)
|
|
48
|
+
throw new TypeError("listbox control must be connected to a document");
|
|
49
|
+
if (typeof HTMLElement.prototype.showPopover !== "function") {
|
|
50
|
+
throw new Error("createListbox needs the Popover API: this browser has no showPopover()");
|
|
51
|
+
}
|
|
52
|
+
const ariaLabel = config.ariaLabel;
|
|
53
|
+
if (typeof ariaLabel !== "string" || ariaLabel.trim() === "") {
|
|
54
|
+
throw new TypeError("listbox ariaLabel must be a nonempty string");
|
|
55
|
+
}
|
|
56
|
+
const placeholder = config.placeholder ?? "";
|
|
57
|
+
if (typeof placeholder !== "string")
|
|
58
|
+
throw new TypeError("listbox placeholder must be a string");
|
|
59
|
+
if (config.disabled !== undefined && typeof config.disabled !== "boolean")
|
|
60
|
+
throw new TypeError("listbox disabled must be a boolean");
|
|
61
|
+
if (config.on !== undefined && (typeof config.on !== "object" || config.on === null))
|
|
62
|
+
throw new TypeError("listbox on must be an object");
|
|
63
|
+
let options = snapshotOptions(config.options);
|
|
64
|
+
const initial = config.value ?? null;
|
|
65
|
+
if (initial !== null && (typeof initial !== "string" || !options.some((option) => option.id === initial))) {
|
|
66
|
+
throw new RangeError(`listbox has no option "${String(initial)}"`);
|
|
67
|
+
}
|
|
68
|
+
const selected = initial === null ? undefined : options.find((option) => option.id === initial);
|
|
69
|
+
if (selected && selected.text === ariaLabel)
|
|
70
|
+
throw new TypeError("listbox ariaLabel must name the field, not its value");
|
|
71
|
+
const originalText = element.textContent;
|
|
72
|
+
let writtenText = originalText;
|
|
73
|
+
let valueId = initial;
|
|
74
|
+
let disabled = config.disabled === true;
|
|
75
|
+
let activeIndex = -1;
|
|
76
|
+
let isOpen = false;
|
|
77
|
+
let destroyed = false;
|
|
78
|
+
let generation = 0;
|
|
79
|
+
let buffer = "";
|
|
80
|
+
let bufferAt = 0;
|
|
81
|
+
let tapActivation = false;
|
|
82
|
+
let observer = null;
|
|
83
|
+
const listeners = new Map();
|
|
84
|
+
const owned = new Map();
|
|
85
|
+
const rows = [];
|
|
86
|
+
const bound = [];
|
|
87
|
+
const temporary = [];
|
|
88
|
+
const domIds = new Map();
|
|
89
|
+
let domCounter = 0;
|
|
90
|
+
const popup = document.createElement("div");
|
|
91
|
+
popup.id = `mtrl-listbox-${++instances}`;
|
|
92
|
+
popup.className = "mtrl-listbox";
|
|
93
|
+
popup.setAttribute("popover", "manual");
|
|
94
|
+
popup.setAttribute("role", "listbox");
|
|
95
|
+
popup.setAttribute("aria-label", ariaLabel);
|
|
96
|
+
const setAttr = (name, value) => {
|
|
97
|
+
const entry = owned.get(name) ?? { original: element.getAttribute(name), written: null };
|
|
98
|
+
owned.set(name, entry);
|
|
99
|
+
entry.written = value;
|
|
100
|
+
if (value === null)
|
|
101
|
+
element.removeAttribute(name);
|
|
102
|
+
else
|
|
103
|
+
element.setAttribute(name, value);
|
|
104
|
+
};
|
|
105
|
+
const setText = (text) => {
|
|
106
|
+
writtenText = text;
|
|
107
|
+
element.textContent = text;
|
|
108
|
+
};
|
|
109
|
+
const optionOf = (id) => (id === null ? undefined : options.find((option) => option.id === id));
|
|
110
|
+
const optionIds = () => new Set(options.map((option) => option.id));
|
|
111
|
+
const subscript = (type, handler) => {
|
|
112
|
+
let set = listeners.get(type);
|
|
113
|
+
if (!set)
|
|
114
|
+
listeners.set(type, (set = new Set()));
|
|
115
|
+
set.add(handler);
|
|
116
|
+
};
|
|
117
|
+
const bind = (list, target, type, handler, options) => {
|
|
118
|
+
target.addEventListener(type, handler, options);
|
|
119
|
+
list.push([target, type, handler, options]);
|
|
120
|
+
};
|
|
121
|
+
const unbind = (list) => {
|
|
122
|
+
for (const [target, type, handler, options] of list.splice(0))
|
|
123
|
+
target.removeEventListener(type, handler, options);
|
|
124
|
+
};
|
|
125
|
+
const pathHas = (event, node) => event.composedPath().includes(node);
|
|
126
|
+
const onlyEnabled = (index) => index >= 0 && index < options.length && !options[index].disabled;
|
|
127
|
+
const domId = (option) => {
|
|
128
|
+
let id = domIds.get(option.id);
|
|
129
|
+
if (!id) {
|
|
130
|
+
const taken = optionIds();
|
|
131
|
+
do
|
|
132
|
+
id = `${popup.id}-o-${++domCounter}`;
|
|
133
|
+
while (taken.has(id));
|
|
134
|
+
domIds.set(option.id, id);
|
|
135
|
+
}
|
|
136
|
+
return id;
|
|
137
|
+
};
|
|
138
|
+
const syncActive = () => {
|
|
139
|
+
rows.forEach((row, index) => row.classList.toggle("mtrl-listbox__option--active", index === activeIndex));
|
|
140
|
+
if (!isOpen)
|
|
141
|
+
return;
|
|
142
|
+
const row = rows[activeIndex];
|
|
143
|
+
setAttr("aria-activedescendant", row && onlyEnabled(activeIndex) ? row.id : null);
|
|
144
|
+
};
|
|
145
|
+
const setActive = (index) => {
|
|
146
|
+
if (index === activeIndex)
|
|
147
|
+
return;
|
|
148
|
+
activeIndex = index;
|
|
149
|
+
syncActive();
|
|
150
|
+
if (isOpen)
|
|
151
|
+
rows[index]?.scrollIntoView({ block: "nearest" });
|
|
152
|
+
};
|
|
153
|
+
const updateValue = () => {
|
|
154
|
+
const option = optionOf(valueId);
|
|
155
|
+
setText(option ? option.text : placeholder);
|
|
156
|
+
rows.forEach((row, index) => row.setAttribute("aria-selected", String(options[index]?.id === valueId)));
|
|
157
|
+
};
|
|
158
|
+
const render = () => {
|
|
159
|
+
rows.length = 0;
|
|
160
|
+
popup.replaceChildren(...options.map((option) => {
|
|
161
|
+
const row = document.createElement("div");
|
|
162
|
+
row.className = "mtrl-listbox__option";
|
|
163
|
+
row.id = domId(option);
|
|
164
|
+
row.setAttribute("role", "option");
|
|
165
|
+
row.setAttribute("aria-selected", String(option.id === valueId));
|
|
166
|
+
if (option.disabled)
|
|
167
|
+
row.setAttribute("aria-disabled", "true");
|
|
168
|
+
row.textContent = option.text;
|
|
169
|
+
rows.push(row);
|
|
170
|
+
return row;
|
|
171
|
+
}));
|
|
172
|
+
syncActive();
|
|
173
|
+
};
|
|
174
|
+
const firstEnabled = () => options.findIndex((option) => !option.disabled);
|
|
175
|
+
const lastEnabled = () => {
|
|
176
|
+
for (let index = options.length - 1; index >= 0; index--)
|
|
177
|
+
if (!options[index].disabled)
|
|
178
|
+
return index;
|
|
179
|
+
return -1;
|
|
180
|
+
};
|
|
181
|
+
const selectedEnabled = () => {
|
|
182
|
+
const index = options.findIndex((option) => option.id === valueId);
|
|
183
|
+
return onlyEnabled(index) ? index : -1;
|
|
184
|
+
};
|
|
185
|
+
const nextEnabled = (from, step) => {
|
|
186
|
+
for (let index = from + step; index >= 0 && index < options.length; index += step)
|
|
187
|
+
if (!options[index].disabled)
|
|
188
|
+
return index;
|
|
189
|
+
return -1;
|
|
190
|
+
};
|
|
191
|
+
const moveActive = (distance) => {
|
|
192
|
+
const step = Math.sign(distance);
|
|
193
|
+
let index = activeIndex;
|
|
194
|
+
for (let remaining = Math.abs(distance); remaining > 0; remaining--) {
|
|
195
|
+
const next = nextEnabled(index, step);
|
|
196
|
+
if (next < 0)
|
|
197
|
+
break;
|
|
198
|
+
index = next;
|
|
199
|
+
}
|
|
200
|
+
if (index >= 0)
|
|
201
|
+
setActive(index);
|
|
202
|
+
};
|
|
203
|
+
const startIndex = (start) => {
|
|
204
|
+
const chosen = start === "first" || start === "last" ? -1 : selectedEnabled();
|
|
205
|
+
if (chosen >= 0)
|
|
206
|
+
return chosen;
|
|
207
|
+
return start === "last" || start === "selected-last" ? lastEnabled() : firstEnabled();
|
|
208
|
+
};
|
|
209
|
+
const emit = (type, detail) => {
|
|
210
|
+
for (const handler of [...(listeners.get(type) ?? [])]) {
|
|
211
|
+
if (destroyed)
|
|
212
|
+
return;
|
|
213
|
+
handler(detail);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
const hide = () => {
|
|
217
|
+
try {
|
|
218
|
+
if (popup.matches(":popover-open"))
|
|
219
|
+
popup.hidePopover();
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const restore = () => {
|
|
225
|
+
for (const [name, entry] of owned) {
|
|
226
|
+
if (element.getAttribute(name) !== entry.written)
|
|
227
|
+
continue;
|
|
228
|
+
if (entry.original === null)
|
|
229
|
+
element.removeAttribute(name);
|
|
230
|
+
else
|
|
231
|
+
element.setAttribute(name, entry.original);
|
|
232
|
+
}
|
|
233
|
+
if (element.textContent === writtenText)
|
|
234
|
+
element.textContent = originalText;
|
|
235
|
+
};
|
|
236
|
+
const place = () => {
|
|
237
|
+
const viewport = document.documentElement;
|
|
238
|
+
const width = viewport.clientWidth;
|
|
239
|
+
const height = viewport.clientHeight;
|
|
240
|
+
const rect = element.getBoundingClientRect();
|
|
241
|
+
const rtl = getComputedStyle(element).direction === "rtl";
|
|
242
|
+
popup.style.minWidth = `${Math.min(rect.width, width)}px`;
|
|
243
|
+
popup.style.maxWidth = `${width}px`;
|
|
244
|
+
popup.style.maxHeight = "";
|
|
245
|
+
popup.style.left = `${rtl ? rect.right : rect.left}px`;
|
|
246
|
+
popup.style.top = `${rect.bottom}px`;
|
|
247
|
+
const natural = popup.getBoundingClientRect().height;
|
|
248
|
+
const below = Math.max(0, height - rect.bottom);
|
|
249
|
+
const above = Math.max(0, rect.top);
|
|
250
|
+
const flip = natural > below && above > below;
|
|
251
|
+
popup.style.maxHeight = `${flip ? above : below}px`;
|
|
252
|
+
const placed = popup.getBoundingClientRect();
|
|
253
|
+
popup.style.left = `${Math.max(0, Math.min(rtl ? rect.right - placed.width : rect.left, width - placed.width))}px`;
|
|
254
|
+
popup.style.top = `${flip ? Math.max(0, rect.top - placed.height) : rect.bottom}px`;
|
|
255
|
+
};
|
|
256
|
+
const observe = () => {
|
|
257
|
+
observer = new MutationObserver(() => {
|
|
258
|
+
if (!element.isConnected)
|
|
259
|
+
close();
|
|
260
|
+
});
|
|
261
|
+
observer.observe(element.getRootNode(), { childList: true, subtree: true });
|
|
262
|
+
};
|
|
263
|
+
const listenForDismissal = (opening) => {
|
|
264
|
+
bind(temporary, document, "pointerdown", (event) => {
|
|
265
|
+
if (event === opening || pathHas(event, element) || pathHas(event, popup))
|
|
266
|
+
return;
|
|
267
|
+
close(event);
|
|
268
|
+
}, true);
|
|
269
|
+
bind(temporary, element, "focusout", () => close());
|
|
270
|
+
bind(temporary, window, "scroll", (event) => {
|
|
271
|
+
if (!pathHas(event, popup))
|
|
272
|
+
close(event);
|
|
273
|
+
}, { capture: true, passive: true });
|
|
274
|
+
bind(temporary, window, "resize", () => close());
|
|
275
|
+
const visual = window.visualViewport;
|
|
276
|
+
if (visual) {
|
|
277
|
+
bind(temporary, visual, "resize", () => close());
|
|
278
|
+
bind(temporary, visual, "scroll", () => close());
|
|
279
|
+
}
|
|
280
|
+
const dialog = element.closest("dialog");
|
|
281
|
+
if (dialog)
|
|
282
|
+
bind(temporary, dialog, "close", () => close());
|
|
283
|
+
observe();
|
|
284
|
+
};
|
|
285
|
+
const open = (event, start = "selected-first") => {
|
|
286
|
+
if (destroyed || isOpen || disabled || !element.isConnected)
|
|
287
|
+
return handle;
|
|
288
|
+
const before = ++generation;
|
|
289
|
+
try {
|
|
290
|
+
activeIndex = startIndex(start);
|
|
291
|
+
popup.showPopover();
|
|
292
|
+
place();
|
|
293
|
+
listenForDismissal(event);
|
|
294
|
+
isOpen = true;
|
|
295
|
+
syncActive();
|
|
296
|
+
element.focus({ preventScroll: true });
|
|
297
|
+
if (destroyed || !isOpen || generation !== before)
|
|
298
|
+
return handle;
|
|
299
|
+
setAttr("aria-expanded", "true");
|
|
300
|
+
setAttr("aria-controls", popup.id);
|
|
301
|
+
menuOpened(handle, event);
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
if (destroyed)
|
|
305
|
+
throw error;
|
|
306
|
+
unbind(temporary);
|
|
307
|
+
observer?.disconnect();
|
|
308
|
+
observer = null;
|
|
309
|
+
hide();
|
|
310
|
+
isOpen = false;
|
|
311
|
+
activeIndex = -1;
|
|
312
|
+
setAttr("aria-expanded", "false");
|
|
313
|
+
setAttr("aria-controls", null);
|
|
314
|
+
setAttr("aria-activedescendant", null);
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
if (generation === before && isOpen && !destroyed)
|
|
318
|
+
emit("open", { listbox: handle, originalEvent: event });
|
|
319
|
+
return handle;
|
|
320
|
+
};
|
|
321
|
+
const close = (event) => {
|
|
322
|
+
if (destroyed || !isOpen)
|
|
323
|
+
return handle;
|
|
324
|
+
isOpen = false;
|
|
325
|
+
generation++;
|
|
326
|
+
activeIndex = -1;
|
|
327
|
+
buffer = "";
|
|
328
|
+
unbind(temporary);
|
|
329
|
+
observer?.disconnect();
|
|
330
|
+
observer = null;
|
|
331
|
+
hide();
|
|
332
|
+
setAttr("aria-expanded", "false");
|
|
333
|
+
setAttr("aria-controls", null);
|
|
334
|
+
setAttr("aria-activedescendant", null);
|
|
335
|
+
syncActive();
|
|
336
|
+
menuClosed(handle);
|
|
337
|
+
emit("close", { listbox: handle, originalEvent: event });
|
|
338
|
+
return handle;
|
|
339
|
+
};
|
|
340
|
+
const commit = (event) => {
|
|
341
|
+
const option = options[activeIndex];
|
|
342
|
+
if (!option || option.disabled) {
|
|
343
|
+
close(event);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const previousValue = valueId;
|
|
347
|
+
const before = generation;
|
|
348
|
+
if (option.id !== previousValue) {
|
|
349
|
+
valueId = option.id;
|
|
350
|
+
updateValue();
|
|
351
|
+
emit("change", { listbox: handle, originalEvent: event, value: option.id, previousValue, option: optionSnapshot(option) });
|
|
352
|
+
}
|
|
353
|
+
if (generation === before)
|
|
354
|
+
close(event);
|
|
355
|
+
};
|
|
356
|
+
const search = (text) => {
|
|
357
|
+
const query = text.toLowerCase();
|
|
358
|
+
const cycling = [...text].every((character) => character === text[0]);
|
|
359
|
+
const length = options.length;
|
|
360
|
+
if (!length)
|
|
361
|
+
return -1;
|
|
362
|
+
const start = activeIndex < 0 ? 0 : cycling ? activeIndex + 1 : activeIndex;
|
|
363
|
+
for (let offset = 0; offset < length; offset++) {
|
|
364
|
+
const index = (start + offset) % length;
|
|
365
|
+
const option = options[index];
|
|
366
|
+
if (!option.disabled && option.text.toLowerCase().startsWith(query))
|
|
367
|
+
return index;
|
|
368
|
+
}
|
|
369
|
+
return -1;
|
|
370
|
+
};
|
|
371
|
+
const typeahead = (character) => {
|
|
372
|
+
const now = performance.now();
|
|
373
|
+
if (now - bufferAt > 500)
|
|
374
|
+
buffer = "";
|
|
375
|
+
buffer += character;
|
|
376
|
+
bufferAt = now;
|
|
377
|
+
let match = search(buffer);
|
|
378
|
+
if (match < 0 && buffer.length > 1) {
|
|
379
|
+
buffer = character;
|
|
380
|
+
match = search(buffer);
|
|
381
|
+
}
|
|
382
|
+
if (match >= 0)
|
|
383
|
+
setActive(match);
|
|
384
|
+
};
|
|
385
|
+
const onKeyDown = (event) => {
|
|
386
|
+
if (destroyed || event.defaultPrevented || event.isComposing || event.keyCode === 229)
|
|
387
|
+
return;
|
|
388
|
+
if (event.ctrlKey || event.metaKey)
|
|
389
|
+
return;
|
|
390
|
+
const key = event.key;
|
|
391
|
+
if (event.altKey) {
|
|
392
|
+
if (key === "ArrowDown" && !isOpen) {
|
|
393
|
+
event.preventDefault();
|
|
394
|
+
open(event);
|
|
395
|
+
}
|
|
396
|
+
else if (key === "ArrowUp" && isOpen) {
|
|
397
|
+
event.preventDefault();
|
|
398
|
+
commit(event);
|
|
399
|
+
}
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (!isOpen) {
|
|
403
|
+
if (disabled)
|
|
404
|
+
return;
|
|
405
|
+
if (key === "Enter" || key === " ") {
|
|
406
|
+
event.preventDefault();
|
|
407
|
+
open(event);
|
|
408
|
+
}
|
|
409
|
+
else if (key === "ArrowDown") {
|
|
410
|
+
event.preventDefault();
|
|
411
|
+
open(event, "selected-first");
|
|
412
|
+
}
|
|
413
|
+
else if (key === "ArrowUp") {
|
|
414
|
+
event.preventDefault();
|
|
415
|
+
open(event, "selected-last");
|
|
416
|
+
}
|
|
417
|
+
else if (key === "Home") {
|
|
418
|
+
event.preventDefault();
|
|
419
|
+
open(event, "first");
|
|
420
|
+
}
|
|
421
|
+
else if (key === "End") {
|
|
422
|
+
event.preventDefault();
|
|
423
|
+
open(event, "last");
|
|
424
|
+
}
|
|
425
|
+
else if (key.length === 1) {
|
|
426
|
+
event.preventDefault();
|
|
427
|
+
open(event);
|
|
428
|
+
if (isOpen)
|
|
429
|
+
typeahead(key);
|
|
430
|
+
}
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (key === "Enter") {
|
|
434
|
+
event.preventDefault();
|
|
435
|
+
commit(event);
|
|
436
|
+
}
|
|
437
|
+
else if (key === " ") {
|
|
438
|
+
event.preventDefault();
|
|
439
|
+
if (buffer && performance.now() - bufferAt <= 500)
|
|
440
|
+
typeahead(" ");
|
|
441
|
+
else
|
|
442
|
+
commit(event);
|
|
443
|
+
}
|
|
444
|
+
else if (key === "ArrowDown" || key === "PageDown") {
|
|
445
|
+
event.preventDefault();
|
|
446
|
+
moveActive(key === "ArrowDown" ? 1 : 10);
|
|
447
|
+
}
|
|
448
|
+
else if (key === "ArrowUp" || key === "PageUp") {
|
|
449
|
+
event.preventDefault();
|
|
450
|
+
moveActive(key === "ArrowUp" ? -1 : -10);
|
|
451
|
+
}
|
|
452
|
+
else if (key === "Home") {
|
|
453
|
+
event.preventDefault();
|
|
454
|
+
setActive(firstEnabled());
|
|
455
|
+
}
|
|
456
|
+
else if (key === "End") {
|
|
457
|
+
event.preventDefault();
|
|
458
|
+
setActive(lastEnabled());
|
|
459
|
+
}
|
|
460
|
+
else if (key === "Escape") {
|
|
461
|
+
event.preventDefault();
|
|
462
|
+
close(event);
|
|
463
|
+
}
|
|
464
|
+
else if (key === "Tab") {
|
|
465
|
+
commit(event);
|
|
466
|
+
}
|
|
467
|
+
else if (key.length === 1) {
|
|
468
|
+
event.preventDefault();
|
|
469
|
+
typeahead(key);
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
const rowAt = (event) => {
|
|
473
|
+
const target = event.target;
|
|
474
|
+
const row = target && target.nodeType === 1 ? target.closest(".mtrl-listbox__option") : null;
|
|
475
|
+
return row ? rows.indexOf(row) : -1;
|
|
476
|
+
};
|
|
477
|
+
const onPointerDown = (event) => {
|
|
478
|
+
tapActivation = false;
|
|
479
|
+
event.preventDefault();
|
|
480
|
+
};
|
|
481
|
+
const onPointerUp = (event) => {
|
|
482
|
+
if (event.pointerType === "mouse" || event.button !== 0)
|
|
483
|
+
return;
|
|
484
|
+
const index = rowAt(event);
|
|
485
|
+
if (onlyEnabled(index)) {
|
|
486
|
+
activeIndex = index;
|
|
487
|
+
commit(event);
|
|
488
|
+
tapActivation = isOpen;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
const onPointerMove = (event) => {
|
|
492
|
+
const index = rowAt(event);
|
|
493
|
+
if (onlyEnabled(index))
|
|
494
|
+
setActive(index);
|
|
495
|
+
};
|
|
496
|
+
const onClick = (event) => {
|
|
497
|
+
if (tapActivation) {
|
|
498
|
+
tapActivation = false;
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
const index = rowAt(event);
|
|
502
|
+
if (onlyEnabled(index)) {
|
|
503
|
+
activeIndex = index;
|
|
504
|
+
commit(event);
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
const onControlClick = (event) => {
|
|
508
|
+
if (destroyed || disabled)
|
|
509
|
+
return;
|
|
510
|
+
if (isOpen)
|
|
511
|
+
close(event);
|
|
512
|
+
else
|
|
513
|
+
open(event);
|
|
514
|
+
};
|
|
515
|
+
const handle = {
|
|
516
|
+
element: popup,
|
|
517
|
+
open,
|
|
518
|
+
close,
|
|
519
|
+
toggle: (event) => (isOpen ? close(event) : open(event)),
|
|
520
|
+
isOpen: () => isOpen,
|
|
521
|
+
getValue: () => valueId,
|
|
522
|
+
setValue: (id) => {
|
|
523
|
+
if (destroyed)
|
|
524
|
+
return handle;
|
|
525
|
+
if (id !== null && typeof id !== "string")
|
|
526
|
+
throw new TypeError("listbox value must be a string or null");
|
|
527
|
+
if (id !== null && !optionOf(id))
|
|
528
|
+
throw new RangeError(`listbox has no option "${id}"`);
|
|
529
|
+
valueId = id;
|
|
530
|
+
updateValue();
|
|
531
|
+
if (isOpen) {
|
|
532
|
+
const index = options.findIndex((option) => option.id === id);
|
|
533
|
+
if (onlyEnabled(index))
|
|
534
|
+
setActive(index);
|
|
535
|
+
}
|
|
536
|
+
return handle;
|
|
537
|
+
},
|
|
538
|
+
getOptions: () => options.map(optionSnapshot),
|
|
539
|
+
setOptions: (next) => {
|
|
540
|
+
if (destroyed)
|
|
541
|
+
return handle;
|
|
542
|
+
const snapshot = snapshotOptions(next);
|
|
543
|
+
const previousActive = options[activeIndex]?.id;
|
|
544
|
+
options = snapshot;
|
|
545
|
+
const ids = optionIds();
|
|
546
|
+
for (const id of [...domIds.keys()])
|
|
547
|
+
if (!ids.has(id))
|
|
548
|
+
domIds.delete(id);
|
|
549
|
+
if (valueId !== null && !optionOf(valueId))
|
|
550
|
+
valueId = null;
|
|
551
|
+
activeIndex = -1;
|
|
552
|
+
render();
|
|
553
|
+
updateValue();
|
|
554
|
+
if (isOpen) {
|
|
555
|
+
const kept = previousActive === undefined ? -1 : options.findIndex((option) => option.id === previousActive);
|
|
556
|
+
setActive(onlyEnabled(kept) ? kept : startIndex("selected-first"));
|
|
557
|
+
}
|
|
558
|
+
return handle;
|
|
559
|
+
},
|
|
560
|
+
setDisabled: (next) => {
|
|
561
|
+
if (destroyed)
|
|
562
|
+
return handle;
|
|
563
|
+
disabled = next === true;
|
|
564
|
+
setAttr("aria-disabled", disabled ? "true" : null);
|
|
565
|
+
if (disabled)
|
|
566
|
+
close();
|
|
567
|
+
return handle;
|
|
568
|
+
},
|
|
569
|
+
isDisabled: () => disabled,
|
|
570
|
+
on: (type, handler) => {
|
|
571
|
+
if (!destroyed)
|
|
572
|
+
subscript(type, handler);
|
|
573
|
+
return handle;
|
|
574
|
+
},
|
|
575
|
+
off: (type, handler) => {
|
|
576
|
+
listeners.get(type)?.delete(handler);
|
|
577
|
+
return handle;
|
|
578
|
+
},
|
|
579
|
+
destroy: () => {
|
|
580
|
+
if (destroyed)
|
|
581
|
+
return;
|
|
582
|
+
destroyed = true;
|
|
583
|
+
generation++;
|
|
584
|
+
buffer = "";
|
|
585
|
+
if (isOpen) {
|
|
586
|
+
isOpen = false;
|
|
587
|
+
menuClosed(handle);
|
|
588
|
+
}
|
|
589
|
+
unbind(temporary);
|
|
590
|
+
unbind(bound);
|
|
591
|
+
observer?.disconnect();
|
|
592
|
+
observer = null;
|
|
593
|
+
hide();
|
|
594
|
+
popup.remove();
|
|
595
|
+
restore();
|
|
596
|
+
attached.delete(element);
|
|
597
|
+
},
|
|
598
|
+
};
|
|
599
|
+
attached.add(element);
|
|
600
|
+
try {
|
|
601
|
+
element.after(popup);
|
|
602
|
+
setAttr("role", "combobox");
|
|
603
|
+
setAttr("tabindex", "0");
|
|
604
|
+
setAttr("aria-haspopup", "listbox");
|
|
605
|
+
setAttr("aria-label", ariaLabel);
|
|
606
|
+
setAttr("aria-expanded", "false");
|
|
607
|
+
if (disabled)
|
|
608
|
+
setAttr("aria-disabled", "true");
|
|
609
|
+
bind(bound, element, "keydown", onKeyDown);
|
|
610
|
+
bind(bound, element, "click", onControlClick);
|
|
611
|
+
bind(bound, popup, "pointerdown", onPointerDown);
|
|
612
|
+
bind(bound, popup, "pointerup", onPointerUp);
|
|
613
|
+
bind(bound, popup, "pointermove", onPointerMove);
|
|
614
|
+
bind(bound, popup, "click", onClick);
|
|
615
|
+
render();
|
|
616
|
+
updateValue();
|
|
617
|
+
const handlers = (config.on ?? {});
|
|
618
|
+
for (const [type, handler] of Object.entries(handlers)) {
|
|
619
|
+
if (typeof handler === "function")
|
|
620
|
+
subscript(type, handler);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
catch (error) {
|
|
624
|
+
destroyed = true;
|
|
625
|
+
unbind(bound);
|
|
626
|
+
popup.remove();
|
|
627
|
+
restore();
|
|
628
|
+
attached.delete(element);
|
|
629
|
+
throw error;
|
|
630
|
+
}
|
|
631
|
+
return handle;
|
|
632
|
+
}
|
|
633
|
+
export default createListbox;
|
package/dist/elements/button.js
CHANGED
|
@@ -11,6 +11,7 @@ variant: { type: "string", config: "variant", update: (c, v) => void c.setVarian
|
|
|
11
11
|
size: { type: "string", config: "size", update: (c, v) => void c.setSize(String(v ?? "s")) },
|
|
12
12
|
shape: { type: "string", config: "shape", update: (c, v) => void c.setShape(String(v ?? "round")) },
|
|
13
13
|
disabled: { type: "boolean", config: "disabled", update: (c, v) => void (v ? c.disable() : c.enable()) },
|
|
14
|
+
loading: { type: "boolean", config: "loading" },
|
|
14
15
|
icon: { type: "string", config: "icon" },
|
|
15
16
|
"icon-position": { type: "string", config: "iconPosition" },
|
|
16
17
|
toggle: { type: "boolean", config: "toggle" },
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import createCarousel from "../components/carousel/index.js";
|
|
2
2
|
import { createDeclarationClass, defineElement, DEFAULT_PREFIX, } from "./define.js";
|
|
3
3
|
const itemValues = new WeakMap();
|
|
4
|
+
const itemName = (child) => {
|
|
5
|
+
const label = child.getAttribute("label");
|
|
6
|
+
if (label !== null)
|
|
7
|
+
return label;
|
|
8
|
+
const title = child.getAttribute("title")?.trim();
|
|
9
|
+
if (title)
|
|
10
|
+
return title;
|
|
11
|
+
return (child.textContent ?? "").trim();
|
|
12
|
+
};
|
|
4
13
|
const declaredItems = (host) => {
|
|
5
14
|
const itemTag = `${host.localName}-item`;
|
|
6
15
|
const items = [];
|
|
7
16
|
for (const child of Array.from(host.children)) {
|
|
8
17
|
if (child.localName !== itemTag)
|
|
9
18
|
continue;
|
|
10
|
-
const title =
|
|
19
|
+
const title = itemName(child);
|
|
11
20
|
const slide = {
|
|
12
21
|
image: child.getAttribute("src") ?? undefined,
|
|
13
22
|
alt: child.getAttribute("alt") ?? undefined,
|
|
@@ -106,6 +115,7 @@ value: { type: "string" },
|
|
|
106
115
|
src: { type: "string" },
|
|
107
116
|
alt: { type: "string" },
|
|
108
117
|
label: { type: "string" },
|
|
118
|
+
title: { type: "string" },
|
|
109
119
|
description: { type: "string" },
|
|
110
120
|
"button-text": { type: "string" },
|
|
111
121
|
"button-url": { type: "string" },
|
package/dist/elements/index.d.ts
CHANGED
|
@@ -602,6 +602,9 @@ declare const carouselItemDeclaration: {
|
|
|
602
602
|
readonly label: {
|
|
603
603
|
readonly type: "string";
|
|
604
604
|
};
|
|
605
|
+
readonly title: {
|
|
606
|
+
readonly type: "string";
|
|
607
|
+
};
|
|
605
608
|
readonly description: {
|
|
606
609
|
readonly type: "string";
|
|
607
610
|
};
|
|
@@ -3161,6 +3164,10 @@ declare const buttonSpec: {
|
|
|
3161
3164
|
config: string;
|
|
3162
3165
|
update: (c: ButtonComponent, v: import("./define.js").AttributeValue) => undefined;
|
|
3163
3166
|
};
|
|
3167
|
+
loading: {
|
|
3168
|
+
type: "boolean";
|
|
3169
|
+
config: string;
|
|
3170
|
+
};
|
|
3164
3171
|
/** Markup (HTML). */
|
|
3165
3172
|
icon: {
|
|
3166
3173
|
type: "string";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! material v3.
|
|
1
|
+
/*! material v3.14.0 | MIT */
|
|
2
2
|
@layer mtrl.preupgrade{m-badge:not(:defined){display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;vertical-align:middle;overflow:hidden;height:16px;min-width:16px;max-width:34px;padding:0 4px;border-radius:var(--mtrl-sys-shape-corner-full, 9999px);font-weight:500;font-size:11px;line-height:16px;background-color:var(--mtrl-sys-color-error);color:var(--mtrl-sys-color-on-error)}m-badge:not(:defined)[color=primary]{background-color:var(--mtrl-sys-color-primary);color:var(--mtrl-sys-color-on-primary)}m-badge:not(:defined)[color=secondary]{background-color:var(--mtrl-sys-color-secondary);color:var(--mtrl-sys-color-on-secondary)}m-badge:not(:defined)[color=tertiary]{background-color:var(--mtrl-sys-color-tertiary);color:var(--mtrl-sys-color-on-tertiary)}m-badge:not(:defined)[color=success]{background-color:var(--mtrl-sys-color-success);color:var(--mtrl-sys-color-on-success)}m-badge:not(:defined)[color=warning]{background-color:var(--mtrl-sys-color-warning);color:var(--mtrl-sys-color-on-warning)}m-badge:not(:defined)[color=info]{background-color:var(--mtrl-sys-color-info);color:var(--mtrl-sys-color-on-info)}m-badge:not(:defined):empty[label]:not([label=""])::before{content:attr(label)}m-badge:not(:defined):not([variant=small]):is(:empty:not([label]),[label=""],[label="0"]){width:0;height:0;min-width:0;max-width:none;padding:0;font-size:0;background-color:rgba(0,0,0,0)}m-badge:not(:defined)[variant=small]{width:6px;height:6px;min-width:6px;max-width:none;padding:0;font-size:0}[data-mtrl-ssr]:not(:defined):not(#\0),[data-mtrl-ssr]:not(:defined):not(#\0)::before,[data-mtrl-ssr]:not(:defined):not(#\0)::after,[data-mtrl-ssr]:not(:defined):not(#\0) > :defined{all:revert-layer}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! material v3.
|
|
1
|
+
/*! material v3.14.0 | MIT */
|
|
2
2
|
@layer mtrl.preupgrade{m-bottom-app-bar:not(:defined){position:absolute;bottom:0;left:0;right:0;display:flex;align-items:center;gap:4px;box-sizing:border-box;height:80px;padding:12px 16px 12px 4px;background-color:var(--mtrl-sys-color-surface-container)}m-bottom-app-bar:not(:defined)>[slot=fab]{margin-left:auto}[data-mtrl-ssr]:not(:defined):not(#\0),[data-mtrl-ssr]:not(:defined):not(#\0)::before,[data-mtrl-ssr]:not(:defined):not(#\0)::after,[data-mtrl-ssr]:not(:defined):not(#\0) > :defined{all:revert-layer}}
|