Skip to content

Commit 35b627e

Browse files
committed
forgot to use generic for autocomplete filter
1 parent 3c2e92c commit 35b627e

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ export interface CollectionOptions extends DOMProps, AriaLabelingProps {
2929
}
3030

3131
// TODO; For now go with Node here, but maybe pare it down to just the essentials? Value, key, and maybe type?
32-
export interface AriaAutocompleteProps extends AutocompleteProps {
32+
export interface AriaAutocompleteProps<T> extends AutocompleteProps {
3333
/**
3434
* An optional filter function used to determine if a option should be included in the autocomplete list.
3535
* Include this if the items you are providing to your wrapped collection aren't filtered by default.
3636
*/
37-
filter?: (textValue: string, inputValue: string, node: Node<unknown>) => boolean,
37+
filter?: (textValue: string, inputValue: string, node: Node<T>) => boolean,
3838

3939
/**
4040
* Whether or not to focus the first item in the collection after a filter is performed.
@@ -43,7 +43,7 @@ export interface AriaAutocompleteProps extends AutocompleteProps {
4343
disableAutoFocusFirst?: boolean
4444
}
4545

46-
export interface AriaAutocompleteOptions extends Omit<AriaAutocompleteProps, 'children'> {
46+
export interface AriaAutocompleteOptions<T> extends Omit<AriaAutocompleteProps<T>, 'children'> {
4747
/** The ref for the wrapped collection element. */
4848
inputRef: RefObject<HTMLInputElement | null>,
4949
/** The ref for the wrapped collection element. */
@@ -67,7 +67,7 @@ export interface AutocompleteAria<T> {
6767
* @param props - Props for the autocomplete.
6868
* @param state - State for the autocomplete, as returned by `useAutocompleteState`.
6969
*/
70-
export function useAutocomplete<T>(props: AriaAutocompleteOptions, state: AutocompleteState): AutocompleteAria<T> {
70+
export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: AutocompleteState): AutocompleteAria<T> {
7171
let {
7272
inputRef,
7373
collectionRef,
@@ -318,7 +318,7 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions, state: Autoco
318318
'aria-label': stringFormatter.format('collectionLabel')
319319
});
320320

321-
let filterFn = useCallback((nodeTextValue: string, node: Node<unknown>) => {
321+
let filterFn = useCallback((nodeTextValue: string, node: Node<T>) => {
322322
if (filter) {
323323
return filter(nodeTextValue, state.inputValue, node);
324324
}

packages/dev/s2-docs/src/SearchMenu.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const getCurrentLibrary = (currentPage: Page) => {
125125

126126
export default function SearchMenu(props: SearchMenuProps) {
127127
let {pages, currentPage, toggleShowSearchMenu, closeSearchMenu, isSearchOpen} = props;
128-
128+
129129
const currentLibrary = getCurrentLibrary(currentPage);
130130
let [selectedLibrary, setSelectedLibrary] = useState<'react-spectrum' | 'react-aria' | 'internationalized'>(currentLibrary);
131131
let [searchValue, setSearchValue] = useState('');
@@ -140,14 +140,14 @@ export default function SearchMenu(props: SearchMenuProps) {
140140
},
141141
{
142142
id: 'react-aria',
143-
label: 'React Aria',
143+
label: 'React Aria',
144144
description: 'Style-free components and hooks for building accessible UIs',
145145
icon: <ReactAriaLogo />
146146
},
147147
{
148148
id: 'internationalized',
149149
label: 'Internationalized',
150-
description: 'Framework-agnostic internationalization utilities',
150+
description: 'Framework-agnostic internationalization utilities',
151151
icon: <InternationalizedLogo />
152152
}
153153
];
@@ -158,7 +158,7 @@ export default function SearchMenu(props: SearchMenuProps) {
158158
const currentTab = allTabs.splice(currentTabIndex, 1)[0];
159159
allTabs.unshift(currentTab);
160160
}
161-
161+
162162
return allTabs;
163163
};
164164

@@ -184,13 +184,13 @@ export default function SearchMenu(props: SearchMenuProps) {
184184
} else if (page.url.includes('react-internationalized')) {
185185
library = 'internationalized';
186186
}
187-
187+
188188
return library === selectedLibrary;
189189
})
190190
.map(page => {
191191
const name = page.url.replace(/^\//, '').replace(/\.html$/, '');
192192
const title = page.tableOfContents?.[0]?.title || name;
193-
193+
194194
return {
195195
id: name,
196196
name: title,
@@ -257,7 +257,7 @@ export default function SearchMenu(props: SearchMenuProps) {
257257

258258
let {contains} = useFilter({sensitivity: 'base'});
259259

260-
let filter: AutocompleteProps['filter'] = (textValue, inputValue) => {
260+
let filter: AutocompleteProps<any>['filter'] = (textValue, inputValue) => {
261261
return textValue != null && contains(textValue, inputValue);
262262
};
263263

@@ -294,7 +294,7 @@ export default function SearchMenu(props: SearchMenuProps) {
294294

295295
return (
296296
<div
297-
className={style({
297+
className={style({
298298
display: 'grid',
299299
gridTemplateColumns: 'auto 1fr',
300300
alignItems: 'center',

packages/dev/s2-docs/src/SearchResultsMenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface SearchResultsMenuProps {
3030
searchRef: React.RefObject<TextFieldRef<HTMLInputElement> | null>,
3131
showCards: boolean,
3232
renderCardList: () => React.ReactNode,
33-
filter?: AutocompleteProps['filter'],
33+
filter?: AutocompleteProps<any>['filter'],
3434
noResultsText?: (value: string) => string,
3535
closeSearchMenu: () => void,
3636
isPrimary?: boolean
@@ -48,7 +48,7 @@ function CloseButton({closeSearchMenu}: {closeSearchMenu: () => void}) {
4848
<Close />
4949
</ActionButton>
5050
</Provider>
51-
</div>
51+
</div>
5252
);
5353
}
5454

packages/react-aria-components/src/Autocomplete.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ import React, {createContext, JSX, RefObject, useRef} from 'react';
2020
import {SearchFieldContext} from './SearchField';
2121
import {TextFieldContext} from './TextField';
2222

23-
export interface AutocompleteProps extends AriaAutocompleteProps, SlotProps {}
23+
export interface AutocompleteProps<T> extends AriaAutocompleteProps<T>, SlotProps {}
2424

25-
interface InternalAutocompleteContextValue {
26-
filter?: (nodeTextValue: string, node: Node<unknown>) => boolean,
25+
interface InternalAutocompleteContextValue<T> {
26+
filter?: (nodeTextValue: string, node: Node<T>) => boolean,
2727
collectionProps: CollectionOptions,
2828
collectionRef: RefObject<HTMLElement | null>
2929
}
3030

31-
export const AutocompleteContext = createContext<SlottedContextValue<Partial<AutocompleteProps>>>(null);
31+
export const AutocompleteContext = createContext<SlottedContextValue<Partial<AutocompleteProps<any>>>>(null);
3232
export const AutocompleteStateContext = createContext<AutocompleteState | null>(null);
3333
// This context is to pass the register and filter down to whatever collection component is wrapped by the Autocomplete
3434
// TODO: export from RAC, but rename to something more appropriate
35-
export const UNSTABLE_InternalAutocompleteContext = createContext<InternalAutocompleteContextValue | null>(null);
35+
export const UNSTABLE_InternalAutocompleteContext = createContext<InternalAutocompleteContextValue<any> | null>(null);
3636

3737
/**
3838
* An autocomplete combines a TextField or SearchField with a Menu or ListBox, allowing users to search or filter a list of suggestions.
3939
*/
40-
export function Autocomplete(props: AutocompleteProps): JSX.Element {
40+
export function Autocomplete<T>(props: AutocompleteProps<T>): JSX.Element {
4141
let ctx = useSlottedContext(AutocompleteContext, props.slot);
4242
props = mergeProps(ctx, props);
4343
let {filter, disableAutoFocusFirst} = props;
@@ -65,7 +65,7 @@ export function Autocomplete(props: AutocompleteProps): JSX.Element {
6565
[TextFieldContext, textFieldProps],
6666
[InputContext, {ref: inputRef}],
6767
[UNSTABLE_InternalAutocompleteContext, {
68-
filter: filterFn,
68+
filter: filterFn as (nodeTextValue: string, node: Node<T>) => boolean,
6969
collectionProps,
7070
collectionRef: mergedCollectionRef
7171
}]

0 commit comments

Comments
 (0)