Skip to content

fix: aria-live and aria-describedby on fieldset element. #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/shared/Fieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ export const Fieldset = memo(

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

const errorDescId = `${id}-desc-error`;
const successDescId = `${id}-desc-valid`;
const messageId = `${id}-desc`;
const messagesWrapperId = `${id}-messages`;

const radioName = (function useClosure() {
Expand Down Expand Up @@ -184,6 +183,7 @@ export const Fieldset = memo(
fr.cx("fr-fieldset__legend", "fr-text--regular"),
classes.legend
)}
aria-describedby={state !== "default" ? messageId : undefined}
>
{legend}
{hintText !== undefined && (
Expand All @@ -197,18 +197,11 @@ export const Fieldset = memo(
<div
className={fr.cx("fr-messages-group")}
id={messagesWrapperId}
aria-live="assertive"
aria-live={state === "error" ? "assertive" : undefined}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le aria-live assertive est à renseigner seulement si c'est une erreur.

>
{stateRelatedMessage !== undefined && (
<p
id={(() => {
switch (state) {
case "error":
return errorDescId;
case "success":
return successDescId;
}
})()}
id={messageId}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai repris la même logique que sur le champ Input pour gérer la relation entre le message et la label.

className={fr.cx(
"fr-message",
(() => {
Expand Down