announcer
import "drab/announcer/define";
<script type="module">
const announcer = document.querySelector("drab-announcer");
const button = document.querySelector("#greeting");
button.addEventListener("click", () => announcer.announce("Greetings!"));
</script>
<drab-announcer></drab-announcer>
<button type="button" id="greeting" class="mb-4">Announce</button>
<div>Activate your screen reader to hear the greeting.</div>
Overview
Defined in: announcer/index.ts:40
Use the Announcer element to create a visually hidden ARIA live region
that announces content changes to screen readers. Use this element when you
need to announce changes to screen readers that something has changed. If changed
element is visible on the page, add the appropriate ARIA live attribute to the
visible element instead of using this announcer.
It’s recommended to create this element with JavaScript using the Announcer.init method,
then you can reuse the same announcer throughout the application to
avoid duplicate regions
(see below).
Attributes
aria-live
By default, the announcer is created with the
polite ARIA live attribute.
Example
import { Announcer } from "drab/announcer";
// creates and appends a new announcer to the body element
const announcer = Announcer.init();
// create announcement
announcer.announce("message");
The
Baseelement creates a singleAnnouncerto share between all elements that can be accessed throughthis.announce. If you are using one of drab’s other elements you can callannouncedirectly on the element to announce changes.
Constructors
Constructor
new Announcer():
Announcer
Defined in: announcer/index.ts:41
Returns
Announcer
Overrides
HTMLElement.constructor
Methods
announce()
announce(
message):void
Defined in: announcer/index.ts:62
Parameters
message
string
message to announce to screen readers
Returns
void
connectedCallback()
connectedCallback():
void
Defined in: announcer/index.ts:45
Returns
void
init()
staticinit():Announcer
Defined in: announcer/index.ts:79
Helper method to create a new Announcer element named drab-announcer
and append the element to the <body> tag. If an announcer already exists
on the page it will return the existing element.
Returns
Announcer
the created or existing Announcer element