Snackbars show short updates about app processes at the bottom of the screen. They inform people of a process that the app has performed or will perform, such as archiving an email or saving a draft.
- A snackbar does not interrupt: people can keep using the page without responding to it.
- One snackbar shows at a time.
- A snackbar can have a single action, such as Undo. Do not make a snackbar the only way to reach something the app needs to be usable.
To interrupt people with a message that needs a response, use a dialog instead.
import {
Snackbar,
SnackbarAction,
SnackbarCloseButton,
SnackbarContent,
SnackbarQueue,
SnackbarRegion,
} from '@material-web/react'
import { Text } from 'react-aria-components'Basic snackbar
A snackbar appears for a short time towards the bottom of the window, in front of the page. This one has a text, an action and a close button.
import {
Button,
Icon,
Snackbar,
SnackbarAction,
SnackbarCloseButton,
SnackbarContent,
SnackbarQueue,
SnackbarRegion,
} from '@material-web/react'
import { Text } from 'react-aria-components'
const snackbars = new SnackbarQueue<string>()
export default function Basic() {
return (
<>
<Button variant="tonal" onPress={() => snackbars.add('Email archived')}>
Archive email
</Button>
<SnackbarRegion queue={snackbars}>
{({ toast }) => (
<Snackbar toast={toast}>
<SnackbarContent>
<Text slot="title">{toast.content}</Text>
</SnackbarContent>
<SnackbarAction onPress={() => snackbars.close(toast.key)}>Undo</SnackbarAction>
<SnackbarCloseButton>
<Icon name="close" />
</SnackbarCloseButton>
</Snackbar>
)}
</SnackbarRegion>
</>
)
}Create a SnackbarQueue, render a SnackbarRegion for it once, and call the queue's add from anywhere in the app to show a snackbar. The region's children are a function that renders each snackbar: a Snackbar with its text in a SnackbarContent, then its action, a SnackbarAction, and its close button, a SnackbarCloseButton. Use these two parts for a snackbar's buttons, not a Button or an IconButton.
The queue, the region and the snackbar work as the parts of React Aria's Toast do.
Note: The snackbar's API may change in a later version.
Composition
A snackbar is composed of these parts:
<SnackbarRegion queue={snackbars}>
{({ toast }) => (
<Snackbar toast={toast}>
<SnackbarContent>
<Text slot="title" />
<Text slot="description" />
</SnackbarContent>
<SnackbarAction />
<SnackbarCloseButton />
</Snackbar>
)}
</SnackbarRegion>These are the parts, where each goes, and what it takes:
| Part | In | Use |
|---|---|---|
SnackbarQueue | Your app, created once | The queue of snackbars to show. It takes two options: maxVisibleToasts, the number of snackbars shown at a time, which is 1 (the default), and wrapUpdate, a function that runs each change to the queue. |
SnackbarRegion | Your app, rendered once | Shows the queue's snackbars. It takes the queue and, as its children, a function that renders each toast. Its className and style can be functions of visibleToasts, isHovered, isFocused and isFocusVisible. |
Snackbar | The region's function | One snackbar. It takes the toast to show. Its className, style and children can be functions of toast, isFocused and isFocusVisible. |
SnackbarContent | Snackbar | Holds the snackbar's text |
SnackbarAction | Snackbar | The action, after the SnackbarContent. It takes onPress and the other press props of a button. Its children can be a function of isHovered, isPressed, isFocused, isFocusVisible and isDisabled. |
SnackbarCloseButton | Snackbar | The close button, last. It takes the same props as a SnackbarAction. |
Queue and region
Create one queue for the app, render one region, and add to the queue from anywhere:
const snackbars = new SnackbarQueue<{ text: string; action?: string }>()
function Snackbars() {
return (
<SnackbarRegion queue={snackbars}>
{({ toast }) => (
<Snackbar toast={toast}>
<SnackbarContent>
<Text slot="title">{toast.content.text}</Text>
</SnackbarContent>
{toast.content.action && (
<SnackbarAction
onPress={() => {
undo()
snackbars.close(toast.key)
}}
>
{toast.content.action}
</SnackbarAction>
)}
<SnackbarCloseButton>
<Icon name="close" />
</SnackbarCloseButton>
</Snackbar>
)}
</SnackbarRegion>
)
}
snackbars.add({ text: 'Email archived', action: 'Undo' })
snackbars.add({ text: 'All changes saved' }, { timeout: 5000 })The content of a snackbar is yours to shape: a string, or an object as above. Type it on the queue, and read it as toast.content in the region's function.
Note: Each example on this page has its own queue and region. All but the one with a dialog show their snackbars in the example's frame, which stands in for the window.
Content
Put the snackbar's text in a SnackbarContent. After it, write the action as a SnackbarAction with its label as its children, and the close button as a SnackbarCloseButton with an icon as its child. Both buttons are optional.
An action that is wider than 128dp together with the close button moves below the text, at the end, and the close button moves with it. The text then takes the whole row. A label wider than that row wraps.
In this example, the region has className="max-w-86", which limits its width to 344dp, so that the longer text takes two lines.
import {
Button,
Icon,
Snackbar,
SnackbarAction,
SnackbarCloseButton,
SnackbarContent,
SnackbarQueue,
SnackbarRegion,
} from '@material-web/react'
import { Text } from 'react-aria-components'
type Message = { text: string; action?: string }
const snackbars = new SnackbarQueue<Message>()
const messages: [label: string, message: Message][] = [
['Single line', { text: 'Photo archived' }],
['With action', { text: 'Photo added to “Natural Light” album', action: 'View' }],
[
'Two lines',
{ text: 'The item already has the label “travel.” Add a new label, or choose another one.' },
],
[
'Longer action',
{ text: 'Can’t add photo to your favorites', action: 'Learn more about storage' },
],
]
export default function Configurations() {
return (
<div className="box-border flex h-64 w-full flex-wrap content-start justify-center gap-space-100 p-space-300">
{messages.map(([label, message]) => (
<Button key={label} variant="outlined" onPress={() => snackbars.add(message)}>
{label}
</Button>
))}
<SnackbarRegion queue={snackbars} className="max-w-86">
{({ toast }) => (
<Snackbar toast={toast}>
<SnackbarContent>
<Text slot="title">{toast.content.text}</Text>
</SnackbarContent>
{toast.content.action && (
<SnackbarAction onPress={() => snackbars.close(toast.key)}>
{toast.content.action}
</SnackbarAction>
)}
<SnackbarCloseButton>
<Icon name="close" />
</SnackbarCloseButton>
</Snackbar>
)}
</SnackbarRegion>
</div>
)
}Slots
- title
- description
| Slot | Child | Use |
|---|---|---|
title | A Text | The text, which names the snackbar |
description | A Text | Describes the snackbar |
Each takes a separate line.
import {
Button,
Icon,
Snackbar,
SnackbarCloseButton,
SnackbarContent,
SnackbarQueue,
SnackbarRegion,
} from '@material-web/react'
import { Text } from 'react-aria-components'
const snackbars = new SnackbarQueue<{ title: string; description: string }>()
export default function Description() {
return (
<>
<Button
variant="tonal"
onPress={() =>
snackbars.add({ title: 'Upload paused', description: 'It resumes once you are online.' })
}
>
Pause upload
</Button>
<SnackbarRegion queue={snackbars}>
{({ toast }) => (
<Snackbar toast={toast}>
<SnackbarContent>
<Text slot="title">{toast.content.title}</Text>
<Text slot="description">{toast.content.description}</Text>
</SnackbarContent>
<SnackbarCloseButton>
<Icon name="close" />
</SnackbarCloseButton>
</Snackbar>
)}
</SnackbarRegion>
</>
)
}Showing and closing
The queue shows one snackbar at a time. Its maxVisibleToasts option sets how many.
- Call
add(content, options)to show a snackbar at once. It returns the snackbar's key. - Call
close(key)to close a snackbar, andclear()to close them all. - An action does not close its snackbar. Call
close(toast.key)in itsonPress. - A close button closes its snackbar when pressed.
For the queue's other methods, see React Aria's ToastQueue.
Dismissal
Pass a timeout in milliseconds in the options of add to close a snackbar automatically, and an onClose to be called when it closes. Without a timeout, a snackbar stays until it is closed.
- Give a snackbar with an action no timeout.
- For a snackbar with no action, use a timeout of at least 5 seconds and at most 10, and show inline feedback as well.
- The timer pauses while the pointer is on the snackbar or the focus is in it.
In this example, the button's label changes to Saved as the inline feedback, and the snackbar closes after 5 seconds.
import {
Button,
Snackbar,
SnackbarContent,
SnackbarQueue,
SnackbarRegion,
} from '@material-web/react'
import { useState } from 'react'
import { Text } from 'react-aria-components'
const snackbars = new SnackbarQueue<string>()
export default function Timeout() {
const [isSaved, setSaved] = useState(false)
return (
<>
<Button
isDisabled={isSaved}
onPress={() => {
setSaved(true)
snackbars.add('All changes saved', { timeout: 5000, onClose: () => setSaved(false) })
}}
>
{isSaved ? 'Saved' : 'Save'}
</Button>
<SnackbarRegion queue={snackbars}>
{({ toast }) => (
<Snackbar toast={toast}>
<SnackbarContent>
<Text slot="title">{toast.content}</Text>
</SnackbarContent>
</Snackbar>
)}
</SnackbarRegion>
</>
)
}Consecutive snackbars
A snackbar added while another shows takes its place, and the earlier one comes back once the newer one has closed. To replace a snackbar for good, close it before you add the next.
import {
Button,
Icon,
Snackbar,
SnackbarCloseButton,
SnackbarContent,
SnackbarQueue,
SnackbarRegion,
} from '@material-web/react'
import { useState } from 'react'
import { Text } from 'react-aria-components'
const snackbars = new SnackbarQueue<string>()
export default function Consecutive() {
const [count, setCount] = useState(0)
return (
<>
<Button
variant="outlined"
onPress={() => {
setCount(count + 1)
snackbars.add(`Message ${count + 1}`)
}}
>
Add a snackbar
</Button>
<SnackbarRegion queue={snackbars}>
{({ toast }) => (
<Snackbar toast={toast}>
<SnackbarContent>
<Text slot="title">{toast.content}</Text>
</SnackbarContent>
<SnackbarCloseButton>
<Icon name="close" />
</SnackbarCloseButton>
</Snackbar>
)}
</SnackbarRegion>
</>
)
}Placement
The region is fixed to the bottom of the window, centered, 12dp from its edges and up to 600dp wide. It is in front of the page, at z-snackbar. Set a className on the SnackbarRegion to move it:
bottom-22places it above a FAB that is 16dp from the corner. See Snackbar with FAB.mx-0aligns it to the window's start.statickeeps it inside a container that you render it into withUNSAFE_PortalProvider.
In a wide window, a snackbar can be centered or aligned to the start, as long as it always shows in the same place. Avoid placing it in front of navigation or other frequently used targets.
In this example, the region has className="mx-0 max-w-86": it is aligned to the start, and up to 344dp wide.
import {
Button,
Icon,
Snackbar,
SnackbarCloseButton,
SnackbarContent,
SnackbarQueue,
SnackbarRegion,
} from '@material-web/react'
import { Text } from 'react-aria-components'
const snackbars = new SnackbarQueue<string>()
export default function Aligned() {
return (
<>
<Button variant="outlined" onPress={() => snackbars.add('Photo archived')}>
Archive photo
</Button>
<SnackbarRegion queue={snackbars} className="mx-0 max-w-86">
{({ toast }) => (
<Snackbar toast={toast}>
<SnackbarContent>
<Text slot="title">{toast.content}</Text>
</SnackbarContent>
<SnackbarCloseButton>
<Icon name="close" />
</SnackbarCloseButton>
</Snackbar>
)}
</SnackbarRegion>
</>
)
}Snackbar with FAB
Show a snackbar above a FAB, not in front of it. Set className="bottom-22" on the SnackbarRegion to place it above a FAB that is 16dp from the corner.
import {
Button,
Fab,
Icon,
Snackbar,
SnackbarAction,
SnackbarContent,
SnackbarQueue,
SnackbarRegion,
} from '@material-web/react'
import { Text } from 'react-aria-components'
const snackbars = new SnackbarQueue<string>()
export default function Position() {
return (
<div className="relative flex h-64 w-full items-start justify-center">
<Button
variant="outlined"
className="mt-space-300"
onPress={() => snackbars.add('Draft saved')}
>
Save draft
</Button>
<Fab aria-label="Compose" className="absolute end-space-200 bottom-space-200">
<Icon name="edit" />
</Fab>
<SnackbarRegion queue={snackbars} className="bottom-22">
{({ toast }) => (
<Snackbar toast={toast}>
<SnackbarContent>
<Text slot="title">{toast.content}</Text>
</SnackbarContent>
<SnackbarAction onPress={() => snackbars.close(toast.key)}>Undo</SnackbarAction>
</Snackbar>
)}
</SnackbarRegion>
</div>
)
}Snackbar with dialog
A snackbar shows in front of an open dialog, and can be used while the dialog is open. Add it from inside the dialog as from anywhere else.
- A press on the snackbar does not close the dialog.
- Escape closes the snackbar while the focus is in it, and the dialog otherwise.
- F6 moves the focus from the dialog to the snackbar.
import {
Button,
Dialog,
DialogTrigger,
Icon,
Snackbar,
SnackbarCloseButton,
SnackbarContent,
SnackbarQueue,
SnackbarRegion,
} from '@material-web/react'
import { Heading, Text } from 'react-aria-components'
const snackbars = new SnackbarQueue<string>()
export default function InDialog() {
return (
<>
<DialogTrigger>
<Button variant="tonal">Share album</Button>
<Dialog>
<Heading
slot="title"
className="m-0 px-space-300 pb-space-200 text-headline-sm text-on-surface"
>
Share album
</Heading>
<Text slot="description" elementType="p" className="m-0 px-space-300 pb-space-100">
Anyone with the link can view this album.
</Text>
<div className="flex shrink-0 justify-end gap-space-100 px-space-300 pt-space-200">
<Button variant="text" onPress={() => snackbars.add('Link copied', { timeout: 5000 })}>
Copy link
</Button>
<Button variant="text" slot="close">
Done
</Button>
</div>
</Dialog>
</DialogTrigger>
<SnackbarRegion queue={snackbars}>
{({ toast }) => (
<Snackbar toast={toast}>
<SnackbarContent>
<Text slot="title">{toast.content}</Text>
</SnackbarContent>
<SnackbarCloseButton>
<Icon name="close" />
</SnackbarCloseButton>
</Snackbar>
)}
</SnackbarRegion>
</>
)
}Customization
Pass classes in className to restyle a part of a snackbar. A class of yours replaces the part's own class for the same property. See Styling for the classes, the states and the theme.
In this example, the snackbar of a failed upload takes the error color roles. The close button has a color of its own, so it takes the on-color too.
import {
Button,
Icon,
Snackbar,
SnackbarCloseButton,
SnackbarContent,
SnackbarQueue,
SnackbarRegion,
} from '@material-web/react'
import { Text } from 'react-aria-components'
const snackbars = new SnackbarQueue<{ text: string; isError?: boolean }>()
export default function Custom() {
return (
<>
<Button variant="outlined" onPress={() => snackbars.add({ text: 'Photo uploaded' })}>
Upload
</Button>
<Button
variant="outlined"
onPress={() => snackbars.add({ text: 'Upload failed', isError: true })}
>
Fail
</Button>
<SnackbarRegion queue={snackbars}>
{({ toast }) => (
<Snackbar
toast={toast}
className={toast.content.isError ? 'bg-error text-on-error' : undefined}
>
<SnackbarContent>
<Text slot="title">{toast.content.text}</Text>
</SnackbarContent>
<SnackbarCloseButton className={toast.content.isError ? 'text-on-error' : undefined}>
<Icon name="close" />
</SnackbarCloseButton>
</Snackbar>
)}
</SnackbarRegion>
</>
)
}- Color: Pass a container color and the on-color of that container to the
Snackbar, as inbg-error text-on-error. Pass a text color to aSnackbarActionand aSnackbarCloseButtonas well: their hover, focus and press states follow it. - Functions: On every part but the
SnackbarContent,classNameandstylecan be functions of the part's state. See Composition for the state of each part, and Children as a function. - Ancestors: The region is rendered at the end of the page, not inside the element it is written in. A class or a
data-themeon an element around it does not reach the snackbars. Set it on theSnackbarRegionitself, or on the root element. - Every snackbar: To restyle all the snackbars at once, change the theme.
Transitions
The queue runs each change in a view transition. Pass a wrapUpdate function in the queue's options to run the changes yourself. A view transition that you start there animates the snackbars only if it has the type snackbar.
Use cases
Material lists what people should be able to do with assistive technology:
- Be alerted, but not disrupted, when a snackbar appears
- Move focus to an actionable snackbar
- Take action on a snackbar using assistive technology
Interaction and style
- States: The action and the close button show a state layer on hover and a ripple on a press, in their own colors. Keyboard focus shows a focus ring around the snackbar and around each button, and a press with a mouse or touch does not.
- Touch target: The action and the close button each have a touch target of at least 48dp.
- Color contrast: A snackbar uses the inverse colors, which stand out from the page. Material advises keeping the default colors, to avoid color conflicts. The text and the action have 4.5:1 contrast or more with the snackbar, and the close icon and the focus rings 3:1, in light and dark schemes at every contrast level.
- Motion: With reduced motion, a snackbar shows and hides at once.
- Forced colors: A snackbar keeps an edge in forced colors.
- Auto-dismiss: On the web, Material requires that the message of a snackbar that closes by itself also show inline, near the action that triggered it, such as a Save button's label changing to Saved. Otherwise, give the snackbar an action and no
timeout: a snackbar with an action should not close by itself. See Dismissal. The timer pauses while the pointer is on the snackbar or the focus is in it.
Focus
- A snackbar appears without moving the focus, and does not keep it.
- F6 moves the focus to the region from anywhere in the page, and Shift+F6 moves it back. Material advises a shortcut like this on the web: tell people about it, such as in a help article.
- Tab reaches the snackbar after the rest of the page, then its action and close button, and then moves on.
- Escape closes the snackbar while the focus is in it. The focus then returns to where it was before.
Keyboard navigation
| Keys | Actions |
|---|---|
| F6 | Move the focus to the snackbar region |
| Shift+F6 | Move the focus back |
| Tab | Move the focus to the snackbar, then to its action and close button |
| Space or Enter | Press the focused action or close button |
| Escape | Close the snackbar while the focus is in it |
Labeling elements
- A snackbar has the
alertdialogrole. Name it with aTextwithslot="title"in itsSnackbarContent, and describe it with one withslot="description". - Its text is in the
alertrole. Assistive technology announces a snackbar's text at once as it appears. - The region is a landmark, named by the number of snackbars it shows.
- The action is named by its label. The close button is named Close, in the app's locale, unless you set an
aria-label.
SnackbarRegion
Props of SnackbarRegion (10)
classNamestring | (values: ToastRegionRenderProps<T> & { defaultClassName: string | undefined; }) => stringDefault'react-aria-ToastRegion'The CSS className for the element. A function may be provided to compute the class based on component state.
queuerequiredToastQueue<T>The queue of toasts to display.
childrenrequiredReactNode | ((renderProps: { toast: QueuedToast<T>; }) => ReactElement)A function to render each toast, or children containing a
<ToastList>.aria-labelstringDefault'Notifications'An accessibility label for the toast region.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
styleCSSProperties | (values: ToastRegionRenderProps<T> & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
renderDOMRenderFunction<'div', ToastRegionRenderProps<T>>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
refRef<HTMLDivElement>
SnackbarRegion also takes the 70 attributes and events of the element it renders.
Snackbar
Props of Snackbar (10)
classNamestring | (values: ToastRenderProps<T> & { defaultClassName: string | undefined; }) => stringDefault'react-aria-Toast'The CSS className for the element. A function may be provided to compute the class based on component state.
toastrequiredQueuedToast<T>The toast object.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
childrenChildrenOrFunction<T>The children of the component. A function may be provided to alter the children based on component state.
styleCSSProperties | (values: ToastRenderProps<T> & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
renderDOMRenderFunction<'div', ToastRenderProps<T>>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
refRef<HTMLDivElement>
Snackbar also takes the 70 attributes and events of the element it renders.
SnackbarContent
SnackbarContent accepts the props of a <div>, and a ref to it.
Props of SnackbarContent (1)
renderDOMRenderFunction<'div', undefined>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
SnackbarContent also takes the 278 attributes and events of the element it renders.
SnackbarAction
isPendingbooleanWhether the button is in a pending state. This disables press and hover events while retaining focusability, and announces the pending state to screen readers.
Props of SnackbarAction (47)
formstringThe
<form>element to associate the button with. The value of this attribute must be the id of a<form>in the same document. See MDN.idstringThe element's unique identifier. See MDN.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
onClick(e: MouseEvent<FocusableElement>) => voidNot recommended – use
onPressinstead.onClickis an alias foronPressprovided for compatibility with other libraries.onPressprovides additional event details for non-mouse interactions.isDisabledbooleanWhether the button is disabled.
onPress(e: PressEvent) => voidHandler that is called when the press is released over the target.
onPressStart(e: PressEvent) => voidHandler that is called when a press interaction starts.
onPressEnd(e: PressEvent) => voidHandler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
onPressChange(isPressed: boolean) => voidHandler that is called when the press state changes.
onPressUp(e: PressEvent) => voidHandler that is called when a press is released over the target, regardless of whether it started on the target or not.
autoFocusbooleanWhether the element should receive focus on render.
onFocus(e: FocusEvent<Target>) => voidHandler that is called when the element receives focus.
onBlur(e: FocusEvent<Target>) => voidHandler that is called when the element loses focus.
onFocusChange(isFocused: boolean) => voidHandler that is called when the element's focus status changes.
onKeyDown(e: KeyboardEvent) => voidHandler that is called when a key is pressed.
onKeyUp(e: KeyboardEvent) => voidHandler that is called when a key is released.
hrefstringA URL to link to if elementType="a".
targetstringThe target window for the link.
relstringThe relationship between the linked resource and the current page. See MDN.
elementTypeT | JSXElementConstructor<any>Default'button'The HTML element or React element used to render the button, e.g. 'div', 'a', or
RouterLink.aria-disabled'true' | 'false' | booleanIndicates whether the element is disabled to users of assistive technology.
aria-expanded'true' | 'false' | booleanIndicates whether the element, or another grouping element it controls, is currently expanded or collapsed.
aria-haspopup'dialog' | 'menu' | 'true' | 'false' | 'grid' | 'listbox' | 'tree' | booleanIndicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
aria-controlsstringIdentifies the element (or elements) whose contents or presence are controlled by the current element.
aria-pressed'true' | 'false' | 'mixed' | booleanIndicates the current "pressed" state of toggle buttons.
aria-current'time' | 'true' | 'false' | 'page' | 'step' | 'location' | 'date' | booleanIndicates whether this element represents the current item within a container or set of related elements.
type'button' | 'submit' | 'reset'Default'button'The behavior of the button when used in an HTML form.
preventFocusOnPressbooleanWhether to prevent focus from moving to the button when pressing it.
Caution, this can make the button inaccessible and should only be used when alternative keyboard interaction is provided, such as ComboBox's MenuTrigger or a NumberField's increment/decrement control.
formActionButtonHTMLAttributes<HTMLButtonElement>['formAction']The URL that processes the information submitted by the button. Overrides the action attribute of the button's form owner.
formEncTypestringIndicates how to encode the form data that is submitted.
formMethodstringIndicates the HTTP method used to submit the form.
formNoValidatebooleanIndicates that the form is not to be validated when it is submitted.
formTargetstringOverrides the target attribute of the button's form owner.
namestringSubmitted as a pair with the button's value as part of the form data.
valuestringThe value associated with the button's name when it's submitted with the form data.
excludeFromTabOrderbooleanWhether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available.
onHoverStart(e: HoverEvent) => voidHandler that is called when a hover interaction starts.
onHoverEnd(e: HoverEvent) => voidHandler that is called when a hover interaction ends.
onHoverChange(isHovering: boolean) => voidHandler that is called when the hover state changes.
slotstring | nullA slot name for the component. Slots allow the component to receive props from a parent component. An explicit
nullvalue indicates that the local props completely override all props received from a parent.refRef<ComponentRef<T> & Element>classNameClassNameOrFunction<ButtonRenderProps>styleStyleOrFunction<ButtonRenderProps>childrenChildrenOrFunction<ButtonRenderProps>
SnackbarCloseButton
isPendingbooleanWhether the button is in a pending state. This disables press and hover events while retaining focusability, and announces the pending state to screen readers.
Props of SnackbarCloseButton (47)
formstringThe
<form>element to associate the button with. The value of this attribute must be the id of a<form>in the same document. See MDN.idstringThe element's unique identifier. See MDN.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
onClick(e: MouseEvent<FocusableElement>) => voidNot recommended – use
onPressinstead.onClickis an alias foronPressprovided for compatibility with other libraries.onPressprovides additional event details for non-mouse interactions.isDisabledbooleanWhether the button is disabled.
onPress(e: PressEvent) => voidHandler that is called when the press is released over the target.
onPressStart(e: PressEvent) => voidHandler that is called when a press interaction starts.
onPressEnd(e: PressEvent) => voidHandler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
onPressChange(isPressed: boolean) => voidHandler that is called when the press state changes.
onPressUp(e: PressEvent) => voidHandler that is called when a press is released over the target, regardless of whether it started on the target or not.
autoFocusbooleanWhether the element should receive focus on render.
onFocus(e: FocusEvent<Target>) => voidHandler that is called when the element receives focus.
onBlur(e: FocusEvent<Target>) => voidHandler that is called when the element loses focus.
onFocusChange(isFocused: boolean) => voidHandler that is called when the element's focus status changes.
onKeyDown(e: KeyboardEvent) => voidHandler that is called when a key is pressed.
onKeyUp(e: KeyboardEvent) => voidHandler that is called when a key is released.
hrefstringA URL to link to if elementType="a".
targetstringThe target window for the link.
relstringThe relationship between the linked resource and the current page. See MDN.
elementTypeT | JSXElementConstructor<any>Default'button'The HTML element or React element used to render the button, e.g. 'div', 'a', or
RouterLink.aria-disabled'true' | 'false' | booleanIndicates whether the element is disabled to users of assistive technology.
aria-expanded'true' | 'false' | booleanIndicates whether the element, or another grouping element it controls, is currently expanded or collapsed.
aria-haspopup'dialog' | 'menu' | 'true' | 'false' | 'grid' | 'listbox' | 'tree' | booleanIndicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
aria-controlsstringIdentifies the element (or elements) whose contents or presence are controlled by the current element.
aria-pressed'true' | 'false' | 'mixed' | booleanIndicates the current "pressed" state of toggle buttons.
aria-current'time' | 'true' | 'false' | 'page' | 'step' | 'location' | 'date' | booleanIndicates whether this element represents the current item within a container or set of related elements.
type'button' | 'submit' | 'reset'Default'button'The behavior of the button when used in an HTML form.
preventFocusOnPressbooleanWhether to prevent focus from moving to the button when pressing it.
Caution, this can make the button inaccessible and should only be used when alternative keyboard interaction is provided, such as ComboBox's MenuTrigger or a NumberField's increment/decrement control.
formActionButtonHTMLAttributes<HTMLButtonElement>['formAction']The URL that processes the information submitted by the button. Overrides the action attribute of the button's form owner.
formEncTypestringIndicates how to encode the form data that is submitted.
formMethodstringIndicates the HTTP method used to submit the form.
formNoValidatebooleanIndicates that the form is not to be validated when it is submitted.
formTargetstringOverrides the target attribute of the button's form owner.
namestringSubmitted as a pair with the button's value as part of the form data.
valuestringThe value associated with the button's name when it's submitted with the form data.
excludeFromTabOrderbooleanWhether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available.
onHoverStart(e: HoverEvent) => voidHandler that is called when a hover interaction starts.
onHoverEnd(e: HoverEvent) => voidHandler that is called when a hover interaction ends.
onHoverChange(isHovering: boolean) => voidHandler that is called when the hover state changes.
slotstring | nullA slot name for the component. Slots allow the component to receive props from a parent component. An explicit
nullvalue indicates that the local props completely override all props received from a parent.refRef<ComponentRef<T> & Element>classNameClassNameOrFunction<ButtonRenderProps>styleStyleOrFunction<ButtonRenderProps>childrenChildrenOrFunction<ButtonRenderProps>