@@ -18,10 +18,11 @@ import {ContextValue, DOMProps, Provider, RenderProps, SlotProps, StyleRenderPro
18
18
import { filterDOMProps , mergeProps , useObjectRef } from '@react-aria/utils' ;
19
19
import { forwardRefType , GlobalDOMAttributes , HoverEvents , Key , LinkDOMProps , PressEvents } from '@react-types/shared' ;
20
20
import { LabelContext } from './Label' ;
21
- import { ListState , Node , useListState } from 'react-stately' ;
21
+ import { ListState , Node , UNSTABLE_useFilteredListState , useListState } from 'react-stately' ;
22
22
import { ListStateContext } from './ListBox' ;
23
23
import React , { createContext , ForwardedRef , forwardRef , JSX , ReactNode , useContext , useEffect , useRef } from 'react' ;
24
24
import { TextContext } from './Text' ;
25
+ import { UNSTABLE_InternalAutocompleteContext } from './Autocomplete' ;
25
26
26
27
export interface TagGroupProps extends Omit < AriaTagGroupProps < unknown > , 'children' | 'items' | 'label' | 'description' | 'errorMessage' | 'keyboardDelegate' > , DOMProps , SlotProps , GlobalDOMAttributes < HTMLDivElement > { }
27
28
@@ -74,16 +75,19 @@ interface TagGroupInnerProps {
74
75
}
75
76
76
77
function TagGroupInner ( { props, forwardedRef : ref , collection} : TagGroupInnerProps ) {
78
+ let { filter} = useContext ( UNSTABLE_InternalAutocompleteContext ) || { } ;
77
79
let tagListRef = useRef < HTMLDivElement > ( null ) ;
78
80
let [ labelRef , label ] = useSlot (
79
81
! props [ 'aria-label' ] && ! props [ 'aria-labelledby' ]
80
82
) ;
81
- let state = useListState ( {
83
+ let tagGroupState = useListState ( {
82
84
...props ,
83
85
children : undefined ,
84
86
collection
85
87
} ) ;
86
88
89
+ let filteredState = UNSTABLE_useFilteredListState ( tagGroupState , filter ) ;
90
+
87
91
// Prevent DOM props from going to two places.
88
92
let domProps = filterDOMProps ( props , { global : true } ) ;
89
93
let domPropOverrides = Object . fromEntries ( Object . entries ( domProps ) . map ( ( [ k ] ) => [ k , undefined ] ) ) ;
@@ -96,7 +100,7 @@ function TagGroupInner({props, forwardedRef: ref, collection}: TagGroupInnerProp
96
100
...props ,
97
101
...domPropOverrides ,
98
102
label
99
- } , state , tagListRef ) ;
103
+ } , filteredState , tagListRef ) ;
100
104
101
105
return (
102
106
< div
@@ -109,7 +113,7 @@ function TagGroupInner({props, forwardedRef: ref, collection}: TagGroupInnerProp
109
113
values = { [
110
114
[ LabelContext , { ...labelProps , elementType : 'span' , ref : labelRef } ] ,
111
115
[ TagListContext , { ...gridProps , ref : tagListRef } ] ,
112
- [ ListStateContext , state ] ,
116
+ [ ListStateContext , filteredState ] ,
113
117
[ TextContext , {
114
118
slots : {
115
119
description : descriptionProps ,
@@ -201,6 +205,14 @@ class TagItemNode extends CollectionNode<any> {
201
205
constructor ( key : Key ) {
202
206
super ( TagItemNode . type , key ) ;
203
207
}
208
+
209
+ filter ( _ , __ , filterFn : ( textValue : string ) => boolean ) : CollectionNode < any > | null {
210
+ if ( filterFn ( this . textValue ) ) {
211
+ return this . clone ( ) ;
212
+ }
213
+
214
+ return null ;
215
+ }
204
216
}
205
217
206
218
/**
0 commit comments