Repository navigation
Description
This issue is to track the implementation of the new Modal component in the ui-components library. The issue is actually created after the fact, and the PR for the implementation is #51070.
I'm using this issue to document the technical design and decision as I'm reviewing the PR.
Current specs
Behaviors
- Closes on Escape press
Styling
- Has 30px top and bottom margin on large screen size (
min-width: 768px) - Has 10px margin on all sides on smaller screen size
- The height grows with the content
- The width follows the Bootstrap sizes (ref):
lgorlarge: 900px widemd: 600px widesmorsmall: 300px wide
- Has a 1px solid border on all sides (set by the
modal-contentclass) - Header:
- The text is centered
margin: 0line-height: 1.42857143- Has a 1px solid bottom border
- Body:
- The content is centered
- Footer:
- Has a 15px padding on all sides and a 1px solid top border
- The content is centered
- When the modal opens, a backdrop with
background-color: #000andopacity: 0.5appears and sits on top of the background content - Has default and danger variants
- Default:
- The border color is
--secondary-color - The background color of the header, body, and footer is
--secondary-background - The color of the text content is
--secondary-color - The variant of the primary and secondary buttons is
primary
- The border color is
- Danger:
- The border color is
--secondary-color - The background color of the header is
--danger-background- Note that this is only for some danger modals (
reset-modalis an example), though in the new Modal version we should apply this styling to all danger modals for consistency
- Note that this is only for some danger modals (
- The color of the text content is
--danger-color - The primary button has the
dangervariant - The secondary button is optional, and has the
primaryvariant - If both the primary and secondary buttons are present, display the secondary button first then primary (see Inconsistent button order in modals #52615)
- The border color is
- Default:
Modal variants
| Variant | Theme | Screenshot |
|---|---|---|
| Default | Light | ![]() |
| Default | Dark | ![]() |
| Danger | Light | ![]() |
| Danger | Dark | ![]() |
Modal position on different screen sizes
| Screen size | Screenshot |
|---|---|
| Width being 768px or above | ![]() |
| Width being less than 768px | ![]() |
Components
ModalModal.HeaderModal.TitleModal.BodyModal.Footer
Props interface
This section contains props that are used in our codebase. The information of the props is copied from https://react-bootstrap-v3.netlify.app/components/modal/#modals-props.
Modal
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
animation |
boolean | true |
Open and close the Modal with a slide and fade animation. | |
backdrop |
'static' | true | false |
Include a backdrop component. Specify 'static' for a backdrop that doesn't trigger an onHide when clicked. |
||
bsSize |
'lg' | 'large' | 'sm' | 'small' |
Component size variations. | ||
dialogClassName |
A css class to apply to the Modal dialog DOM node. | |||
keyboard |
boolean | Close the modal when escape key is pressed. | ||
onExited |
function | Callback fired after the Modal finishes transitioning out. | ||
onHide |
function | A callback fired when the header close button or non-static backdrop is clicked. Required if either are specified. | ||
show |
boolean | When true the modal will show itself. |
Notes:
bsSizehas the follow values (ref):lgorlarge: 900px widemd: 600px widesmorsmall: 300px wide
SignoutModalpassesonClosetoModal, but this prop appears to be ineffective/redundant asreact-bootstrapdoesn't have this prop listed in the prop table
onClose={handleModalHide} ExamResultsModalpassessizetoModal, but this prop appears to be ineffective/redundant asreact-bootstrapdoesn't have this prop listed in the prop table
size='lg' ProjectModalpassessizetoModal, but this prop appears to be ineffective/redundant asreact-bootstrapdoesn't have this prop listed in the prop table
size='lg' StagingWarningModalpassesonClosetoModal, but this prop appears to be ineffective/redundant asreact-bootstrapdoesn't have this prop listed in the prop table
onClose={handleModalHide} CompletionModalpassesonKeydowntoModal. This prop isn't listed in thereact-bootstrap's prop table but appears to be needed / in effect
onKeyDown={isOpen ? this.handleKeypress : noop}
Modal.Header
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
closeButton |
boolean | false |
Specify whether the component should contain a close button. |
Modal.Title
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
children |
ReactNode |
Title of the modal. |
Modal.Body
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
children |
ReactNode |
Content of the modal. |
Modal.Footer
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
children |
ReactNode |
Footer of the modal, usually is a button or a group of buttons. |
Implementation plan
Dependencies
We will use the Dialog component of radix-ui.
Components and sub-components
Sub-components:
Close: The "x" buttonTrigger: The button that triggers/opens the modal- We don't need this at the moment since we've been triggering dialogs via redux
Description: The body of the modalModalLayer: ThePortalthat the modal is rendered in- Note: The portal must be rendered under an element with the class
light-paletteordark-palettein order to be themed properly
- Note: The portal must be rendered under an element with the class
ModalTitle: The title of the modalModalHeader: The header of the modal. This section includesModalTitleandCloseModalFooter: The footer of the modal. This section includes buttons for the actions
We will expose a single Modal component, which encapsulates sub-components.
Public components are:
ModalModal.HeaderModal.Title- We are exporting this component to ease the migration process. But in the future, I think we could turn this into a
titleprop ofModal.Headerand only useModal.Headerto compose modal
- We are exporting this component to ease the migration process. But in the future, I think we could turn this into a
Modal.BodyModal.Footer
Props interface
Modal
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
size |
'large' | 'medium' |
'medium' | Component size variations. | |
variant |
'default' | 'danger' |
Component style variations. | ||
onExited |
function | A callback fired after the Modal finishes transitioning out. | ||
open |
boolean | When true the modal will show itself. |
||
onClose |
function | A callback responsible for the close action. |
Notes:
- We should build the Bootstrap's
animationandbackdropbehaviors into the Modal component, so that the modal display is consistent - We should build the Bootstrap's
keyboardbehavior into the Modal component to ensure the component is accessible
Modal.Header
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
children |
ReactNode |
Content of the header, usually the modal title, rendered by the Modal.Title component. |
||
showCloseButton |
boolean |
true |
Whether the header should contain a close button. |
Note: We are currently using Modal.Header with closeButton={true} in all modals, except for donation-modal. Setting the default value to true would improve the DX a little as we don't have to specify this prop in most cases.
Modal.Title
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
children |
ReactNode |
Title of the modal. |
Modal.Body
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
children |
ReactNode |
Content of the modal. |
Modal.Footer
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
children |
ReactNode |
Footer of the modal, usually is a button or a group of buttons. |
Usage example
const MyModal = () => (
<Modal show={show}>
<Modal.Header>
<Modal.Title>Modal title</Modal.Title>
</Modal.Header>
<Modal.Body>
// content
</Modal.Body>
<Modal.Footer>
<Button>Button one</Button>
<Button>Button two<Button>
</Modal.Footer>
</Modal>
)References
- Bootstrap Modal documentation: https://react-bootstrap-v3.netlify.app/components/modal/
- Bootstrap Modal styling: https://github.com/twbs/bootstrap/blob/f17f882df292b29323f1e1da515bd16f326cee4a/less/modals.less






Activity