UNPKG

@studiocms/ui

Version:

The UI library for StudioCMS. Includes the layouts & components we use to build StudioCMS.

25 lines (24 loc) 928 B
function loadCheckboxes() { const allElements = document.querySelectorAll(".sui-checkmark-container"); const allCheckbox = document.querySelectorAll(".sui-checkbox"); for (const element of allElements) { if (element.dataset.initialized) continue; element.dataset.initialized = "true"; element.addEventListener("keydown", (e) => { if (e.key !== "Enter" && e.key !== " ") return; e.preventDefault(); const checkbox = element.querySelector(".sui-checkbox"); if (!checkbox) return; checkbox.click(); }); } for (const box of allCheckbox) { if (box.dataset.initialized) continue; box.dataset.initialized = "true"; box.addEventListener("change", (e) => { box.parentElement.ariaChecked = e.target.checked ? "true" : "false"; box.ariaChecked = e.target.checked ? "true" : "false"; }); } } document.addEventListener("astro:page-load", loadCheckboxes);