Skip to content

Commit e4a90c9

Browse files
authored
Rename filterFn in useAutocomplete to filter (#7863)
1 parent 59f4543 commit e4a90c9

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface AutocompleteAria {
5656
/** Ref to attach to the wrapped collection. */
5757
collectionRef: RefObject<HTMLElement | null>,
5858
/** A filter function that returns if the provided collection node should be filtered out of the collection. */
59-
filterFn?: (nodeTextValue: string) => boolean
59+
filter?: (nodeTextValue: string) => boolean
6060
}
6161

6262
/**
@@ -97,7 +97,7 @@ export function useAutocomplete(props: AriaAutocompleteOptions, state: Autocompl
9797
if (e.isTrusted || !target || queuedActiveDescendant.current === target.id) {
9898
return;
9999
}
100-
100+
101101
clearTimeout(timeout.current);
102102
if (target !== collectionRef.current) {
103103
if (delayNextActiveDescendant.current) {
@@ -252,7 +252,7 @@ export function useAutocomplete(props: AriaAutocompleteOptions, state: Autocompl
252252
new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)
253253
) || false;
254254
}
255-
255+
256256
if (shouldPerformDefaultAction) {
257257
switch (e.key) {
258258
case 'ArrowLeft':
@@ -359,6 +359,6 @@ export function useAutocomplete(props: AriaAutocompleteOptions, state: Autocompl
359359
disallowTypeAhead: true
360360
}),
361361
collectionRef: mergedCollectionRef,
362-
filterFn: filter != null ? filterFn : undefined
362+
filter: filter != null ? filterFn : undefined
363363
};
364364
}

packages/@react-stately/list/src/useListState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export function useListState<T extends object>(props: ListProps<T>): ListState<T
7373
/**
7474
* Filters a collection using the provided filter function and returns a new ListState.
7575
*/
76-
export function UNSTABLE_useFilteredListState<T extends object>(state: ListState<T>, filterFn: ((nodeValue: string) => boolean) | null | undefined): ListState<T> {
77-
let collection = useMemo(() => filterFn ? state.collection.UNSTABLE_filter!(filterFn) : state.collection, [state.collection, filterFn]);
76+
export function UNSTABLE_useFilteredListState<T extends object>(state: ListState<T>, filter: ((nodeValue: string) => boolean) | null | undefined): ListState<T> {
77+
let collection = useMemo(() => filter ? state.collection.UNSTABLE_filter!(filter) : state.collection, [state.collection, filter]);
7878
let selectionManager = state.selectionManager.withCollection(collection);
7979
useFocusedKeyReset(collection, selectionManager);
8080
return {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {TextFieldContext} from './TextField';
2222
export interface AutocompleteProps extends AriaAutocompleteProps, SlotProps {}
2323

2424
interface InternalAutocompleteContextValue {
25-
filterFn?: (nodeTextValue: string) => boolean,
25+
filter?: (nodeTextValue: string) => boolean,
2626
collectionProps: CollectionOptions,
2727
collectionRef: RefObject<HTMLElement | null>
2828
}
@@ -47,7 +47,7 @@ export function Autocomplete(props: AutocompleteProps) {
4747
textFieldProps,
4848
collectionProps,
4949
collectionRef: mergedCollectionRef,
50-
filterFn
50+
filter: filterFn
5151
} = useAutocomplete({
5252
...removeDataAttributes(props),
5353
filter,
@@ -64,7 +64,7 @@ export function Autocomplete(props: AutocompleteProps) {
6464
[TextFieldContext, textFieldProps],
6565
[InputContext, {ref: inputRef}],
6666
[UNSTABLE_InternalAutocompleteContext, {
67-
filterFn,
67+
filter: filterFn,
6868
collectionProps,
6969
collectionRef: mergedCollectionRef
7070
}]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ interface ListBoxInnerProps<T> {
118118
}
119119

120120
function ListBoxInner<T extends object>({state: inputState, props, listBoxRef}: ListBoxInnerProps<T>) {
121-
let {filterFn, collectionProps, collectionRef} = useContext(UNSTABLE_InternalAutocompleteContext) || {};
121+
let {filter, collectionProps, collectionRef} = useContext(UNSTABLE_InternalAutocompleteContext) || {};
122122
props = useMemo(() => collectionProps ? ({...props, ...collectionProps}) : props, [props, collectionProps]);
123123
let {dragAndDropHooks, layout = 'stack', orientation = 'vertical'} = props;
124124
// Memoed so that useAutocomplete callback ref is properly only called once on mount and not everytime a rerender happens
125125
listBoxRef = useObjectRef(useMemo(() => mergeRefs(listBoxRef, collectionRef !== undefined ? collectionRef as RefObject<HTMLDivElement> : null), [collectionRef, listBoxRef]));
126-
let state = UNSTABLE_useFilteredListState(inputState, filterFn);
126+
let state = UNSTABLE_useFilteredListState(inputState, filter);
127127
let {collection, selectionManager} = state;
128128
let isListDraggable = !!dragAndDropHooks?.useDraggableCollectionState;
129129
let isListDroppable = !!dragAndDropHooks?.useDroppableCollectionState;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ interface MenuInnerProps<T> {
183183
}
184184

185185
function MenuInner<T extends object>({props, collection, menuRef: ref}: MenuInnerProps<T>) {
186-
let {filterFn, collectionProps: autocompleteMenuProps, collectionRef} = useContext(UNSTABLE_InternalAutocompleteContext) || {};
186+
let {filter, collectionProps: autocompleteMenuProps, collectionRef} = useContext(UNSTABLE_InternalAutocompleteContext) || {};
187187
// Memoed so that useAutocomplete callback ref is properly only called once on mount and not everytime a rerender happens
188188
ref = useObjectRef(useMemo(() => mergeRefs(ref, collectionRef !== undefined ? collectionRef as RefObject<HTMLDivElement> : null), [collectionRef, ref]));
189-
let filteredCollection = useMemo(() => filterFn ? collection.UNSTABLE_filter(filterFn) : collection, [collection, filterFn]);
189+
let filteredCollection = useMemo(() => filter ? collection.UNSTABLE_filter(filter) : collection, [collection, filter]);
190190
let state = useTreeState({
191191
...props,
192192
collection: filteredCollection as ICollection<Node<object>>,

0 commit comments

Comments
 (0)