2021-06-23 05:37:08 -04:00
|
|
|
import { useCallback } from 'react'
|
2022-07-07 10:04:20 -04:00
|
|
|
import { Modal, ModalProps } from 'react-bootstrap'
|
2021-01-05 05:57:45 -05:00
|
|
|
|
2023-01-05 05:17:57 -05:00
|
|
|
// A wrapper for the v0.33 React Bootstrap Modal component,
|
|
|
|
// which ensures that the `aria-hidden` attribute is not set on the modal when it's visible,
|
|
|
|
// and that role="dialog" is not duplicated.
|
|
|
|
// https://github.com/react-bootstrap/react-bootstrap/issues/4790
|
|
|
|
// There are other ARIA attributes on these modals which could be improved,
|
|
|
|
// but this at least makes them accessible for tests.
|
|
|
|
function AccessibleModal(props: ModalProps) {
|
|
|
|
const modalRef = useCallback(
|
2021-01-05 05:57:45 -05:00
|
|
|
element => {
|
2023-01-05 05:17:57 -05:00
|
|
|
const modalNode = element?._modal?.modalNode
|
|
|
|
if (modalNode) {
|
|
|
|
if (props.show) {
|
|
|
|
modalNode.removeAttribute('role')
|
|
|
|
modalNode.removeAttribute('aria-hidden')
|
|
|
|
} else {
|
|
|
|
// NOTE: possibly not ever used, as the modal is only rendered when shown
|
|
|
|
modalNode.setAttribute('aria-hidden', 'true')
|
|
|
|
}
|
2021-01-05 05:57:45 -05:00
|
|
|
}
|
|
|
|
},
|
2023-01-05 05:17:57 -05:00
|
|
|
[props.show]
|
2021-01-05 05:57:45 -05:00
|
|
|
)
|
|
|
|
|
2023-01-05 05:17:57 -05:00
|
|
|
return <Modal {...props} ref={modalRef} />
|
2021-01-05 05:57:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default AccessibleModal
|