sui-components
sui-components copied to clipboard
Modal improvements
Is your iteration request related to a problem? Some improvements that I thought
Describe the solution you'd like
API:
Use compound components pattern to allow more flexibility
<Modal isOpen={isOpen} onClose={onClose}>
<ModalHeader>Title</ModalHeader>
<ModalCloseButton />
<ModalContent>
<Lorem count={2} />
</ModalContent>
<ModalFooter>
<Button onClick={onClose}>
Close
</Button>
</ModalFooter>
</Modal>
A Drawer could be created using this API since it's also a modal
Accessibility:
-
ModalContentshould be asectiontag -
ModalContentshould have rolemodaloralertdialog -
ModalContentshould havearia-modal=true - If we want to support older browsers sibling nodes of the modal should have
aria-hidden=true - Focus should be lock inside the modal (see react-focus-lock and its size)
- If
modalrole is set, first element of the modal should gain focus when is opened and the button that opened the modal should get the focus again when is closed - If
alertdialogrole is set, it should be like themodalwith the difference that the less destructive action should get the focus when the modal is opened - Scroll outside should be optionally locked (see react-remove-scroll and its size)
- Header should be a
headertag - Close button should always have a
aria-label(e.g.Close). I think that would be nice for it to be aAtomButton - Usage of
aria-labelledby(id of the header) andaria-describedby(id of the content)
Features (nice to have):
-
scrollBehaviourcould beinsideoroutside - Support custom transitions
Sources:
- w3c
- MDN
- It’s a (focus) Trap! article