@ -3,6 +3,7 @@ import RcMentions from 'rc-mentions';
import type {
MentionsProps as RcMentionsProps ,
MentionsRef as RcMentionsRef ,
DataDrivenOptionProps as MentionsOptionProps ,
} from 'rc-mentions/lib/Mentions' ;
import { composeRef } from 'rc-util/lib/ref' ;
import * as React from 'react' ;
@ -12,6 +13,7 @@ import { FormItemInputContext } from '../form/context';
import Spin from '../spin' ;
import type { InputStatus } from '../_util/statusUtils' ;
import { getMergedStatus , getStatusClassNames } from '../_util/statusUtils' ;
import warning from '../_util/warning' ;
export const { Option } = RcMentions ;
@ -21,6 +23,10 @@ function loadingFilterOption() {
export type MentionPlacement = 'top' | 'bottom' ;
export type {
DataDrivenOptionProps as MentionsOptionProps ,
} from 'rc-mentions/lib/Mentions' ;
export interface OptionProps {
value : string ;
children : React.ReactNode ;
@ -30,6 +36,7 @@ export interface OptionProps {
export interface MentionProps extends RcMentionsProps {
loading? : boolean ;
status? : InputStatus ;
options? : MentionsOptionProps [ ] ;
}
export interface MentionsRef extends RcMentionsRef { }
@ -63,6 +70,7 @@ const InternalMentions: React.ForwardRefRenderFunction<MentionsRef, MentionProps
filterOption ,
children ,
notFoundContent ,
options ,
status : customStatus ,
. . . restProps
} ,
@ -71,6 +79,16 @@ const InternalMentions: React.ForwardRefRenderFunction<MentionsRef, MentionProps
const [ focused , setFocused ] = React . useState ( false ) ;
const innerRef = React . useRef < MentionsRef > ( ) ;
const mergedRef = composeRef ( ref , innerRef ) ;
// =================== Warning =====================
if ( process . env . NODE_ENV !== 'production' ) {
warning (
! children ,
'Mentions' ,
'`Mentions.Option` is deprecated. Please use `options` instead.' ,
) ;
}
const { getPrefixCls , renderEmpty , direction } = React . useContext ( ConfigContext ) ;
const {
status : contextStatus ,
@ -114,6 +132,16 @@ const InternalMentions: React.ForwardRefRenderFunction<MentionsRef, MentionProps
return children ;
} ;
const mergedOptions = loading
? [
{
value : 'ANTD_SEARCHING' ,
disabled : true ,
label : < Spin size = "small" / > ,
} ,
]
: options ;
const getFilterOption = ( ) : any = > {
if ( loading ) {
return loadingFilterOption ;
@ -145,6 +173,7 @@ const InternalMentions: React.ForwardRefRenderFunction<MentionsRef, MentionProps
onFocus = { onFocus }
onBlur = { onBlur }
ref = { mergedRef as any }
options = { mergedOptions }
>
{ getOptions ( ) }
< / RcMentions >
@ -185,7 +214,7 @@ Mentions.getMentions = (value: string = '', config: MentionsConfig = {}): Mentio
. map ( ( str = '' ) : MentionsEntity | null = > {
let hitPrefix : string | null = null ;
prefixList . some ( prefixStr = > {
prefixList . some ( ( prefixStr ) = > {
const startStr = str . slice ( 0 , prefixStr . length ) ;
if ( startStr === prefixStr ) {
hitPrefix = prefixStr ;