Skip to content

Commit 0a1d0cd

Browse files
add help text support to SearchAutocomplete (#4327)
Co-authored-by: Robert Snow <[email protected]>
1 parent 23c3a91 commit 0a1d0cd

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

packages/@react-aria/autocomplete/src/useSearchAutocomplete.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ export interface SearchAutocompleteAria<T> {
2828
/** Props for the list box, to be passed to [useListBox](useListBox.html). */
2929
listBoxProps: AriaListBoxOptions<T>,
3030
/** Props for the search input's clear button. */
31-
clearButtonProps: AriaButtonProps
31+
clearButtonProps: AriaButtonProps,
32+
/** Props for the search autocomplete description element, if any. */
33+
descriptionProps: DOMAttributes,
34+
/** Props for the search autocomplete error message element, if any. */
35+
errorMessageProps: DOMAttributes
3236
}
3337

3438
export interface AriaSearchAutocompleteOptions<T> extends AriaSearchAutocompleteProps<T> {
@@ -58,7 +62,7 @@ export function useSearchAutocomplete<T>(props: AriaSearchAutocompleteOptions<T>
5862
onClear
5963
} = props;
6064

61-
let {inputProps, clearButtonProps} = useSearchField({
65+
let {inputProps, clearButtonProps, descriptionProps, errorMessageProps} = useSearchField({
6266
...props,
6367
value: state.inputValue,
6468
onChange: state.setInputValue,
@@ -98,6 +102,8 @@ export function useSearchAutocomplete<T>(props: AriaSearchAutocompleteOptions<T>
98102
labelProps,
99103
inputProps: mergeProps(inputProps, comboBoxInputProps),
100104
listBoxProps,
101-
clearButtonProps
105+
clearButtonProps,
106+
descriptionProps,
107+
errorMessageProps
102108
};
103109
}

packages/@react-spectrum/autocomplete/src/SearchAutocomplete.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function _SearchAutocompleteBase<T extends object>(props: SpectrumSearchAutocomp
9696
);
9797
let layout = useListBoxLayout(state);
9898

99-
let {inputProps, listBoxProps, labelProps, clearButtonProps} = useSearchAutocomplete(
99+
let {inputProps, listBoxProps, labelProps, clearButtonProps, descriptionProps, errorMessageProps} = useSearchAutocomplete(
100100
{
101101
...props,
102102
keyboardDelegate: layout,
@@ -133,7 +133,12 @@ function _SearchAutocompleteBase<T extends object>(props: SpectrumSearchAutocomp
133133

134134
return (
135135
<>
136-
<Field {...props} labelProps={labelProps} ref={domRef}>
136+
<Field
137+
{...props}
138+
descriptionProps={descriptionProps}
139+
errorMessageProps={errorMessageProps}
140+
labelProps={labelProps}
141+
ref={domRef}>
137142
<SearchAutocompleteInput
138143
{...props}
139144
isOpen={state.isOpen}

0 commit comments

Comments
 (0)