@@ -8,6 +8,7 @@ import KeywordTrigger from './KeywordTrigger';
88import { MentionsContextProvider } from './MentionsContext' ;
99import Option , { OptionProps } from './Option' ;
1010import {
11+ filterOption as defaultFilterOption ,
1112 getBeforeSelectionText ,
1213 getLastMeasureIndex ,
1314 replaceWithMeasure ,
@@ -27,6 +28,7 @@ export interface MentionsProps {
2728 autoFocus ?: boolean ;
2829 split ?: string ;
2930 validateSearch ?: typeof defaultValidateSearch ;
31+ filterOption ?: false | typeof defaultFilterOption ;
3032}
3133interface MentionsState {
3234 value : string ;
@@ -44,6 +46,7 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
4446 prefix : '@' ,
4547 split : ' ' ,
4648 validateSearch : defaultValidateSearch ,
49+ filterOption : defaultFilterOption ,
4750 } ;
4851
4952 public static getDerivedStateFromProps ( props : MentionsProps , prevState : MentionsState ) {
@@ -217,12 +220,16 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
217220 } ;
218221
219222 public getOptions = ( measureText ?: string ) : OptionProps [ ] => {
220- const targetMeasureText = ( measureText || this . state . measureText || '' ) . toLocaleLowerCase ( ) ;
221- const { children } = this . props ;
223+ const targetMeasureText = measureText || this . state . measureText || '' ;
224+ const { children, filterOption } = this . props ;
222225 const list = toArray ( children )
223226 . map ( ( { props } : { props : OptionProps } ) => props )
224- . filter ( ( { value = '' } : OptionProps ) => {
225- return value . toLowerCase ( ) . indexOf ( targetMeasureText ) !== - 1 ;
227+ . filter ( ( option : OptionProps ) => {
228+ /** Return all result if `filterOption` is false. */
229+ if ( filterOption === false ) {
230+ return true ;
231+ }
232+ return filterOption ! ( targetMeasureText , option ) ;
226233 } ) ;
227234 return list ;
228235 } ;
0 commit comments