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
|
|
|
|
|
|
|
// a bootstrap Modal with its `aria-hidden` attribute removed. Visisble modals
|
|
|
|
// should not have their `aria-hidden` attribute set but that's a bug in our
|
|
|
|
// version of react-bootstrap.
|
2022-07-07 10:04:20 -04:00
|
|
|
function AccessibleModal({ show, ...otherProps }: ModalProps) {
|
2021-01-05 05:57:45 -05:00
|
|
|
// use a callback ref to track the modal. This will re-run the function
|
|
|
|
// when the element node or any of the dependencies are updated
|
|
|
|
const setModalRef = useCallback(
|
|
|
|
element => {
|
|
|
|
if (!element) return
|
|
|
|
|
|
|
|
const modalNode = element._modal && element._modal.modalNode
|
|
|
|
if (!modalNode) return
|
|
|
|
|
|
|
|
if (show) {
|
|
|
|
modalNode.removeAttribute('aria-hidden')
|
|
|
|
} else {
|
|
|
|
modalNode.setAttribute('aria-hidden', 'true')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// `show` is necessary as a dependency, but eslint thinks it is not
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
[show]
|
|
|
|
)
|
|
|
|
|
|
|
|
return <Modal show={show} {...otherProps} ref={setModalRef} />
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AccessibleModal
|