Skip to content

Commit 728a1d1

Browse files
authored
fix(accessibilite): utilisation de fieldset dans le formulaire "Votre avis nous intéresse" (règle 11.6) (#6798)
1 parent 9ab5e26 commit 728a1d1

File tree

5 files changed

+71
-79
lines changed

5 files changed

+71
-79
lines changed

packages/code-du-travail-frontend/lint-staged.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ module.exports = {
55
"**/*.ts?(x)": () => "tsc -p tsconfig.json --noEmit",
66
"*.{js,ts,tsx,jsx}": ["jest --bail --findRelatedTests"],
77
"*.{js,ts,tsx,jsx}": [buildEslintCommand],
8-
"{pages,src}/**/*.{js,ts,tsx,jsx}": ["yarn lint:css"],
98
"*.{js,ts,tsx,jsx,json,md}": ["yarn format"],
109
};

packages/code-du-travail-frontend/src/modules/outils/indemnite-depart/feedback/Questionnaire.tsx

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,25 @@ export const Questionnaire = forwardRef<HTMLHeadingElement, QuestionnaireProps>(
4545
}, [displayError]);
4646

4747
return (
48-
<form
49-
onSubmit={(e) => {
50-
if (!status) {
51-
setDisplayError(true);
52-
e.preventDefault();
53-
} else {
54-
trackFeedback(EVENT_ACTION.GLOBAL, status, category);
55-
onClick();
56-
}
57-
}}
58-
>
59-
<fieldset>
60-
<legend>
61-
<h2
62-
ref={ref}
63-
tabIndex={-1}
64-
className={fr.cx("fr-text--lg", "fr-mb-2w", "fr-text--bold")}
65-
>
66-
Comment s&apos;est passée cette simulation pour vous ?
67-
</h2>
68-
</legend>
48+
<div>
49+
<h2
50+
ref={ref}
51+
tabIndex={-1}
52+
className={fr.cx("fr-text--lg", "fr-mb-2w", "fr-text--bold")}
53+
>
54+
Comment s&apos;est passée cette simulation pour vous ?
55+
</h2>
56+
<form
57+
onSubmit={(e) => {
58+
if (!status) {
59+
setDisplayError(true);
60+
e.preventDefault();
61+
} else {
62+
trackFeedback(EVENT_ACTION.GLOBAL, status, category);
63+
onClick();
64+
}
65+
}}
66+
>
6967
<SmileyQuestionnaireItem
7068
badEventValue={FEEDBACK_RESULT.NOT_GOOD}
7169
averageEventValue={FEEDBACK_RESULT.AVERAGE}
@@ -76,23 +74,23 @@ export const Questionnaire = forwardRef<HTMLHeadingElement, QuestionnaireProps>(
7674
}}
7775
displayError={displayError}
7876
/>
79-
</fieldset>
80-
<div
81-
className={fr.cx(
82-
"fr-btns-group",
83-
"fr-btns-group--inline",
84-
"fr-mt-2w"
85-
)}
86-
>
87-
<Button
88-
priority="secondary"
89-
type="submit"
90-
nativeButtonProps={{ "aria-disabled": displayError }}
77+
<div
78+
className={fr.cx(
79+
"fr-btns-group",
80+
"fr-btns-group--inline",
81+
"fr-mt-2w"
82+
)}
9183
>
92-
Envoyer
93-
</Button>
94-
</div>
95-
</form>
84+
<Button
85+
priority="secondary"
86+
type="submit"
87+
nativeButtonProps={{ "aria-disabled": displayError }}
88+
>
89+
Envoyer
90+
</Button>
91+
</div>
92+
</form>
93+
</div>
9694
);
9795
}
9896
);

packages/code-du-travail-frontend/src/modules/outils/indemnite-depart/feedback/QuestionnaireAdvanced.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const QuestionnaireAdvanced = forwardRef<
106106
};
107107

108108
return (
109-
<form ref={formRef} onSubmit={handleSubmit}>
109+
<div>
110110
<h2
111111
ref={ref}
112112
tabIndex={-1}
@@ -117,7 +117,7 @@ export const QuestionnaireAdvanced = forwardRef<
117117
<p className={fr.cx("fr-text--sm", "fr-mb-3w")}>
118118
Veuillez répondre à au moins une des questions ci-dessous.
119119
</p>
120-
<div>
120+
<form ref={formRef} onSubmit={handleSubmit}>
121121
<NumberedScaleQuestionnaireItem
122122
title="Que pensez-vous de l'utilisation du simulateur ?"
123123
values={[
@@ -181,13 +181,17 @@ export const QuestionnaireAdvanced = forwardRef<
181181
onChange={setFeedbackText}
182182
id="more-input"
183183
/>
184-
</div>
185-
<div
186-
className={fr.cx("fr-btns-group", "fr-btns-group--inline", "fr-mt-2w")}
187-
>
188-
<Button type="submit">Envoyer</Button>
189-
</div>
190-
</form>
184+
<div
185+
className={fr.cx(
186+
"fr-btns-group",
187+
"fr-btns-group--inline",
188+
"fr-mt-2w"
189+
)}
190+
>
191+
<Button type="submit">Envoyer</Button>
192+
</div>
193+
</form>
194+
</div>
191195
);
192196
});
193197

packages/code-du-travail-frontend/src/modules/outils/indemnite-depart/feedback/QuestionnaireText.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use client";
22

33
import { fr } from "@codegouvfr/react-dsfr";
4-
import { Input } from "@codegouvfr/react-dsfr/Input";
54
import { useState } from "react";
65

76
type QuestionnaireItemProps = {
@@ -21,6 +20,8 @@ export const QuestionnaireText = ({
2120
const maxCharacters = 200;
2221
const [remainingChars, setRemainingChars] = useState(maxCharacters);
2322

23+
const charactersCountThresholds = [100, 50, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0];
24+
2425
const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
2526
const currentLength = e.target.value.length;
2627
setRemainingChars(maxCharacters - currentLength);
@@ -29,26 +30,28 @@ export const QuestionnaireText = ({
2930

3031
return (
3132
<div>
32-
<Input
33-
label={title}
34-
textArea
35-
nativeTextAreaProps={
36-
{
37-
id: id,
38-
onChange: handleChange,
39-
maxLength: maxCharacters,
40-
"aria-describedby": `${id}-hint ${id}-remaining`,
41-
"data-testid": `${id}`,
42-
} as any
43-
}
44-
hintText={placeholder}
33+
<label htmlFor={id} className={fr.cx("fr-label")}>
34+
{title}
35+
{placeholder && <span className="fr-hint-text">{placeholder}</span>}
36+
</label>
37+
<textarea
38+
id={id}
39+
className={fr.cx("fr-input")}
40+
maxLength={maxCharacters}
41+
aria-describedby={`${id}-remaining`}
42+
data-testid={id}
43+
onChange={handleChange}
4544
/>
4645
<p
4746
id={`${id}-remaining`}
48-
className={fr.cx("fr-sr-only")}
49-
aria-live="polite"
47+
aria-live={
48+
charactersCountThresholds.indexOf(remainingChars) !== -1
49+
? "polite"
50+
: "off"
51+
}
5052
aria-atomic="true"
5153
role="status"
54+
className="fr-info-text"
5255
>
5356
{`${remainingChars} caractère${
5457
remainingChars > 1 ? "s" : ""

packages/code-du-travail-frontend/src/modules/outils/indemnite-depart/feedback/SmileyQuestionnaireItem.tsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useState, useEffect, useRef } from "react";
3+
import { useState, useEffect, useRef, ReactNode } from "react";
44
import { FEEDBACK_RESULT } from "./tracking";
55
import { fr } from "@codegouvfr/react-dsfr";
66
import { BadIcon } from "./icons/BadIcon";
@@ -50,7 +50,9 @@ export const SmileyQuestionnaireItem = ({
5050
aria-invalid={displayError ? "true" : undefined}
5151
aria-describedby={displayError ? errorId : undefined}
5252
>
53-
<legend className={srOnlyStyle}>Évaluation de satisfaction</legend>
53+
<legend className={fr.cx("fr-sr-only")}>
54+
Évaluation de satisfaction
55+
</legend>
5456
<div
5557
className={fr.cx("fr-btns-group", "fr-btns-group--inline")}
5658
style={{ justifyContent: "center", gap: "1rem" }}
@@ -132,7 +134,6 @@ export const SmileyQuestionnaireItem = ({
132134
</label>
133135
</div>
134136
</div>
135-
136137
{displayError && (
137138
<p
138139
id={errorId}
@@ -198,16 +199,3 @@ const radioTextStyle = css({
198199
fontSize: "0.875rem",
199200
},
200201
});
201-
202-
// Visually hidden but accessible to screen readers
203-
const srOnlyStyle = css({
204-
position: "absolute !important",
205-
width: "1px !important",
206-
height: "1px !important",
207-
padding: "0 !important",
208-
margin: "-1px !important",
209-
overflow: "hidden !important",
210-
clip: "rect(0, 0, 0, 0) !important",
211-
whiteSpace: "nowrap !important",
212-
border: "0 !important",
213-
});

0 commit comments

Comments
 (0)