JavaScript
Dispatch an integration event, disable the action, and announce both cooldown states.
import { createA11yOtpField } from "./dist/index.js";
const root = document.querySelector("[data-a11y-otp]");
const otp = createA11yOtpField(root);
const button = root.querySelector(".a11y-otp__resend");
const status = root.querySelector(".a11y-otp__status");
button.addEventListener("click", () => {
root.dispatchEvent(new CustomEvent("a11y-otp-field:resend", {
detail: { value: otp.getValue() }
}));
button.disabled = true;
status.textContent = "You can request a new code in 30 seconds.";
setTimeout(() => {
button.disabled = false;
status.textContent = "You can request a new code again now.";
}, 30000);
});