@@ -16,7 +16,7 @@ import composeRefs from '../../_util/composeRefs';
1616import forwardRefWithStatics from '../../_util/forwardRefWithStatics' ;
1717import { getOffsetTopToContainer } from '../../_util/helper' ;
1818import noop from '../../_util/noop' ;
19- import { parseContentTNode } from '../../_util/parseTNode' ;
19+ import { extractTextFromTNode , parseContentTNode } from '../../_util/parseTNode' ;
2020import FakeArrow from '../../common/FakeArrow' ;
2121import useConfig from '../../hooks/useConfig' ;
2222import useControlled from '../../hooks/useControlled' ;
@@ -287,23 +287,30 @@ const Select = forwardRefWithStatics(
287287 return filter ( value , option ) ;
288288 }
289289 const upperValue = value . toUpperCase ( ) ;
290- return ( option ?. label || '' ) . toUpperCase ( ) . includes ( upperValue ) ;
290+ const searchableText = extractTextFromTNode ( option . label ) ;
291+ return searchableText . toUpperCase ( ) . includes ( upperValue ) ;
291292 } ;
292293
293294 tmpPropOptions ?. forEach ( ( option ) => {
294295 if ( isSelectOptionGroup ( option ) ) {
295- filteredOptions . push ( {
296- ...option ,
297- children : option . children ?. filter ( ( child ) => {
298- if ( filterMethods ( child ) ) {
299- filterLabels . push ( child . label ) ;
300- return true ;
301- }
302- return false ;
303- } ) ,
296+ const filteredChildren = option . children ?. filter ( ( child ) => {
297+ if ( filterMethods ( child ) ) {
298+ const searchableText = extractTextFromTNode ( child ?. label ) ;
299+ filterLabels . push ( searchableText ) ;
300+ return true ;
301+ }
302+ return false ;
304303 } ) ;
304+
305+ if ( filteredChildren && filteredChildren . length > 0 ) {
306+ filteredOptions . push ( {
307+ ...option ,
308+ children : filteredChildren ,
309+ } ) ;
310+ }
305311 } else if ( filterMethods ( option ) ) {
306- filterLabels . push ( option . label ) ;
312+ const searchableText = extractTextFromTNode ( option ?. label ) ;
313+ filterLabels . push ( searchableText ) ;
307314 filteredOptions . push ( option ) ;
308315 }
309316 } ) ;
@@ -367,6 +374,7 @@ const Select = forwardRefWithStatics(
367374 }
368375 return child ;
369376 } ) ;
377+
370378 // 渲染主体内容
371379 const renderContent = ( ) => {
372380 const popupContentProps = {
@@ -404,6 +412,7 @@ const Select = forwardRefWithStatics(
404412 }
405413 return ( { value : val } ) =>
406414 val . slice ( 0 , minCollapsedNum ? minCollapsedNum : val . length ) . map ( ( v : string , key : number ) => {
415+ const originalLabel = get ( selectedOptions [ key ] , keys ?. label || 'label' ) ;
407416 const filterOption : SelectOption & { disabled ?: boolean } = options ?. find ( ( option ) => option . label === v ) ;
408417 return (
409418 < Tag
@@ -438,7 +447,7 @@ const Select = forwardRefWithStatics(
438447 } ) ;
439448 } }
440449 >
441- { v }
450+ { originalLabel }
442451 </ Tag >
443452 ) ;
444453 } ) ;
0 commit comments