23
23
import * as React from 'react' ;
24
24
import classnames from 'classnames' ;
25
25
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 { strings } from '@material/dialog/constants' ;
30
+ import { ponyfill } from '@material/dom' ;
30
31
/* eslint-disable no-unused-vars */
31
32
import DialogContent , { DialogContentProps } from './DialogContent' ;
32
33
import DialogFooter , { DialogFooterProps } from './DialogFooter' ;
@@ -89,7 +90,7 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
89
90
DialogState
90
91
> {
91
92
focusTrap ?: FocusTrap ;
92
- foundation : MDCDialogFoundation ;
93
+ foundation ! : MDCDialogFoundation ;
93
94
dialogElement : React . RefObject < HTMLElement > = React . createRef ( ) ;
94
95
labelledBy ?: string ;
95
96
describedBy ?: string ;
@@ -103,6 +104,8 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
103
104
id : 'mdc-dialog' ,
104
105
open : false ,
105
106
role : 'alertdialog' ,
107
+ escapeKeyAction : strings . CLOSE_ACTION ,
108
+ scrimClickAction : strings . CLOSE_ACTION ,
106
109
} ;
107
110
108
111
state : DialogState = { classList : new Set ( ) } ;
@@ -116,7 +119,7 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
116
119
this . open ( ) ;
117
120
}
118
121
if ( ! autoStackButtons ) {
119
- this . foundation . setAutoStackButtons ( autoStackButtons ) ;
122
+ this . foundation . setAutoStackButtons ( autoStackButtons ! ) ;
120
123
}
121
124
122
125
if ( typeof escapeKeyAction === 'string' ) { // set even if empty string
@@ -136,15 +139,15 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
136
139
const { open, autoStackButtons, escapeKeyAction, scrimClickAction} = this . props ;
137
140
138
141
if ( prevProps . autoStackButtons !== autoStackButtons ) {
139
- this . foundation . setAutoStackButtons ( autoStackButtons ) ;
142
+ this . foundation . setAutoStackButtons ( autoStackButtons ! ) ;
140
143
}
141
144
142
145
if ( prevProps . escapeKeyAction !== escapeKeyAction ) {
143
- this . foundation . setEscapeKeyAction ( escapeKeyAction ) ;
146
+ this . foundation . setEscapeKeyAction ( escapeKeyAction ! ) ;
144
147
}
145
148
146
149
if ( prevProps . scrimClickAction !== scrimClickAction ) {
147
- this . foundation . setScrimClickAction ( scrimClickAction ) ;
150
+ this . foundation . setScrimClickAction ( scrimClickAction ! ) ;
148
151
}
149
152
150
153
if ( prevProps . open !== open ) {
@@ -181,13 +184,12 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
181
184
} ;
182
185
183
186
private initializeFocusTrap = ( ) : void => {
184
- this . focusTrap = this . props . children && util . createFocusTrapInstance ( this . dialogElement . current ) ;
187
+ this . focusTrap = this . props . children && createFocusTrapInstance ( this . dialogElement . current ! ) ;
185
188
} ;
186
189
187
- get adapter ( ) : Partial < MDCDialogAdapter > {
190
+ get adapter ( ) : MDCDialogAdapter {
188
191
const strings = MDCDialogFoundation . strings ;
189
192
const { closest, matches} = ponyfill ;
190
- const { isScrollable, areTopsMisaligned} = util ;
191
193
return {
192
194
addClass : ( className : string ) => {
193
195
const { classList} = this . state ;
@@ -258,8 +260,8 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
258
260
} ;
259
261
260
262
handleInteraction = ( e : React . MouseEvent < HTMLElement > | React . KeyboardEvent < HTMLElement > ) : void =>
261
- this . foundation . handleInteraction ( e ) ;
262
- handleDocumentKeyDown = ( e : Event ) : void =>
263
+ this . foundation . handleInteraction ( e . nativeEvent ) ;
264
+ handleDocumentKeyDown = ( e : KeyboardEvent ) : void =>
263
265
this . foundation . handleDocumentKeydown ( e ) ;
264
266
handleLayout = ( ) : void => this . foundation . layout ( ) ;
265
267
0 commit comments