From d32e6d01dc9c9458f2456ace6ebb8da173a43e88 Mon Sep 17 00:00:00 2001 From: Brian Smith <112954497+brian-smith-tcril@users.noreply.github.com> Date: Tue, 19 Dec 2023 16:29:42 -0500 Subject: [PATCH] fix: associate labels with autosuggest input (#2755) --- src/Form/FormAutosuggest.jsx | 16 ++- src/Form/form-autosuggest.mdx | 152 +++++++++++++----------- src/Form/tests/FormAutosuggest.test.jsx | 21 ++++ 3 files changed, 112 insertions(+), 77 deletions(-) diff --git a/src/Form/FormAutosuggest.jsx b/src/Form/FormAutosuggest.jsx index a2ef755281..0e255d5553 100644 --- a/src/Form/FormAutosuggest.jsx +++ b/src/Form/FormAutosuggest.jsx @@ -6,7 +6,7 @@ import { v4 as uuidv4 } from 'uuid'; import { useIntl } from 'react-intl'; import { KeyboardArrowUp, KeyboardArrowDown } from '../../icons'; import Icon from '../Icon'; -import FormGroup from './FormGroup'; +import { FormGroupContextProvider, useFormGroupContext } from './FormGroupContext'; import FormControl from './FormControl'; import FormControlFeedback from './FormControlFeedback'; import IconButton from '../IconButton'; @@ -239,12 +239,18 @@ function FormAutosuggest({ setDisplayValue(e.target.value); }; + const { getControlProps } = useFormGroupContext(); + const controlProps = getControlProps(props); + return (
{`${state.dropDownItems.length} options found`}
- + 0).toString()} @@ -259,7 +265,7 @@ function FormAutosuggest({ onClick={handleClick} trailingElement={iconToggle} data-testid="autosuggest-textbox-input" - {...props} + {...controlProps} /> {helpMessage && !state.errorMessage && ( @@ -269,11 +275,11 @@ function FormAutosuggest({ )} {state.errorMessage && ( - + {errorMessageText} )} - +