@@ -69,11 +69,36 @@ const itemToString = (value, isMulti, showMore, handleShowMore, handleChange) =>
6969} ;
7070
7171// TODO fix the value of internal select not to be an array all the time. It forces the filter value to be an array and it crashes sometimes.
72- const filterOptions = ( options , filterValue = '' ) =>
73- options . filter ( ( { label } ) => {
74- const filter = Array . isArray ( filterValue ) && filterValue . length > 0 ? filterValue [ 0 ] : filterValue ;
75- return label . toLowerCase ( ) . includes ( filter . toLowerCase ( ) ) ;
76- } ) ;
72+ const filterOptions = ( options , filterValue = '' ) => {
73+ const filter = ( Array . isArray ( filterValue ) && filterValue . length > 0 ? filterValue [ 0 ] : filterValue ) . toLowerCase ( ) ;
74+
75+ if ( ! filter ) {
76+ return options ;
77+ }
78+
79+ return options
80+ . map ( ( option ) => {
81+ if ( option . options ) {
82+ const filteredNested = option . options . map ( ( option ) => ( option . label ?. toLowerCase ( ) . includes ( filter ) ? option : null ) ) . filter ( Boolean ) ;
83+
84+ if ( filteredNested . length === 0 ) {
85+ return null ;
86+ }
87+
88+ return {
89+ ...option ,
90+ options : filteredNested ,
91+ } ;
92+ }
93+
94+ if ( option . label ?. toLowerCase ( ) . includes ( filter ) ) {
95+ return option ;
96+ }
97+
98+ return null ;
99+ } )
100+ . filter ( Boolean ) ;
101+ } ;
77102
78103const getValue = ( isMulti , option , value ) => {
79104 if ( ! isMulti || ! option ) {
@@ -154,6 +179,7 @@ const InternalSelect = ({
154179 loadingMessage,
155180 menuPortalTarget,
156181 menuIsPortal,
182+ originalOptions,
157183 ...props
158184} ) => {
159185 const [ showMore , setShowMore ] = useState ( false ) ;
@@ -223,6 +249,7 @@ const InternalSelect = ({
223249 menuPortalTarget = { menuPortalTarget }
224250 menuIsPortal = { menuIsPortal }
225251 selectToggleRef = { selectToggleRef }
252+ originalOptions = { originalOptions }
226253 />
227254 ) }
228255 </ div >
@@ -257,6 +284,7 @@ InternalSelect.propTypes = {
257284 loadingMessage : PropTypes . node ,
258285 menuPortalTarget : PropTypes . any ,
259286 menuIsPortal : PropTypes . bool ,
287+ originalOptions : PropTypes . array ,
260288} ;
261289
262290const Select = ( { menuIsPortal, ...props } ) => {
0 commit comments