|
1 | 1 | ### CSS Classes
|
2 | 2 |
|
3 | 3 | Sometimes it may be preferable to use CSS classes rather than inline styles.
|
| 4 | +react-modal can be configured to use CSS classes to style the modal content and |
| 5 | +overlay, as well as the document body and the portal within which the modal is |
| 6 | +mounted. |
4 | 7 |
|
5 |
| -You can use the `className` and `overlayClassName` props to specify a given CSS |
6 |
| -class for each of those. |
| 8 | +#### For the content and overlay |
| 9 | + |
| 10 | +You can use the `className` and `overlayClassName` props to control the CSS |
| 11 | +classes that are applied to the modal content and the overlay, respectively. |
| 12 | +Each of these props may be a single string containing the class name to apply |
| 13 | +to the component. |
| 14 | + |
| 15 | +Alternatively, you may pass an object with the `base`, `afterOpen` and |
| 16 | +`beforeClose` keys, where the value corresponding to each key is a class name. |
| 17 | +The `base` class will always be applied to the component, the `afterOpen` class |
| 18 | +will be applied after the modal has been opened and the `beforeClose` class |
| 19 | +will be applied after the modal has requested to be closed (e.g. when the user |
| 20 | +presses the escape key or clicks on the overlay). |
| 21 | + |
| 22 | +Please note that the `beforeClose` class will have no effect unless the |
| 23 | +`closeTimeoutMS` prop is set to a non-zero value, since otherwise the modal |
| 24 | +will be closed immediately when requested. Thus, if you are using the |
| 25 | +`afterOpen` and `beforeClose` classes to provide transitions, you may want to |
| 26 | +set `closeTimeoutMS` to the length (in milliseconds) of your closing |
| 27 | +transition. |
| 28 | + |
| 29 | +If you specify `className`, the [default content styles](README.md) will not be |
| 30 | +applied. Likewise, if you specify `overlayClassName`, the default overlay |
| 31 | +styles will not be applied. |
| 32 | + |
| 33 | +If no class names are specified for the overlay, the default classes |
| 34 | +`ReactModal__Overlay`, `ReactModal__Overlay--after-open` and |
| 35 | +`ReactModal__Overlay--before-close` will be applied; the default classes for |
| 36 | +the content use the analogous prefix `ReactModal__Content`. Please note that |
| 37 | +any styles applied using these default classes will not override the default |
| 38 | +styles as they would if specified using the `className` or `overlayClassName` |
| 39 | +props. |
| 40 | + |
| 41 | +#### For the document body |
7 | 42 |
|
8 | 43 | You can override the default class that is added to `document.body` when the
|
9 | 44 | modal is open by defining a property `bodyOpenClassName`.
|
10 | 45 |
|
11 |
| -It's required that `bodyOpenClassName` must be `constant string`, otherwise we |
12 |
| -would end up with a complex system to manage which class name should appear or |
13 |
| -be removed from `document.body` from which modal (if using multiple modals |
| 46 | +The `bodyOpenClassName` prop must be a *constant string*; otherwise, we would |
| 47 | +require a complex system to manage which class name should be added to or |
| 48 | +removed from `document.body` from which modal (if using multiple modals |
14 | 49 | simultaneously).
|
15 | 50 |
|
16 | 51 | `bodyOpenClassName` can support adding multiple classes to `document.body` when
|
17 | 52 | the modal is open. Add as many class names as you desire, delineated by spaces.
|
18 | 53 |
|
19 |
| -Note: If you provide those props all default styles will not be applied, leaving |
20 |
| -all styles under control of the CSS class. |
| 54 | +#### For the entire portal |
21 | 55 |
|
22 |
| -The `portalClassName` can also be used however there are no styles by default applied |
| 56 | +To specify a class to be applied to the entire portal, you may use the |
| 57 | +`portalClassName` prop. By default, there are no styles applied to the portal |
| 58 | +itself. |
0 commit comments