diff --git a/packages/react-core/src/components/InputGroup/InputGroup.tsx b/packages/react-core/src/components/InputGroup/InputGroup.tsx index 1872146594a..499ae7ad92b 100644 --- a/packages/react-core/src/components/InputGroup/InputGroup.tsx +++ b/packages/react-core/src/components/InputGroup/InputGroup.tsx @@ -31,9 +31,11 @@ export const InputGroup: React.FunctionComponent = ({
{idItem ? React.Children.map(children, (child: any) => - formCtrls.includes(child.type.displayName) - ? React.cloneElement(child, { 'aria-describedby': idItem.props.id }) - : child + !formCtrls.includes(child.type.displayName) || child.props['aria-describedby'] + ? child + : React.cloneElement(child, { + 'aria-describedby': child.props['aria-describedby'] === '' ? undefined : idItem.props.id + }) ) : children}
diff --git a/packages/react-core/src/components/InputGroup/__tests__/InputGroup.test.tsx b/packages/react-core/src/components/InputGroup/__tests__/InputGroup.test.tsx index 7580d6d0070..d91a03091fd 100644 --- a/packages/react-core/src/components/InputGroup/__tests__/InputGroup.test.tsx +++ b/packages/react-core/src/components/InputGroup/__tests__/InputGroup.test.tsx @@ -20,4 +20,34 @@ describe('InputGroup', () => { ); expect(screen.getByLabelText('some text')).toHaveAttribute('aria-describedby', 'button-id'); }); + + test('wont add aria-describedby to form-control if describedby is empty string', () => { + // In this test, TextInput is a form-control component and Button is not. + // If Button has an id props, this should be used in aria-describedby, but this + // example has an empty aria-describedby to prevent that from happening. + render( + + + + + ); + expect(screen.getByLabelText('some text')).not.toHaveAttribute('aria-describedby'); + }); + + test('wont override aria-describedby in form-control if describedby has value', () => { + // In this test, TextInput is a form-control component and Button is not. + // If Button has an id props, this should be used in aria-describedby, but this + // example has a predefined aria-describedby to prevent that from happening + render( + + + + + ); + expect(screen.getByLabelText('some text')).toHaveAttribute('aria-describedby', 'myself'); + }); }); diff --git a/packages/react-core/src/components/NumberInput/NumberInput.tsx b/packages/react-core/src/components/NumberInput/NumberInput.tsx index 2af531ba82c..a3da0f3fa17 100644 --- a/packages/react-core/src/components/NumberInput/NumberInput.tsx +++ b/packages/react-core/src/components/NumberInput/NumberInput.tsx @@ -5,7 +5,8 @@ import MinusIcon from '@patternfly/react-icons/dist/esm/icons/minus-icon'; import PlusIcon from '@patternfly/react-icons/dist/esm/icons/plus-icon'; import { InputGroup } from '../InputGroup'; import { Button, ButtonProps } from '../Button'; -import { KEY_CODES } from '../../helpers'; +import { KEY_CODES, ValidatedOptions } from '../../helpers'; +import { TextInput } from '../TextInput'; export interface NumberInputProps extends React.HTMLProps { /** Value of the number input */ @@ -16,6 +17,10 @@ export interface NumberInputProps extends React.HTMLProps { widthChars?: number; /** Indicates the whole number input should be disabled */ isDisabled?: boolean; + /** Value to indicate if the input is modified to show that validation state + * @beta + */ + validated?: 'default' | 'error' | 'warning' | 'success' | ValidatedOptions; /** Callback for the minus button */ onMinus?: (event: React.MouseEvent, name?: string) => void; /** Callback for the text input changing */ @@ -66,6 +71,7 @@ export const NumberInput: React.FunctionComponent = ({ className, widthChars, isDisabled = false, + validated = ValidatedOptions.default, onMinus = () => {}, onChange, onBlur, @@ -99,7 +105,7 @@ export const NumberInput: React.FunctionComponent = ({ return (
= ({
+ +`; + +exports[`numberInput renders warning validated 1`] = ` + +
+
+ + +