You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -155,90 +155,134 @@ When the modal is mounted, you'll notice the following:
155
155
- Your content is horizontally centered. You can also vertically center it, if you wish.
156
156
- The modal is appended to `document.body`, not inserted directly into the HTML source order, as you might assume; but it should still update correctly. (This makes positioning easier (no weird nested z-index troubles).)
Any `data-*` or `aria-*` props that you provide will be passed directly to the modal's container `<div>`.
161
188
162
-
### onExit
163
-
164
-
Type: `Function`
165
-
166
-
This function handles the state change of *exiting* (or deactivating) the modal.
167
-
It will be invoked when the user clicks outside the modal (if `underlayClickExits={true}`, as is the default) or hits Escape (if `escapeExits={true}`, as is the default), and it receives the event that triggered it as its only argument.
189
+
### alert
168
190
169
-
Maybe it's just a wrapper around `setState()`; or maybe you use some more involved Flux-inspired state management — whatever the case, this module leaves the state management up to *you* instead of making assumptions. That also makes it easier to create your own "close modal" buttons; because you have the function that closes the modal right there, written by you, at your disposal.
191
+
_Type_: `Boolean`
170
192
171
-
You may omit this prop if you don't want clicks outside the modal or Escape to close it, so don't want to provide a function.
193
+
If `true`, the modal will receive a `role` of `alertdialog`, instead of its default `dialog`. The `alertdialog` role should only be used when an alert, error, or warning occurs ([more info](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_alertdialog_role)).
172
194
173
195
### applicationNode
174
196
175
-
Type: `DOM Node`
197
+
_Type_: `DOM Node`
176
198
177
199
Provide your main application node here (which the modal should render outside of), and when the modal is open this application node will receive the attribute `aria-hidden="true"`. This [can help screen readers understand what's going on](https://www.w3.org/WAI/GL/wiki/Using_ARIA_role%3Ddialog_to_implement_a_modal_dialog_box#Description).
178
200
179
201
This module can't guess your application node, so you have to provide this prop to get the full accessibility benefit.
180
202
181
-
### getApplicationNode
182
-
183
-
Type: `Function`
184
-
185
-
Same as `applicationNode`, but a function that returns the node instead of the node itself. This can be useful or necessary in a variety of situations, one of which is server-side React rendering. The function will not be called until after the component mounts, so it is safe to use browser globals and refer to DOM nodes within it (e.g. `document.getElementById(..)`), without ruining your server-side rendering.
186
-
187
-
### alert
188
-
189
-
Type: `Boolean`
190
-
191
-
If `true`, the modal will receive a `role` of `alertdialog`, instead of its default `dialog`. The `alertdialog` role should only be used when an alert, error, or warning occurs ([more info](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_alertdialog_role)).
192
-
193
-
### includeDefaultStyles
194
-
195
-
Type: `Boolean`, Default: `true`
196
-
197
-
By default, styles are applied inline to the dialog and underlay portions of the component. However, you can disable all inline styles by setting `includeDefaultStyles` to `false`. If set, *you must specify all styles externally*, including positioning. This is helpful if your project uses external CSS assets.
198
-
199
-
*Note:*`underlayStyle` and `dialogStyle` can still be set inline, but these will be the only styles applied.
200
-
201
203
### dialogClass
202
204
203
-
Type: `String`
205
+
_Type_: `String`
204
206
205
207
Apply a class to the dialog in order to custom-style it.
206
208
207
209
Be aware that, *by default*, this module does apply various inline styles to the dialog element in order position it. To disable *all inline styles*, see `includeDefaultStyles`.
Choose your own id attribute for the dialog element.
214
218
215
219
### dialogStyle
216
220
217
-
Type: `Object`
221
+
_Type_: `Object`
218
222
219
223
Customize properties of the `style` prop that is passed to the dialog.
220
224
225
+
### escapeExits
226
+
227
+
_Type_: `Boolean`
228
+
229
+
_Default_: `true`
230
+
231
+
By default, the Escape key exits the modal. Pass `false`, and it won't.
232
+
221
233
### focusDialog
222
234
223
-
Type: `Boolean`
235
+
_Type_: `Boolean`
224
236
225
237
By default, when the modal activates its first focusable child will receive focus.
226
238
However, if `focusDialog` is `true`, the dialog itself will receive initial focus —
227
239
and that focus will be hidden. (This is essentially what Bootstrap does with their modal.)
228
240
229
241
See the example below.
230
242
243
+
### focusTrapOptions
244
+
245
+
_Type_: `Object`
246
+
247
+
Customize properties of the `focusTrapOptions` prop that is passed to the modal dialog's [focus trap](https://github.com/davidtheclark/focus-trap).
248
+
For example, you can use this prop if you need better control of where focus is returned.
249
+
250
+
### focusTrapPaused
251
+
252
+
_Type_: `Boolean`
253
+
254
+
If `true`, the modal dialog's [focus trap](https://github.com/davidtheclark/focus-trap) will be paused.
255
+
256
+
You won't typically need to use this prop.
257
+
It used to be that the typical reason for pausing a focus trap was to enable *nested* focus traps; but as of [focus-trap v4](https://github.com/davidtheclark/focus-trap/blob/master/CHANGELOG.md#400), the pausing and unpausing of hierachical traps is handled automatically.
258
+
259
+
### getApplicationNode
260
+
261
+
_Type_: `() => void`
262
+
263
+
Same as `applicationNode`, but a function that returns the node instead of the node itself. This can be useful or necessary in a variety of situations, one of which is server-side React rendering. The function will not be called until after the component mounts, so it is safe to use browser globals and refer to DOM nodes within it (e.g. `document.getElementById(..)`), without ruining your server-side rendering.
264
+
265
+
### includeDefaultStyles
266
+
267
+
_Type_: `Boolean`
268
+
269
+
_Default_: `true`
270
+
271
+
By default, styles are applied inline to the dialog and underlay portions of the component. However, you can disable all inline styles by setting `includeDefaultStyles` to `false`. If set, *you must specify all styles externally*, including positioning. This is helpful if your project uses external CSS assets.
272
+
273
+
*Note:*`underlayStyle` and `dialogStyle` can still be set inline, but these will be the only styles applied.
274
+
231
275
### initialFocus
232
276
233
-
Type: `String`
277
+
_Type_: `String`
234
278
235
279
By default, when the modal activates its first focusable child will receive focus. If, instead, you want to *identify a specific element that should receive initial focus*, pass a *selector string* to this prop. (That selector is passed to `document.querySelector()` to find the DOM node.)
236
280
237
281
Demo example 3 and an additional example below illustrate a good method if you want no initial visible focus. (Add `tabIndex='0'` to the modal's content and give it `outline: 0;`.)
238
282
239
283
### mounted
240
284
241
-
Type: `Boolean`
285
+
_Type_: `Boolean`
242
286
243
287
By default, the modal is active when mounted, deactivated when unmounted.
244
288
However, you can also control its active/inactive state by changing its `mounted` property instead.
@@ -279,94 +323,88 @@ var MyComponentTakeTwo = React.createClass({
279
323
280
324
### onEnter
281
325
282
-
Type: `Function`
326
+
_Type_: `() => void`
283
327
284
328
This function is called in the modal's `componentDidMount()` lifecycle method.
285
329
You can use it to do whatever diverse and sundry things you feel like doing after the modal activates.
286
330
287
331
Demo Five, for example, uses it to modify class names and enable some CSS transitions.
288
332
333
+
### onExit
334
+
335
+
_Type_: `(event) => void`
336
+
337
+
This function handles the state change of *exiting* (or deactivating) the modal.
338
+
It will be invoked when the user clicks outside the modal (if `underlayClickExits={true}`, as is the default) or hits Escape (if `escapeExits={true}`, as is the default), and it receives the event that triggered it as its only argument.
339
+
340
+
Maybe it's just a wrapper around `setState()`; or maybe you use some more involved Flux-inspired state management — whatever the case, this module leaves the state management up to *you* instead of making assumptions. That also makes it easier to create your own "close modal" buttons; because you have the function that closes the modal right there, written by you, at your disposal.
341
+
342
+
You may omit this prop if you don't want clicks outside the modal or Escape to close it, so don't want to provide a function.
343
+
344
+
### scrollDisabled
345
+
346
+
_Type_: `Boolean`
347
+
348
+
_Default_: `true`
349
+
350
+
If `true`, the modal dialog will prevent any scrolling behind the modal window.
351
+
289
352
### titleId
290
353
291
-
Type: `string`
354
+
_Type_: `String`
292
355
293
356
The id of the element that should be used as the modal's accessible title. This value is passed to the modal's `aria-labelledby` attribute.
294
357
295
358
You must use either `titleId` or `titleText`, but not both.
296
359
297
360
### titleText
298
361
299
-
Type: `string`
362
+
_Type_: `String`
300
363
301
364
A string to use as the modal's accessible title. This value is passed to the modal's `aria-label` attribute.
302
365
303
366
You must use either `titleId` or `titleText`, but not both.
304
367
305
-
306
-
### underlayStyle
307
-
308
-
Type: `object`
309
-
310
-
Customize properties of the `style` prop that is passed to the underlay.
311
-
312
-
**The best way to add some vertical displacement to the dialog is to add top & bottom padding to the underlay**. This is illustrated in the demo examples.
313
-
314
368
### underlayClass
315
369
316
-
Type: `string`
370
+
_Type_: `String`
317
371
318
372
Apply a class to the underlay in order to custom-style it.
319
373
320
374
This module does apply various inline styles, though, so be aware that overriding some styles might be difficult. If, for example, you want to change the underlay's color, you should probably use the `underlayColor` prop instead of a class. If you would rather control *all CSS*, see `includeDefaultStyles`.
321
375
322
376
### underlayClickExits
323
377
324
-
Type: `boolean`, Default: `true`
325
-
326
-
By default, a click on the underlay will exit the modal. Pass `false`, and clicking on the underlay will do nothing.
327
-
328
-
### escapeExits
378
+
_Type_: `Boolean`
329
379
330
-
Type: `boolean`, Default: `true`
380
+
_Default_: `true`
331
381
332
-
By default, the Escape key exits the modal. Pass `false`, and it won't.
382
+
By default, a click on the underlay will exit the modal. Pass `false`, and clicking on the underlay will do nothing.
333
383
334
384
### underlayColor
335
385
336
-
Type: `string` (color value) or `false`, Default: `rgba(0,0,0,0.5)`
386
+
_Type_: `String` (color value) or `false`
387
+
388
+
_Default_: `rgba(0,0,0,0.5)`
337
389
338
390
If you want to change the underlay's color, you can do that with this prop.
339
391
340
392
If `false`, no background color will be applied with inline styles.
341
393
Presumably you will apply then yourself via an `underlayClass`.
342
394
343
-
### verticallyCenter
344
-
345
-
Type: `boolean`
346
-
347
-
If `true`, the modal's contents will be vertically (as well as horizontally) centered.
348
-
349
-
### focusTrapPaused
350
-
351
-
Type: `boolean`
352
-
353
-
If `true`, the modal dialog's [focus trap](https://github.com/davidtheclark/focus-trap) will be paused.
354
-
355
-
You won't typically need to use this prop.
356
-
It used to be that the typical reason for pausing a focus trap was to enable *nested* focus traps; but as of [focus-trap v4](https://github.com/davidtheclark/focus-trap/blob/master/CHANGELOG.md#400), the pausing and unpausing of hierachical traps is handled automatically.
395
+
### underlayStyle
357
396
358
-
### focusTrapOptions
397
+
_Type_: `Object`
359
398
360
-
Type: `object`
399
+
Customize properties of the `style` prop that is passed to the underlay.
361
400
362
-
Customize properties of the `focusTrapOptions` prop that is passed to the modal dialog's [focus trap](https://github.com/davidtheclark/focus-trap).
363
-
For example, you can use this prop if you need better control of where focus is returned.
401
+
**The best way to add some vertical displacement to the dialog is to add top & bottom padding to the underlay**. This is illustrated in the demo examples.
364
402
365
-
### scrollDisabled
403
+
### verticallyCenter
366
404
367
-
Type: `boolean`, Default: `true`
405
+
_Type_: `Boolean`
368
406
369
-
If `true`, the modal dialog will prevent any scrolling behind the modal window.
407
+
If `true`, the modal's contents will be vertically (as well as horizontally) centered.
0 commit comments