Skip to content

LiveRegion

Says something to screen readers without moving the focus: a count that changes, «3 rows exported». announce() does it from anywhere.

import { LiveRegion } from '@sypnia/ui/react'

On this page
  1. A count and a message
  2. When to use it
  3. For everyone
  4. Props

A count and a message

3 rows selected
Code
import { useState } from 'react';
import { announce, Button, LiveRegion } from '@sypnia/ui/react';

// A screen reader says the count when it changes, and «Exported» without moving the focus.
export default function Count() {
  const [n, setN] = useState(3);
  return (
    <div className="sy-stack" style={{ '--gap': 'var(--s-3)' } as React.CSSProperties}>
      <LiveRegion>{n} rows selected</LiveRegion>
      <div className="sy-row"><Button onClick={() => setN(n + 1)}>Select one more</Button><Button onClick={() => announce('Exported 3 rows')}>Export</Button></div>
    </div>
  );
}

When to use it

Use it when

  • Results of an action that has no other visible answer near the focus.

Do not use it when

  • Everything that changes: people hear it all. Announce what they asked for.

For everyone

  • Polite waits for a pause; assertive interrupts and is only for failures.

Props

LiveRegionTypeDefault
className string
mode "assertive" | "polite" polite
visible boolean true
  1. A count and a message
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms