Skip to content

Commit

Permalink
Added ability to lock an item from dismissal via the locked flag
Browse files Browse the repository at this point in the history
handleDismissOldest will now call items onClose
  • Loading branch information
butchmarshall committed Feb 7, 2019
1 parent 2c4281d commit 43923bf
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/SnackbarProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,28 @@ class SnackbarProvider extends Component {
* Hide oldest snackbar on the screen because there exists a new one which we have to display.
*/
handleDismissOldest = () => {
let popped = false;

this.setState(({ snacks }) => ({
snacks: snacks
.filter(item => item.open === true)
.map((item, i) => (i === 0 ? { ...item, open: false } : { ...item })),
.map((item, i) => {
if (!popped && !item.locked) {
popped = true;
if (item.onClose) {
item.onClose(null, "maxsnack", item.key);
}

return {
...item,
open: false,
};
}

return {
...item,
};
}),
}));
};

Expand Down

0 comments on commit 43923bf

Please sign in to comment.