Skip to content

Commit 8fdc5da

Browse files
committed
fix: aria-live and aria-describedby on fieldset element.
1 parent 7df734e commit 8fdc5da

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/shared/Fieldset.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, {
2-
useId,
3-
memo,
2+
type ComponentProps,
3+
type CSSProperties,
44
forwardRef,
5+
memo,
56
type ReactNode,
6-
type CSSProperties,
7-
type ComponentProps
7+
useId
88
} from "react";
99
import { symToStr } from "tsafe/symToStr";
1010
import { assert } from "tsafe/assert";
@@ -96,8 +96,7 @@ export const Fieldset = memo(
9696

9797
const legendId = `${id}-legend`;
9898

99-
const errorDescId = `${id}-desc-error`;
100-
const successDescId = `${id}-desc-valid`;
99+
const messageId = `${id}-desc`;
101100
const messagesWrapperId = `${id}-messages`;
102101

103102
const radioName = (function useClosure() {
@@ -184,6 +183,7 @@ export const Fieldset = memo(
184183
fr.cx("fr-fieldset__legend", "fr-text--regular"),
185184
classes.legend
186185
)}
186+
aria-describedby={state !== "default" ? messageId : undefined}
187187
>
188188
{legend}
189189
{hintText !== undefined && (
@@ -197,18 +197,11 @@ export const Fieldset = memo(
197197
<div
198198
className={fr.cx("fr-messages-group")}
199199
id={messagesWrapperId}
200-
aria-live="assertive"
200+
aria-live={state === "error" ? "assertive" : undefined}
201201
>
202202
{stateRelatedMessage !== undefined && (
203203
<p
204-
id={(() => {
205-
switch (state) {
206-
case "error":
207-
return errorDescId;
208-
case "success":
209-
return successDescId;
210-
}
211-
})()}
204+
id={messageId}
212205
className={fr.cx(
213206
"fr-message",
214207
(() => {

0 commit comments

Comments
 (0)