@@ -12,9 +12,10 @@ import {
1212 getLastMeasureIndex ,
1313 replaceWithMeasure ,
1414 setInputSelection ,
15+ validateSearch as defaultValidateSearch ,
1516} from './util' ;
1617
17- interface MentionsProps {
18+ export interface MentionsProps {
1819 defaultValue ?: string ;
1920 value ?: string ;
2021 onChange ?: ( text : string ) => void ;
@@ -24,6 +25,8 @@ interface MentionsProps {
2425 className ?: string ;
2526 style ?: React . CSSProperties ;
2627 autoFocus ?: boolean ;
28+ split ?: string ;
29+ validateSearch ?: typeof defaultValidateSearch ;
2730}
2831interface MentionsState {
2932 value : string ;
@@ -39,6 +42,8 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
3942 public static defaultProps = {
4043 prefixCls : 'rc-mentions' ,
4144 prefix : '@' ,
45+ split : ' ' ,
46+ validateSearch : defaultValidateSearch ,
4247 } ;
4348
4449 public static getDerivedStateFromProps ( props : MentionsProps , prevState : MentionsState ) {
@@ -135,21 +140,27 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
135140 public onKeyUp : React . KeyboardEventHandler < HTMLTextAreaElement > = event => {
136141 const { key, which } = event ;
137142 const { measureText : prevMeasureText , measuring } = this . state ;
138- const { prefix = '' , onSearch } = this . props ;
139- const selectionStartText = getBeforeSelectionText ( event . target as HTMLTextAreaElement ) ;
143+ const { prefix = '' , split = ' ' , onSearch, validateSearch } = this . props ;
144+ const target = event . target as HTMLTextAreaElement ;
145+ const selectionStartText = getBeforeSelectionText ( target ) ;
140146 const { location : measureIndex , prefix : measurePrefix } = getLastMeasureIndex (
141147 selectionStartText ,
142148 prefix ,
143149 ) ;
144150
145151 // Skip if match the white key list
146- if ( [ KeyCode . ESC , KeyCode . UP , KeyCode . DOWN ] . indexOf ( which ) !== - 1 ) {
152+ if ( [ KeyCode . ESC , KeyCode . UP , KeyCode . DOWN , KeyCode . ENTER ] . indexOf ( which ) !== - 1 ) {
153+ return ;
154+ }
155+
156+ // Skip if is the last one
157+ if ( KeyCode . RIGHT === which && target . selectionStart === target . value . length ) {
147158 return ;
148159 }
149160
150161 if ( measureIndex !== - 1 ) {
151162 const measureText = selectionStartText . slice ( measureIndex + measurePrefix . length ) ;
152- const validateMeasure = measureText . indexOf ( ' ' ) === - 1 ;
163+ const validateMeasure : boolean = validateSearch ! ( measureText , this . props ) ;
153164 const matchOption : boolean = ! ! this . getOptions ( measureText ) . length ;
154165
155166 if ( key === measurePrefix || measuring || ( measureText !== prevMeasureText && matchOption ) ) {
@@ -175,13 +186,15 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
175186
176187 public selectOption = ( option : OptionProps ) => {
177188 const { value, measureLocation, measurePrefix } = this . state ;
189+ const { split } = this . props ;
178190
179191 const { value : mentionValue = '' } = option ;
180192 const { text, selectionLocation } = replaceWithMeasure ( value , {
181193 measureLocation,
182194 targetText : mentionValue ,
183195 prefix : measurePrefix ,
184196 selectionStart : this . textarea ! . selectionStart ,
197+ split : split ! ,
185198 } ) ;
186199 this . triggerChange ( text ) ;
187200 this . stopMeasure ( ( ) => {
0 commit comments