From 0feb6771386e5c944fbdc1ed9510e35c3a09c600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20Jos=C3=A9povic?= Date: Tue, 5 Sep 2023 16:56:09 -0400 Subject: [PATCH 1/5] Remove accessibility warning when a label element is present --- .../src/number-input/src/NumberInput.tsx | 14 +++-- .../tests/jest/NumberInput.test.tsx | 55 +++++++++++++++++++ .../components/src/shared/src/assertions.ts | 2 +- .../components/src/text-area/src/TextArea.tsx | 14 +++-- .../text-area/tests/jest/TextArea.test.tsx | 55 +++++++++++++++++++ .../src/text-input/src/TextInput.tsx | 18 +++--- .../text-input/tests/jest/TextInput.test.tsx | 55 +++++++++++++++++++ 7 files changed, 195 insertions(+), 18 deletions(-) diff --git a/packages/components/src/number-input/src/NumberInput.tsx b/packages/components/src/number-input/src/NumberInput.tsx index f422a54db..5e76a7999 100644 --- a/packages/components/src/number-input/src/NumberInput.tsx +++ b/packages/components/src/number-input/src/NumberInput.tsx @@ -1,6 +1,6 @@ import { AbstractInputProps, adaptInputStylingProps, useInput, useInputIcon, useInputSpinner } from "../../input"; import { Box, BoxProps } from "../../box"; -import { ChangeEvent, ComponentProps, FocusEvent, FocusEventHandler, MouseEvent, ReactElement, Ref, SyntheticEvent, forwardRef, useCallback, useMemo } from "react"; +import { ChangeEvent, ComponentProps, FocusEvent, FocusEventHandler, MouseEvent, ReactElement, Ref, SyntheticEvent, forwardRef, useCallback, useEffect, useMemo } from "react"; import { Div, HtmlButton } from "../../html"; import { OmitInternalProps, @@ -201,10 +201,6 @@ export function InnerNumberInput(props: InnerNumberInputProps) { ...rest } = adaptInputStylingProps(props, contextualProps); - if (isNil(ariaLabel) && isNil(ariaLabelledBy) && isNil(placeholder)) { - console.error("An input component must either have an \"aria-label\" attribute, an \"aria-labelledby\" attribute or a \"placeholder\" attribute."); - } - const fluidValue = useResponsiveValue(fluid); const [inputValueRef, setInputValue] = useRefState(""); @@ -335,6 +331,14 @@ export function InnerNumberInput(props: InnerNumberInputProps) { value: inputValueRef.current }); + useEffect(() => { + const input = inputRef.current; + + if (isNil(ariaLabel) && isNil(ariaLabelledBy) && isNil(placeholder) && isNilOrEmpty(input.labels)) { + console.error("An input component must either have a