useToast

Provides the behavior and accessibility implementation for a toast component. Toasts display brief, temporary notifications of actions, errors, or other events in an application.

Example
Toast.tsx
Toast.css
Button.tsx
Button.css
import {ToastProvider, Button} from './Toast';

<ToastProvider>
  {state => (
    <Button onPress={() => state.add('Toast is done!')}>Show toast</Button>
  )}
</ToastProvider>

API

Analysis completeTitleClose buttonToastRegion
<ToastRegion>
  {({toast}) => (
    <Toast toast={toast}>
      <ToastContent>
        <Text slot="title" />
        <Text slot="description" />
      </ToastContent>
      <Button slot="close" />
    </Toast>
  )}
</ToastRegion>
useToastState<T>(props: ): <T>useToastQueue<T>(queue: <T>): <T>useToastRegion<T>( props: , state: <T>, ref: <HTMLElementnull> ): useToast<T>( props: <T>, state: <T>, ref: <FocusableElementnull> ):

ToastState

Properties

NameType
visibleToasts<T>[]

The visible toasts.

Methods

add(content: T, options?: ): string
Adds a new toast to the queue.
close(key: string): void
Closes a toast.
pauseAll(): void
Pauses the timers for all visible toasts.
resumeAll(): void
Resumes the timers for all visible toasts.

AriaToastRegionProps

NameType

ToastRegionAria

NameType
regionPropsDOMAttributes

Props for the landmark region element.

AriaToastProps

NameType
toast<T>

The toast object.

ToastAria

NameType
toastPropsDOMAttributes

Props for the toast container, non-modal dialog element.

contentPropsDOMAttributes

Props for the toast content alert message.

titlePropsDOMAttributes

Props for the toast title element.

descriptionPropsDOMAttributes

Props for the toast description element, if any.

closeButtonProps

Props for the toast close button.