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

Commit eb35255

Browse files
dpraulacdvorak
authored andcommitted
fix(snackbar): Stop queued data from modifying current data (#1084)
Fixes #1083
1 parent edfdbe6 commit eb35255

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

packages/mdc-snackbar/foundation.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,28 @@ export default class MDCSnackbarFoundation extends MDCFoundation {
119119
}
120120

121121
show(data) {
122-
clearTimeout(this.timeoutId_);
123-
this.snackbarData_ = data;
124-
this.firstFocus_ = true;
125-
this.adapter_.registerVisibilityChangeHandler(this.visibilitychangeHandler_);
126-
this.adapter_.registerCapturedBlurHandler(this.blurHandler_);
127-
['touchstart', 'mousedown', 'focus'].forEach((evtType) => {
128-
this.adapter_.registerCapturedInteractionHandler(evtType, this.interactionHandler_);
129-
});
130-
131-
if (!this.snackbarData_) {
122+
if (!data) {
132123
throw new Error(
133124
'Please provide a data object with at least a message to display.');
134125
}
135-
if (!this.snackbarData_.message) {
126+
if (!data.message) {
136127
throw new Error('Please provide a message to be displayed.');
137128
}
138-
if (this.snackbarData_.actionHandler && !this.snackbarData_.actionText) {
129+
if (data.actionHandler && !data.actionText) {
139130
throw new Error('Please provide action text with the handler.');
140131
}
141132
if (this.active) {
142-
this.queue_.push(this.snackbarData_);
133+
this.queue_.push(data);
134+
return;
143135
}
136+
clearTimeout(this.timeoutId_);
137+
this.snackbarData_ = data;
138+
this.firstFocus_ = true;
139+
this.adapter_.registerVisibilityChangeHandler(this.visibilitychangeHandler_);
140+
this.adapter_.registerCapturedBlurHandler(this.blurHandler_);
141+
['touchstart', 'mousedown', 'focus'].forEach((evtType) => {
142+
this.adapter_.registerCapturedInteractionHandler(evtType, this.interactionHandler_);
143+
});
144144

145145
const {ACTIVE, MULTILINE, ACTION_ON_BOTTOM} = cssClasses;
146146

test/unit/mdc-snackbar/foundation.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ test('#show while snackbar is already showing will queue the data object.', () =
244244
});
245245

246246
td.verify(mockAdapter.setMessageText('Message Deleted'));
247-
td.verify(mockAdapter.setMessageText('Message Archived'));
247+
td.verify(mockAdapter.setMessageText('Message Archived'), {times: 0});
248248
});
249249

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

270+
td.verify(mockAdapter.setMessageText('Message Archived'), {times: 0});
271+
270272
clock.tick(numbers.MESSAGE_TIMEOUT);
271273
transEndHandler();
272274

0 commit comments

Comments
 (0)