diff --git a/client/components/common/BasicModal/index.jsx b/client/components/common/BasicModal/index.jsx index d9aed660f..155d2201f 100644 --- a/client/components/common/BasicModal/index.jsx +++ b/client/components/common/BasicModal/index.jsx @@ -39,21 +39,21 @@ const BasicModal = ({ }, [show]); const id = useMemo(() => { - return uniqueId('focus-trapped-modal-'); + return uniqueId('modal-'); }, []); return ( - + @@ -65,6 +65,7 @@ const BasicModal = ({ as={ModalTitleStyle} tabIndex="-1" ref={headerRef} + id={`title-${id}`} > {title} diff --git a/client/components/common/BasicThemedModal/index.jsx b/client/components/common/BasicThemedModal/index.jsx index 428a3e445..be6a96492 100644 --- a/client/components/common/BasicThemedModal/index.jsx +++ b/client/components/common/BasicThemedModal/index.jsx @@ -1,9 +1,10 @@ -import React, { useEffect, useRef } from 'react'; +import React, { useEffect, useMemo, useRef } from 'react'; import PropTypes from 'prop-types'; import { Button, Modal } from 'react-bootstrap'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons'; import styled from '@emotion/styled'; +import { uniqueId } from 'lodash'; const ModalTitleStyle = styled.h1` border: 0; @@ -50,6 +51,10 @@ const BasicThemedModal = ({ headerRef.current.focus(); }, [show]); + const id = useMemo(() => { + return uniqueId('modal-'); + }, []); + return ( <> @@ -68,6 +73,7 @@ const BasicThemedModal = ({ as={ModalTitleStyle} tabIndex="-1" ref={headerRef} + id={`title-${id}`} > ', () => { + it('has aria-labelledby matching the modal title id', () => { + const { getByRole, getByText } = render( + + ); + + const modal = getByRole('dialog'); + const title = getByText('Test Title'); + + expect(modal).toHaveAttribute('aria-labelledby', title.id); + }); +});