Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
fix(snackbar): Stop queued data from modifying current data (#1084)
Browse files Browse the repository at this point in the history
Fixes #1083
  • Loading branch information
dpraul authored and acdvorak committed Aug 8, 2017
1 parent edfdbe6 commit eb35255
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
26 changes: 13 additions & 13 deletions packages/mdc-snackbar/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,28 @@ export default class MDCSnackbarFoundation extends MDCFoundation {
}

show(data) {
clearTimeout(this.timeoutId_);
this.snackbarData_ = data;
this.firstFocus_ = true;
this.adapter_.registerVisibilityChangeHandler(this.visibilitychangeHandler_);
this.adapter_.registerCapturedBlurHandler(this.blurHandler_);
['touchstart', 'mousedown', 'focus'].forEach((evtType) => {
this.adapter_.registerCapturedInteractionHandler(evtType, this.interactionHandler_);
});

if (!this.snackbarData_) {
if (!data) {
throw new Error(
'Please provide a data object with at least a message to display.');
}
if (!this.snackbarData_.message) {
if (!data.message) {
throw new Error('Please provide a message to be displayed.');
}
if (this.snackbarData_.actionHandler && !this.snackbarData_.actionText) {
if (data.actionHandler && !data.actionText) {
throw new Error('Please provide action text with the handler.');
}
if (this.active) {
this.queue_.push(this.snackbarData_);
this.queue_.push(data);
return;
}
clearTimeout(this.timeoutId_);
this.snackbarData_ = data;
this.firstFocus_ = true;
this.adapter_.registerVisibilityChangeHandler(this.visibilitychangeHandler_);
this.adapter_.registerCapturedBlurHandler(this.blurHandler_);
['touchstart', 'mousedown', 'focus'].forEach((evtType) => {
this.adapter_.registerCapturedInteractionHandler(evtType, this.interactionHandler_);
});

const {ACTIVE, MULTILINE, ACTION_ON_BOTTOM} = cssClasses;

Expand Down
4 changes: 3 additions & 1 deletion test/unit/mdc-snackbar/foundation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ test('#show while snackbar is already showing will queue the data object.', () =
});

td.verify(mockAdapter.setMessageText('Message Deleted'));
td.verify(mockAdapter.setMessageText('Message Archived'));
td.verify(mockAdapter.setMessageText('Message Archived'), {times: 0});
});

test('#show while snackbar is already showing will show after the timeout and transition end', () => {
Expand All @@ -267,6 +267,8 @@ test('#show while snackbar is already showing will show after the timeout and tr
message: 'Message Archived',
});

td.verify(mockAdapter.setMessageText('Message Archived'), {times: 0});

clock.tick(numbers.MESSAGE_TIMEOUT);
transEndHandler();

Expand Down

0 comments on commit eb35255

Please sign in to comment.