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

Commit dc12fac

Browse files
committed
feat(dialog): upgrade mdc-web to v1
1 parent 1ad8cd2 commit dc12fac

File tree

5 files changed

+114
-97
lines changed

5 files changed

+114
-97
lines changed

package-lock.json

Lines changed: 64 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@material/card": "^0.41.0",
6767
"@material/checkbox": "^0.41.0",
6868
"@material/chips": "^1.0.0",
69-
"@material/dialog": "^0.43.0",
69+
"@material/dialog": "^1.0.0",
7070
"@material/dom": "^0.41.0",
7171
"@material/drawer": "^1.0.1",
7272
"@material/fab": "^0.41.0",

packages/dialog/index.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import * as React from 'react';
2424
import classnames from 'classnames';
2525

26-
// @ts-ignore no .d.ts file
27-
import {MDCDialogFoundation, MDCDialogAdapter, util} from '@material/dialog/dist/mdc.dialog';
28-
// @ts-ignore no .d.ts file
29-
import {ponyfill} from '@material/dom/dist/mdc.dom';
26+
import {MDCDialogFoundation} from '@material/dialog/foundation';
27+
import {MDCDialogAdapter} from '@material/dialog/adapter';
28+
import {createFocusTrapInstance, isScrollable, areTopsMisaligned} from '@material/dialog/util';
29+
import {ponyfill} from '@material/dom';
3030
/* eslint-disable no-unused-vars */
3131
import DialogContent, {DialogContentProps} from './DialogContent';
3232
import DialogFooter, {DialogFooterProps} from './DialogFooter';
@@ -89,7 +89,7 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
8989
DialogState
9090
> {
9191
focusTrap?: FocusTrap;
92-
foundation: MDCDialogFoundation;
92+
foundation!: MDCDialogFoundation;
9393
dialogElement: React.RefObject<HTMLElement> = React.createRef();
9494
labelledBy?: string;
9595
describedBy?: string;
@@ -116,7 +116,7 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
116116
this.open();
117117
}
118118
if (!autoStackButtons) {
119-
this.foundation.setAutoStackButtons(autoStackButtons);
119+
this.foundation.setAutoStackButtons(autoStackButtons!);
120120
}
121121

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

138138
if (prevProps.autoStackButtons !== autoStackButtons) {
139-
this.foundation.setAutoStackButtons(autoStackButtons);
139+
this.foundation.setAutoStackButtons(autoStackButtons!);
140140
}
141141

142142
if (prevProps.escapeKeyAction !== escapeKeyAction) {
143-
this.foundation.setEscapeKeyAction(escapeKeyAction);
143+
this.foundation.setEscapeKeyAction(escapeKeyAction!);
144144
}
145145

146146
if (prevProps.scrimClickAction !== scrimClickAction) {
147-
this.foundation.setScrimClickAction(scrimClickAction);
147+
this.foundation.setScrimClickAction(scrimClickAction!);
148148
}
149149

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

183183
private initializeFocusTrap = (): void => {
184-
this.focusTrap = this.props.children && util.createFocusTrapInstance(this.dialogElement.current);
184+
this.focusTrap = this.props.children && createFocusTrapInstance(this.dialogElement.current!);
185185
};
186186

187-
get adapter(): Partial<MDCDialogAdapter> {
187+
get adapter(): MDCDialogAdapter {
188188
const strings = MDCDialogFoundation.strings;
189189
const {closest, matches} = ponyfill;
190-
const {isScrollable, areTopsMisaligned} = util;
191190
return {
192191
addClass: (className: string) => {
193192
const {classList} = this.state;
@@ -258,8 +257,8 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
258257
};
259258

260259
handleInteraction = (e: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>): void =>
261-
this.foundation.handleInteraction(e);
262-
handleDocumentKeyDown = (e: Event): void =>
260+
this.foundation.handleInteraction(e.nativeEvent);
261+
handleDocumentKeyDown = (e: KeyboardEvent): void =>
263262
this.foundation.handleDocumentKeydown(e);
264263
handleLayout = (): void => this.foundation.layout();
265264

packages/dialog/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"dialog"
1212
],
1313
"dependencies": {
14-
"@material/dialog": "0.43.0",
15-
"@material/dom": "^0.41.0",
14+
"@material/dialog": "1.0.1",
15+
"@material/dom": "^1.0.0",
1616
"@material/react-button": "^0.11.0",
1717
"classnames": "^2.2.6",
1818
"focus-trap": "^4.0.2",

0 commit comments

Comments
 (0)