Skip to content

Commit

Permalink
fix: fix @material/mwc-dialog closes unexpectedly for all Enter keys
Browse files Browse the repository at this point in the history
  • Loading branch information
motss committed Nov 20, 2021
1 parent a0b49b9 commit 3951f86
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/date-picker-dialog/date-picker-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,3 @@ export class DatePickerDialog extends DatePickerMixin(DatePickerMinMaxMixin(Root
this.value = undefined;
}
}

// FIXME: Do not close dialog when enter/ space or select new year
7 changes: 7 additions & 0 deletions src/month-calendar/month-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ export class MonthCalendar extends RootElement implements MonthCalendarPropertie
const type = event.type as 'click' | 'keydown' | 'keyup';

if (type === 'keydown') {
/**
* NOTE: `@material/mwc-dialog` captures Enter keyboard event then closes the dialog.
* This is not what `month-calendar` expects so here stops all event propagation immediately for
* all key events.
*/
event.stopImmediatePropagation();

const isConfirmKey = confirmKeySet.has(key as InferredFromSet<typeof confirmKeySet>);

if (
Expand Down
9 changes: 8 additions & 1 deletion src/year-grid/year-grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,15 @@ export class YearGrid extends RootElement implements YearGridProperties {

#updateYear = (event: KeyboardEvent): void => {
if (event.type === 'keydown') {
/**
* NOTE: `@material/mwc-dialog` captures Enter keyboard event then closes the dialog.
* This is not what `year-grid` expects so here stops all event propagation immediately for
* all key events.
*/
event.stopImmediatePropagation();

const key =
event.key as InferredFromSet<typeof navigationKeySetGrid>;
event.key as InferredFromSet<typeof navigationKeySetGrid>;

if (!navigationKeySetGrid.has(key)) return;

Expand Down

0 comments on commit 3951f86

Please sign in to comment.