Skip to content

Commit 2270ab1

Browse files
Fix duplicated IDs issue while using multiple modals in a single page (#82)
* Fix Modal title hardcoded id Title: Fix duplicated IDs issue while using multiple modals in a single page Description: This pull request addresses the issue of duplicated IDs by modifying the code to use the modal ID for creating the H1 ID. This change ensures that the H1 ID remains unique, even when multiple modals are present on the same page. Signed-off-by: Clément Lelong <clement@numericite.eu> * Update src/Modal.tsx Co-authored-by: Joseph Garrone <joseph.garrone.gj@gmail.com> Signed-off-by: Clément Lelong <clement@numericite.eu> * Update src/Modal.tsx Co-authored-by: Joseph Garrone <joseph.garrone.gj@gmail.com> Signed-off-by: Clément Lelong <clement@numericite.eu> * Update src/Modal.tsx Co-authored-by: Joseph Garrone <joseph.garrone.gj@gmail.com> Signed-off-by: Clément Lelong <clement@numericite.eu> * Update src/Modal.tsx Signed-off-by: Joseph Garrone <joseph.garrone.gj@gmail.com> --------- Signed-off-by: Clément Lelong <clement@numericite.eu> Signed-off-by: Joseph Garrone <joseph.garrone.gj@gmail.com> Co-authored-by: Joseph Garrone <joseph.garrone.gj@gmail.com>
1 parent c10ead8 commit 2270ab1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Modal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ const Modal = memo(
5959
: [buttons_props];
6060

6161
const { t } = useTranslation();
62-
62+
const titleId= `fr-modal-title-${id}`;
6363
return (
6464
<dialog
65-
aria-labelledby="fr-modal-title-modal-1"
65+
aria-labelledby={titleId}
6666
role="dialog"
6767
id={id}
6868
className={cx(fr.cx("fr-modal", topAnchor && "fr-modal--top"), className)}
@@ -96,7 +96,7 @@ const Modal = memo(
9696
</div>
9797
<div className={fr.cx("fr-modal__content")}>
9898
<h1
99-
id="fr-modal-title-modal-1"
99+
id={titleId}
100100
className={fr.cx("fr-modal__title")}
101101
>
102102
{iconId !== undefined && (

0 commit comments

Comments
 (0)