Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
57 lines (49 loc) · 2.29 KB
/
Copy pathmain.js
File metadata and controls
57 lines (49 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Primary Imports
import {
CheckboxGroup,
MenuElement,
ComboboxField,
ComboboxListbox,
ComboboxOption,
SelectEnhancer,
PseudoBackdrop,
} from "@itenthusiasm/custom-elements";
/* -------------------- "App Logic" -------------------- */
customElements.define("menu-element", MenuElement);
customElements.define("checkbox-group", CheckboxGroup);
customElements.define("combobox-listbox", ComboboxListbox);
customElements.define("combobox-field", ComboboxField);
customElements.define("combobox-option", ComboboxOption);
customElements.define("select-enhancer", SelectEnhancer);
customElements.define("pseudo-backdrop", PseudoBackdrop);
/* -------------------- Handlers for Debugging -------------------- */
/* ---------- Form Submission ---------- */
/** @type {HTMLFormElement} */ (document.querySelector("form")).addEventListener("submit", handleSubmit);
/** @param {SubmitEvent} event */
function handleSubmit(event) {
event.preventDefault();
const form = /** @type {HTMLFormElement} */ (event.currentTarget);
console.log(Object.fromEntries(new FormData(form))); // eslint-disable-line no-console
console.log(event); // eslint-disable-line no-console
}
/* ---------- Menu Item Selection ---------- */
const menudemo = /** @type {HTMLElement} */ (document.getElementById("advanced-menu-example"));
menudemo.addEventListener("click", handleButtonGroupClick);
menudemo.addEventListener("menuselect", handleMenuselect);
/** @param {PointerEvent} event @returns {void} */
function handleButtonGroupClick(event) {
const menubutton = /** @type {HTMLElement} */ (event.target).closest("button");
if (!menubutton) return;
const menuId = /** @type {string} */ (menubutton.getAttribute("aria-controls"));
const menu = /** @type {MenuElement} */ (document.getElementById(menuId));
const anchor = /** @type {HTMLElement} */ (menubutton.parentElement);
if (anchor.contains(menu)) return; // The `menu` has already been anchored here
// Re-anchor the `menu` and associate it with the new `<button>`.
menu.setAttribute("menubutton", menubutton.id);
menu.setAttribute("menuanchor", anchor.id);
menubutton.ariaExpanded = String(true);
}
/** @param {CustomEvent<string>} event @returns {void} */
function handleMenuselect(event) {
console.log("Action Selected: ", event.detail); // eslint-disable-line no-console
}