UNPKG

@studiocms/ui

Version:

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

24 lines (23 loc) 884 B
function loadToggles() { const allToggleElements = document.querySelectorAll(".sui-toggle-container"); const allToggles = document.querySelectorAll(".sui-toggle-checkbox"); for (const element of allToggleElements) { 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-toggle-checkbox"); if (!checkbox) return; checkbox.click(); }); } for (const box of allToggles) { if (box.dataset.initialized) continue; box.dataset.initialized = "true"; box.addEventListener("change", (e) => { box.previousSibling.ariaChecked = e.target.checked ? "true" : "false"; }); } } document.addEventListener("astro:page-load", loadToggles);