@@ -7,6 +7,7 @@ import { PropsTable, Playground } from 'docz'
77import { BlockList , PropDesc , getSystemPropDesc } from ' @docs/utils'
88import {
99 Modal ,
10+ ModalCloseButton ,
1011 ModalBody ,
1112 ModalContent ,
1213 ModalDialog ,
@@ -25,6 +26,7 @@ Below is a static modal example (meaning its `position` and `display` have been
2526<Playground >
2627 <ModalDialogExample >
2728 <ModalContent >
29+ <ModalCloseButton />
2830 <ModalHeader >
2931 <Typography variant = " h5" m = { 0 } >
3032 Modal title
@@ -53,6 +55,7 @@ You can toggle a modal from a `Button` using the `Toggler`.
5355 <Modal opened = { toggled } onClose = { () => onToggle (false )} >
5456 <ModalDialog >
5557 <ModalContent >
58+ <ModalCloseButton />
5659 <ModalHeader >
5760 <Typography variant = " h5" m = { 0 } >
5861 Modal title
@@ -73,6 +76,57 @@ You can toggle a modal from a `Button` using the `Toggler`.
7376 </Toggler >
7477</Playground >
7578
79+ ## Initial focus
80+
81+ Modal will focus the first focusable node by default, but you can specify a custom one using ` initialFocusRef ` .
82+
83+ In this example, the close button in ` ModalFooter ` will be focused instead of the ` ModalCloseButton ` .
84+
85+ <Playground >
86+ { () => {
87+ class App extends React .Component {
88+ constructor (props ) {
89+ super (props )
90+ this .buttonRef = React .createRef ()
91+ this .state = { showDialog: false }
92+ this .open = () => this .setState ({ showDialog: true })
93+ this .close = () => this .setState ({ showDialog: false })
94+ }
95+
96+ render() {
97+ return (
98+ <div >
99+ <Button variant = " primary" onClick = { this .open } >
100+ Open modal
101+ </Button >
102+ <Modal opened = { this .state .showDialog } initialFocusRef = { this .buttonRef } onClose = { this .close } >
103+ <ModalDialog >
104+ <ModalContent >
105+ <ModalCloseButton />
106+ <ModalHeader >
107+ <Typography variant = " h5" m = { 0 } >
108+ Modal title
109+ </Typography >
110+ </ModalHeader >
111+ <ModalBody >Modal body</ModalBody >
112+ <ModalFooter >
113+ <Button variant = " primary" >Save changes</Button >
114+ <Button ref = { this .buttonRef } variant = " secondary" onClick = { this .close } >
115+ Close
116+ </Button >
117+ </ModalFooter >
118+ </ModalContent >
119+ </ModalDialog >
120+ </Modal >
121+ </div >
122+ )
123+ }
124+ }
125+
126+ return <App />
127+ }}
128+ </Playground >
129+
76130## Scrolling long content
77131
78132When modals become too long for the userβs viewport or device, they scroll independent of the page itself. Try the demo below to see what we mean.
@@ -157,53 +211,6 @@ When modals become too long for the userβs viewport or device, they scroll ind
157211 </Toggler >
158212</Playground >
159213
160- ## Persistent
161-
162- Set ` persistent ` to ` true ` to keep the modal mounted even if closed.
163-
164- <Playground >
165- <BlockList >
166- <Toggler >
167- { ({ toggled , onToggle }) => (
168- <div >
169- <Button variant = " primary" onClick = { () => onToggle (true )} >
170- Open non-persistent
171- </Button >
172- <Modal persistent = { false } opened = { toggled } onClose = { () => onToggle (false )} >
173- <ModalDialog >
174- <ModalContent >
175- <ModalBody >
176- Counter is resetted each time you open it <br />
177- <Counter />
178- </ModalBody >
179- </ModalContent >
180- </ModalDialog >
181- </Modal >
182- </div >
183- )}
184- </Toggler >
185- <Toggler >
186- { ({ toggled , onToggle }) => (
187- <div >
188- <Button variant = " primary" onClick = { () => onToggle (true )} >
189- Open persistent modal (default)
190- </Button >
191- <Modal opened = { toggled } onClose = { () => onToggle (false )} >
192- <ModalDialog >
193- <ModalContent >
194- <ModalBody >
195- Counter continue in background <br />
196- <Counter />
197- </ModalBody >
198- </ModalContent >
199- </ModalDialog >
200- </Modal >
201- </div >
202- )}
203- </Toggler >
204- </BlockList >
205- </Playground >
206-
207214
208215## API
209216
@@ -214,7 +221,7 @@ Set `persistent` to `true` to keep the modal mounted even if closed.
214221 children: PropDesc .node ,
215222 onClose: PropDesc .func ,
216223 opened: PropDesc .bool ,
217- persistent : PropDesc .bool . defaultTo ( true ). desc ( ' Set "persistent" to `true` to keep modal mounted when closed ' ) ,
224+ initialFocusRef : PropDesc .object ,
218225 ... getSystemPropDesc (Modal ),
219226 })}
220227/>
@@ -264,3 +271,13 @@ Set `persistent` to `true` to keep the modal mounted even if closed.
264271 ... getSystemPropDesc (ModalHeader ),
265272 })}
266273/>
274+
275+ ### ModalCloseButton
276+
277+ <PropsTable
278+ of = { PropDesc ({
279+ children: PropDesc .node ,
280+ ... getSystemPropDesc (ModalCloseButton ),
281+ })}
282+ />
283+
0 commit comments