Skip to content

Commit

Permalink
feat(snackbar): upd snackbar dismissal mechanisms
Browse files Browse the repository at this point in the history
  • Loading branch information
soykje committed Mar 19, 2024
1 parent 76a2894 commit a288d56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/components/snackbar/src/Snackbar.doc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ Use `icon` prop on snackbar item to add an icon before message.

### Dismiss

**To dismiss snackbar automatically** use `timeout` option. For accessibility reasons the value of this timeout shouldn't be less than 5 seconds.
**To dismiss snackbar automatically** use `timeout` option. For accessibility reasons the value of this timeout shouldn't be less than 5 seconds. Also for the same reasons timers will automatically pause when the user focuses or hovers over a snackbar.

**To allow the user to close by himself the snackbar** thanks to a dedicated close button, use `isClosable` prop on snackbar item, or as `addSnackbar` option.
**To allow the user to close the snackbar** thanks to a dedicated close button, use `isClosable` prop on snackbar item, or as `addSnackbar` option.

For both cases there is a specific `onClose` handler which is called when snackbar closes.

Expand Down
17 changes: 16 additions & 1 deletion packages/components/snackbar/src/Snackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,22 @@ export const Snackbar = forwardRef<HTMLDivElement, SnackbarProps>(

Snackbar.displayName = 'Snackbar'

export interface AddSnackbarArgs extends SnackbarItemValue, SnackBarItemOptions {}
export interface AddSnackbarArgs extends SnackbarItemValue, SnackBarItemOptions {
/**
* Handler that is called when the snackbar is closed, either by the user
* or after a timeout.
*/
onClose?: () => void
/**
* A timeout to automatically close the snackbar after, in milliseconds.
* @default 5000
*/
timeout?: number
/**
* The priority of the snackbar relative to other snackbars. Larger numbers indicate higher priority.
*/
priority?: number
}

export const addSnackbar = ({ onClose, timeout = 5000, priority, ...content }: AddSnackbarArgs) => {
const queue = getGlobalSnackBarQueue()
Expand Down

0 comments on commit a288d56

Please sign in to comment.