web_sr_announcer
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

Web Sr Announcer

A small utility to send messages to screen readers using aria-live

See Demo

Install

npm install --save web_sr_announcer

Or for a CDN version, you can use it on unpkg.com

<script src="https://unpkg.com/web_sr_announcer"></script>
<script>
  webSrAnnouncer.initialize()
</script>

Usage

import webSrAnnouncer from "web_sr_announcer" // or use the script tag using cdn.
webSrAnnouncer.initialize()

// just the message is needed.
webSrAnnouncer.announce("this is a test with default params")

// using all params.
webSrAnnouncer.announce("this is a test", "polite", 3000)

functions.

initialize.

this function creates or initializes the containers for the aria-live regions. call this before use announce function, otherwise the first message can be lost.

* nodeId: string, an optional param if you want to use your own html container for the aria live regions.

announce.

update the aria-live region with the specified message. If a screen reader is active, should speak the message.

this function has 3 params:

* text: string, the text to be announced.
* politeness: 'assertive' or 'polite', 'assertive' by default.
* timeout: number, the time the message is available for screen readers. Default is 1000 ms.

terminate.

removes the containers used for live regions. you usually don't need to use this.

Package Sidebar

Install

npm i web_sr_announcer

Weekly Downloads

2

Version

1.1.2

License

MIT

Unpacked Size

24.8 kB

Total Files

10

Last publish

Collaborators

  • davidacm