From 6e79c9546799d5e29f97a20149014b25ea6e4caf Mon Sep 17 00:00:00 2001 From: Mason Hu Date: Wed, 14 Feb 2024 12:53:58 +0200 Subject: [PATCH] fix: address a11y issues in input related components Signed-off-by: Mason Hu --- src/components/Input/Input.tsx | 7 ++++--- src/components/Input/__snapshots__/Input.test.tsx.snap | 1 - .../__snapshots__/TablePaginationControls.test.tsx.snap | 1 - .../__snapshots__/TablePagination.test.tsx.snap | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/Input/Input.tsx b/src/components/Input/Input.tsx index 41e46b8ab..bc3318672 100644 --- a/src/components/Input/Input.tsx +++ b/src/components/Input/Input.tsx @@ -100,10 +100,11 @@ const Input = ({ const helpId = useId(); const hasError = !!error; + const description = [help ? helpId : null, success ? validationId : null] + .filter(Boolean) + .join(" "); const commonProps = { - "aria-describedby": [help ? helpId : null, success ? validationId : null] - .filter(Boolean) - .join(" "), + "aria-describedby": !description ? undefined : description, "aria-errormessage": hasError ? validationId : null, "aria-invalid": hasError, id: inputId, diff --git a/src/components/Input/__snapshots__/Input.test.tsx.snap b/src/components/Input/__snapshots__/Input.test.tsx.snap index 3f8708882..da4273d0c 100644 --- a/src/components/Input/__snapshots__/Input.test.tsx.snap +++ b/src/components/Input/__snapshots__/Input.test.tsx.snap @@ -9,7 +9,6 @@ exports[`Input renders 1`] = ` class="p-form__control u-clearfix" > renders table pagination controls and match exports[` renders table pagination controls and matches the snapshot 2`] = ` renders table pagination and matches the snapshot 1 class="p-form__control u-clearfix" >