Skip to content

Commit 76715cd

Browse files
initFabianFabian Buentello
andauthored
Improve Documentation (#104)
* Improve documentation * remove double spaces * combine columns in API table Co-authored-by: Fabian Buentello <[email protected]>
1 parent 3f4542d commit 76715cd

File tree

1 file changed

+116
-78
lines changed

1 file changed

+116
-78
lines changed

README.md

Lines changed: 116 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -155,90 +155,134 @@ When the modal is mounted, you'll notice the following:
155155
- Your content is horizontally centered. You can also vertically center it, if you wish.
156156
- 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).)
157157

158-
## Props
158+
## API
159+
|Name| Type (`Default`) |
160+
|---|---|
161+
| [alert](#alert) | `Boolean` |
162+
| [applicationNode](#applicationNode) | `DOM Node` |
163+
| [dialogClass](#dialogClass) | `String` |
164+
| [dialogId](#dialogId) | `String` (`'react-aria-modal-dialog'`) |
165+
| [dialogStyle](#dialogStyle) | `Object` |
166+
| [escapeExits](#escapeExits) | `Boolean` (`true`) |
167+
| [focusDialog](#focusDialog) | `Boolean` |
168+
| [focusTrapOptions](#focusTrapOptions) | `Object` |
169+
| [focusTrapPaused](#focusTrapPaused) | `Boolean` |
170+
| [getApplicationNode](#getApplicationNode) | `() => void` |
171+
| [includeDefaultStyles](#includeDefaultStyles) | `Boolean` (`true`) |
172+
| [initialFocus](#initialFocus) | `String` |
173+
| [mounted](#mounted) | `Boolean` |
174+
| [onEnter](#onEnter) | `() => void` |
175+
| [onExit](#onExit) | `(event) => void` |
176+
| [scrollDisabled](#scrollDisabled) | `Boolean` (`true`) |
177+
| [titleId](#titleId) | `String` |
178+
| [titleText](#titleText) | `String` |
179+
| [underlayClass](#underlayClass) | `String` |
180+
| [underlayClickExits](#underlayClickExits) | `Boolean` (`true`) |
181+
| [underlayColor](#underlayColor) | `String` (`'rgba(0,0,0,0.5)'`) |
182+
| [underlayStyle](#underlayStyle) | `Object` |
183+
| [verticallyCenter](#verticallyCenter) | `Boolean` |
184+
185+
## Reference API
159186

160187
Any `data-*` or `aria-*` props that you provide will be passed directly to the modal's container `<div>`.
161188

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
168190

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`
170192

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)).
172194

173195
### applicationNode
174196

175-
Type: `DOM Node`
197+
_Type_: `DOM Node`
176198

177199
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).
178200

179201
This module can't guess your application node, so you have to provide this prop to get the full accessibility benefit.
180202

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-
201203
### dialogClass
202204

203-
Type: `String`
205+
_Type_: `String`
204206

205207
Apply a class to the dialog in order to custom-style it.
206208

207209
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`.
208210

209211
### dialogId
210212

211-
Type: `String`, Default: `react-aria-modal-dialog`
213+
_Type_: `String`
214+
215+
_Default_: `react-aria-modal-dialog`
212216

213217
Choose your own id attribute for the dialog element.
214218

215219
### dialogStyle
216220

217-
Type: `Object`
221+
_Type_: `Object`
218222

219223
Customize properties of the `style` prop that is passed to the dialog.
220224

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+
221233
### focusDialog
222234

223-
Type: `Boolean`
235+
_Type_: `Boolean`
224236

225237
By default, when the modal activates its first focusable child will receive focus.
226238
However, if `focusDialog` is `true`, the dialog itself will receive initial focus —
227239
and that focus will be hidden. (This is essentially what Bootstrap does with their modal.)
228240

229241
See the example below.
230242

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+
231275
### initialFocus
232276

233-
Type: `String`
277+
_Type_: `String`
234278

235279
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.)
236280

237281
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;`.)
238282

239283
### mounted
240284

241-
Type: `Boolean`
285+
_Type_: `Boolean`
242286

243287
By default, the modal is active when mounted, deactivated when unmounted.
244288
However, you can also control its active/inactive state by changing its `mounted` property instead.
@@ -279,94 +323,88 @@ var MyComponentTakeTwo = React.createClass({
279323

280324
### onEnter
281325

282-
Type: `Function`
326+
_Type_: `() => void`
283327

284328
This function is called in the modal's `componentDidMount()` lifecycle method.
285329
You can use it to do whatever diverse and sundry things you feel like doing after the modal activates.
286330

287331
Demo Five, for example, uses it to modify class names and enable some CSS transitions.
288332

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+
289352
### titleId
290353

291-
Type: `string`
354+
_Type_: `String`
292355

293356
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.
294357

295358
You must use either `titleId` or `titleText`, but not both.
296359

297360
### titleText
298361

299-
Type: `string`
362+
_Type_: `String`
300363

301364
A string to use as the modal's accessible title. This value is passed to the modal's `aria-label` attribute.
302365

303366
You must use either `titleId` or `titleText`, but not both.
304367

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-
314368
### underlayClass
315369

316-
Type: `string`
370+
_Type_: `String`
317371

318372
Apply a class to the underlay in order to custom-style it.
319373

320374
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`.
321375

322376
### underlayClickExits
323377

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`
329379

330-
Type: `boolean`, Default: `true`
380+
_Default_: `true`
331381

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.
333383

334384
### underlayColor
335385

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)`
337389

338390
If you want to change the underlay's color, you can do that with this prop.
339391

340392
If `false`, no background color will be applied with inline styles.
341393
Presumably you will apply then yourself via an `underlayClass`.
342394

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
357396

358-
### focusTrapOptions
397+
_Type_: `Object`
359398

360-
Type: `object`
399+
Customize properties of the `style` prop that is passed to the underlay.
361400

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.
364402

365-
### scrollDisabled
403+
### verticallyCenter
366404

367-
Type: `boolean`, Default: `true`
405+
_Type_: `Boolean`
368406

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.
370408

371409
## AriaModal.renderTo(HTMLElement | string)
372410

0 commit comments

Comments
 (0)