mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-11-28 18:28:04 -08:00
18 lines
518 B
JavaScript
18 lines
518 B
JavaScript
// show a short confirmation in a role="status" element, which screen readers announce, then clear it
|
|
const clearTimers = new WeakMap();
|
|
|
|
const announce = (elem, text, duration = 5000) => {
|
|
if (!elem) return;
|
|
clearTimeout(clearTimers.get(elem));
|
|
// empty it first so the same message is announced again when it repeats
|
|
elem.textContent = '';
|
|
setTimeout(() => {
|
|
elem.textContent = text;
|
|
clearTimers.set(elem, setTimeout(() => {
|
|
elem.textContent = '';
|
|
}, duration));
|
|
}, 100);
|
|
};
|
|
|
|
export default announce;
|