Skip to content

Commit 38399f6

Browse files
authored
SearchAutocomplete: fix types (#4305)
* fix SearchAutocomplete types * fix types * move icons to spectrum prop
1 parent c463c88 commit 38399f6

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212
export {useSearchAutocomplete} from './useSearchAutocomplete';
13-
export type {AriaSearchAutocompleteProps, SearchAutocompleteAria} from './useSearchAutocomplete';
13+
export type {AriaSearchAutocompleteOptions, SearchAutocompleteAria} from './useSearchAutocomplete';
14+
export type {AriaSearchAutocompleteProps} from '@react-types/autocomplete';

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,14 @@
1212

1313
import {AriaButtonProps} from '@react-types/button';
1414
import {AriaListBoxOptions} from '@react-aria/listbox';
15+
import {AriaSearchAutocompleteProps} from '@react-types/autocomplete';
1516
import {ComboBoxState} from '@react-stately/combobox';
16-
import {DOMAttributes} from '@react-types/shared';
17+
import {DOMAttributes, KeyboardDelegate} from '@react-types/shared';
1718
import {InputHTMLAttributes, RefObject} from 'react';
18-
import {KeyboardDelegate} from '@react-types/shared';
1919
import {mergeProps} from '@react-aria/utils';
20-
import {SearchAutocompleteProps} from '@react-types/autocomplete';
2120
import {useComboBox} from '@react-aria/combobox';
2221
import {useSearchField} from '@react-aria/searchfield';
2322

24-
export interface AriaSearchAutocompleteProps<T> extends SearchAutocompleteProps<T> {
25-
/** The ref for the input element. */
26-
inputRef: RefObject<HTMLInputElement>,
27-
/** The ref for the list box popover. */
28-
popoverRef: RefObject<HTMLDivElement>,
29-
/** The ref for the list box. */
30-
listBoxRef: RefObject<HTMLElement>,
31-
/** An optional keyboard delegate implementation, to override the default. */
32-
keyboardDelegate?: KeyboardDelegate
33-
}
34-
3523
export interface SearchAutocompleteAria<T> {
3624
/** Props for the label element. */
3725
labelProps: DOMAttributes,
@@ -43,13 +31,24 @@ export interface SearchAutocompleteAria<T> {
4331
clearButtonProps: AriaButtonProps
4432
}
4533

34+
export interface AriaSearchAutocompleteOptions<T> extends AriaSearchAutocompleteProps<T> {
35+
/** The ref for the input element. */
36+
inputRef: RefObject<HTMLInputElement>,
37+
/** The ref for the list box popover. */
38+
popoverRef: RefObject<HTMLDivElement>,
39+
/** The ref for the list box. */
40+
listBoxRef: RefObject<HTMLElement>,
41+
/** An optional keyboard delegate implementation, to override the default. */
42+
keyboardDelegate?: KeyboardDelegate
43+
}
44+
4645
/**
4746
* Provides the behavior and accessibility implementation for a search autocomplete component.
4847
* A search autocomplete combines a combobox with a searchfield, allowing users to filter a list of options to items matching a query.
4948
* @param props - Props for the search autocomplete.
5049
* @param state - State for the search autocomplete, as returned by `useSearchAutocomplete`.
5150
*/
52-
export function useSearchAutocomplete<T>(props: AriaSearchAutocompleteProps<T>, state: ComboBoxState<T>): SearchAutocompleteAria<T> {
51+
export function useSearchAutocomplete<T>(props: AriaSearchAutocompleteOptions<T>, state: ComboBoxState<T>): SearchAutocompleteAria<T> {
5352
let {
5453
popoverRef,
5554
inputRef,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ let SearchAutocompleteBase = React.forwardRef(_SearchAutocompleteBase) as <T>(pr
179179

180180
interface SearchAutocompleteInputProps<T> extends SpectrumSearchAutocompleteProps<T> {
181181
inputProps: InputHTMLAttributes<HTMLInputElement>,
182-
inputRef: RefObject<HTMLInputElement | HTMLTextAreaElement>,
182+
inputRef: RefObject<HTMLInputElement>,
183183
style?: React.CSSProperties,
184184
className?: string,
185185
isOpen?: boolean,

packages/@react-types/autocomplete/src/index.d.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {AriaSearchFieldProps} from '@react-types/searchfield';
14-
import {AsyncLoadable, CollectionBase, LoadingState, SpectrumLabelableProps, SpectrumTextInputBase, StyleProps} from '@react-types/shared';
13+
import {AriaLabelingProps, AsyncLoadable, CollectionBase, DOMProps, LoadingState, SpectrumLabelableProps, SpectrumTextInputBase, StyleProps} from '@react-types/shared';
1514
import {Key, ReactElement} from 'react';
1615
import {MenuTriggerAction} from '@react-types/combobox';
16+
import {SearchFieldProps} from '@react-types/searchfield';
1717

18-
export interface SearchAutocompleteProps<T> extends CollectionBase<T>, Omit<AriaSearchFieldProps, 'onSubmit'> {
18+
export interface SearchAutocompleteProps<T> extends CollectionBase<T>, Omit<SearchFieldProps, 'onSubmit' | 'defaultValue' | 'value'> {
1919
/** The list of SearchAutocomplete items (uncontrolled). */
2020
defaultItems?: Iterable<T>,
2121
/** The list of SearchAutocomplete items (controlled). */
@@ -41,12 +41,12 @@ export interface SearchAutocompleteProps<T> extends CollectionBase<T>, Omit<Aria
4141
* A `key` will be passed if the submission is a selected item (e.g. a user clicks or presses enter on an option).
4242
* If the input is a custom value, `key` will be null.
4343
*/
44-
onSubmit?: (value: string | null, key: Key | null) => void,
45-
/** An icon to display at the start of the input. */
46-
icon?: ReactElement | null
44+
onSubmit?: (value: string | null, key: Key | null) => void
4745
}
4846

49-
export interface SpectrumSearchAutocompleteProps<T> extends SpectrumTextInputBase, Omit<SearchAutocompleteProps<T>, 'menuTrigger'>, SpectrumLabelableProps, StyleProps, Omit<AsyncLoadable, 'isLoading'> {
47+
export interface AriaSearchAutocompleteProps<T> extends SearchAutocompleteProps<T>, DOMProps, AriaLabelingProps {}
48+
49+
export interface SpectrumSearchAutocompleteProps<T> extends SpectrumTextInputBase, Omit<AriaSearchAutocompleteProps<T>, 'menuTrigger'>, SpectrumLabelableProps, StyleProps, Omit<AsyncLoadable, 'isLoading'> {
5050
/**
5151
* The interaction required to display the SearchAutocomplete menu. Note that this prop has no effect on the mobile SearchAutocomplete experience.
5252
* @default 'input'
@@ -66,5 +66,7 @@ export interface SpectrumSearchAutocompleteProps<T> extends SpectrumTextInputBas
6666
* @default true
6767
*/
6868
shouldFlip?: boolean,
69-
onLoadMore?: () => void
69+
onLoadMore?: () => void,
70+
/** An icon to display at the start of the input. */
71+
icon?: ReactElement | null
7072
}

0 commit comments

Comments
 (0)