Skip to content

Commit

Permalink
fix: rgaa gestion des focus
Browse files Browse the repository at this point in the history
  • Loading branch information
victor committed Dec 19, 2024
1 parent 2d6fe5a commit 846a02c
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button } from "@codegouvfr/react-dsfr/Button";
import { Checkbox } from "@codegouvfr/react-dsfr/Checkbox";
import { Input } from "@codegouvfr/react-dsfr/Input";
import { FeedbackActionChoiceValue } from "./tracking";
import { useState } from "react";
import { useEffect, useState } from "react";

const MAX_LENGTH_SUGGESTION = 500;

Expand All @@ -18,6 +18,9 @@ export type FeedbackDataSent = {
};

export const FeedbackContent = (props: Props) => {
const [firstCheckboxRef, setFirstCheckboxRef] =
useState<HTMLInputElement | null>();
const [textAreaRef, setTextAreaRef] = useState<HTMLTextAreaElement | null>();
const [categories, setCategories] = useState<FeedbackActionChoiceValue[]>([]);
const [suggestion, setSuggestion] = useState<string | undefined>(undefined);
const [hasCheckBoxError, setHasCheckBoxError] = useState<boolean>(false);
Expand Down Expand Up @@ -77,6 +80,14 @@ export const FeedbackContent = (props: Props) => {
400, 300, 200, 100, 50, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
];

useEffect(() => {
if (props.type === "negative") {
firstCheckboxRef?.focus();
} else {
textAreaRef?.focus();
}
});

return (
<>
<h2 className={fr.cx("fr-h5")}>Merci pour votre réponse.</h2>
Expand All @@ -90,6 +101,7 @@ export const FeedbackContent = (props: Props) => {
name: "unclear",
value: "unclear" as FeedbackActionChoiceValue,
onChange: onChangeCategories,
ref: setFirstCheckboxRef,
},
},
{
Expand Down Expand Up @@ -128,6 +140,7 @@ export const FeedbackContent = (props: Props) => {
nativeTextAreaProps={{
onChange: onInputSuggestion,
value: suggestion,
ref: setTextAreaRef,
}}
state={hasSuggestionError ? "error" : "default"}
stateRelatedMessage={errorMessageSuggestion}
Expand Down

0 comments on commit 846a02c

Please sign in to comment.