( message: string, priority: 'polite' | 'assertive' = 'polite' )
| 3 | * SSR-safe: no-op when document is not available. |
| 4 | */ |
| 5 | export function announce( |
| 6 | message: string, |
| 7 | priority: 'polite' | 'assertive' = 'polite' |
| 8 | ): void { |
| 9 | // SSR safety check |
| 10 | if (typeof document === 'undefined') { |
| 11 | return; |
| 12 | } |
| 13 | |
| 14 | const announcement = document.createElement('div'); |
| 15 | announcement.setAttribute('role', 'status'); |
| 16 | announcement.setAttribute('aria-live', priority); |
| 17 | announcement.setAttribute('aria-atomic', 'true'); |
| 18 | announcement.style.position = 'absolute'; |
| 19 | announcement.style.left = '-10000px'; |
| 20 | announcement.style.width = '1px'; |
| 21 | announcement.style.height = '1px'; |
| 22 | announcement.style.overflow = 'hidden'; |
| 23 | announcement.textContent = message; |
| 24 | |
| 25 | document.body.appendChild(announcement); |
| 26 | |
| 27 | // Remove after announcement |
| 28 | setTimeout(() => { |
| 29 | document.body.removeChild(announcement); |
| 30 | }, 1000); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Format size for screen reader announcement |
no outgoing calls
no test coverage detected
searching dependent graphs…