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

fix(dialog): mdc-web v1 upgrade #779

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 64 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@material/card": "^0.41.0",
"@material/checkbox": "^0.41.0",
"@material/chips": "^1.0.0",
"@material/dialog": "^0.43.0",
"@material/dialog": "^1.0.0",
"@material/dom": "^0.41.0",
"@material/drawer": "^1.0.1",
"@material/fab": "^0.41.0",
Expand Down
27 changes: 13 additions & 14 deletions packages/dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import * as React from 'react';
import classnames from 'classnames';

// @ts-ignore no .d.ts file
import {MDCDialogFoundation, MDCDialogAdapter, util} from '@material/dialog/dist/mdc.dialog';
// @ts-ignore no .d.ts file
import {ponyfill} from '@material/dom/dist/mdc.dom';
import {MDCDialogFoundation} from '@material/dialog/foundation';
import {MDCDialogAdapter} from '@material/dialog/adapter';
import {createFocusTrapInstance, isScrollable, areTopsMisaligned} from '@material/dialog/util';
import {ponyfill} from '@material/dom';
/* eslint-disable no-unused-vars */
import DialogContent, {DialogContentProps} from './DialogContent';
import DialogFooter, {DialogFooterProps} from './DialogFooter';
Expand Down Expand Up @@ -89,7 +89,7 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
DialogState
> {
focusTrap?: FocusTrap;
foundation: MDCDialogFoundation;
foundation!: MDCDialogFoundation;
dialogElement: React.RefObject<HTMLElement> = React.createRef();
labelledBy?: string;
describedBy?: string;
Expand All @@ -116,7 +116,7 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
this.open();
}
if (!autoStackButtons) {
this.foundation.setAutoStackButtons(autoStackButtons);
this.foundation.setAutoStackButtons(autoStackButtons!);
}

if (typeof escapeKeyAction === 'string') { // set even if empty string
Expand All @@ -136,15 +136,15 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
const {open, autoStackButtons, escapeKeyAction, scrimClickAction} = this.props;

if (prevProps.autoStackButtons !== autoStackButtons) {
this.foundation.setAutoStackButtons(autoStackButtons);
this.foundation.setAutoStackButtons(autoStackButtons!);
}

if (prevProps.escapeKeyAction !== escapeKeyAction) {
this.foundation.setEscapeKeyAction(escapeKeyAction);
this.foundation.setEscapeKeyAction(escapeKeyAction!);
}

if (prevProps.scrimClickAction !== scrimClickAction) {
this.foundation.setScrimClickAction(scrimClickAction);
this.foundation.setScrimClickAction(scrimClickAction!);
}

if (prevProps.open !== open) {
Expand Down Expand Up @@ -181,13 +181,12 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
};

private initializeFocusTrap = (): void => {
this.focusTrap = this.props.children && util.createFocusTrapInstance(this.dialogElement.current);
this.focusTrap = this.props.children && createFocusTrapInstance(this.dialogElement.current!);
};

get adapter(): Partial<MDCDialogAdapter> {
get adapter(): MDCDialogAdapter {
const strings = MDCDialogFoundation.strings;
const {closest, matches} = ponyfill;
const {isScrollable, areTopsMisaligned} = util;
return {
addClass: (className: string) => {
const {classList} = this.state;
Expand Down Expand Up @@ -258,8 +257,8 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
};

handleInteraction = (e: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>): void =>
this.foundation.handleInteraction(e);
handleDocumentKeyDown = (e: Event): void =>
this.foundation.handleInteraction(e.nativeEvent);
handleDocumentKeyDown = (e: KeyboardEvent): void =>
this.foundation.handleDocumentKeydown(e);
handleLayout = (): void => this.foundation.layout();

Expand Down
4 changes: 2 additions & 2 deletions packages/dialog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"dialog"
],
"dependencies": {
"@material/dialog": "0.43.0",
"@material/dom": "^0.41.0",
"@material/dialog": "1.0.1",
"@material/dom": "^1.0.0",
"@material/react-button": "^0.11.0",
"classnames": "^2.2.6",
"focus-trap": "^4.0.2",
Expand Down
Loading