Skip to content

Commit

Permalink
Add 'intructed' to onClose callback reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhosseindhv committed Feb 23, 2020
1 parent da8f479 commit 20327b5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/SnackbarProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ class SnackbarProvider extends Component {
// call individual snackbar onClose callback passed through options parameter
const toBeClosed = this.state.snacks.find(item => item.key === key);
if (toBeClosed && toBeClosed.onClose) {
toBeClosed.onClose(null, null, key);
toBeClosed.onClose(null, REASONS.INSTRUCTED, key);
}

this.handleCloseSnack(null, null, key);
this.handleCloseSnack(null, REASONS.INSTRUCTED, key);
}

/**
Expand Down Expand Up @@ -378,7 +378,8 @@ SnackbarProvider.propTypes = {
*
* @param {object} event The event source of the callback
* @param {string} reason Can be:`"timeout"` (`autoHideDuration` expired) or: `"clickaway"`
* or: `"maxsnack"` (snackbar is closed because `maxSnack` has reached.)
* or: `"maxsnack"` (snackbar was closed because `maxSnack` has reached) or: `"instructed"`
* (snackbar was closed programmatically)
* @param {string|number} key key of a Snackbar
*/
onClose: PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type SnackbarMessage = string | React.ReactNode;
export type SnackbarAction = SnackbarContentProps['action'] | ((key: SnackbarKey) => React.ReactNode);
export type SnackbarContent = React.ReactNode | ((key: SnackbarKey, message: SnackbarMessage) => React.ReactNode);

export type CloseReason = 'timeout' | 'clickaway' | 'maxsnack' | null;
export type CloseReason = 'timeout' | 'clickaway' | 'maxsnack' | 'instructed';
export type TransitionCloseHandler = (event: React.SyntheticEvent<any> | null, reason: CloseReason, key: SnackbarKey) => void;
export type TransitionEnterHandler = (node: HTMLElement, isAppearing: boolean, key: SnackbarKey) => void;
export type TransitionHandler = (node: HTMLElement, key: SnackbarKey) => void;
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ export const originKeyExtractor = anchor => `${capitalise(anchor.vertical)}${cap
export const REASONS = {
CLICKAWAY: 'clickaway',
MAXSNACK: 'maxsnack',
INSTRUCTED: 'instructed',
};

0 comments on commit 20327b5

Please sign in to comment.