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

0.1.1 • Public • Published

Build Status Coverage Status

Extended screen reader support for React components

react-screenreader exposes useScreenReader React hook which allows you to easily implement custom dynamic descriptions for screen readers.

Requirements

react-screenreader has no dependencies however it relies on react ^16.8.6 and react-dom ^16.8.6 as peer dependencies.

Installation

yarn add react-screenreader

Usage

useScreenReader hook returns an object with the following properties:

  • reader function will return onFocus and onBlur event handlers which allows you to "read" any string when an element is focused. Make sure that target element can accept and properly utilize these props.
  • read function allows you to "read" strings programmatically.
  • a11y will render neccessary content for screen reader.

Basic example:

import react, { useCallback } from 'react';
import useScreenReader from 'react-screenreader';
 
const MyComponent = () => {
    const { reader, read, a11y } = useScreenReader();
 
    const onButtonClick = useCallback(() => read(`Hello screen reader!`), []);
 
    return (
        <div>
            {a11y()}
            <button 
                onClick={onButtonClick} 
                {...reader("This sentence will be read on button focus")}
                >
                Click me to hear the voice
            </button>
        </div>
    )
}

Package Sidebar

Install

npm i react-screenreader

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

17 kB

Total Files

9

Last publish

Collaborators

  • mr-zoidberg