-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support mentions onece delete #48389
base: feature
Are you sure you want to change the base?
Changes from 3 commits
d6c7b4e
53323e9
78d6fb3
2ebf56e
b6050fc
d09f34c
733cc88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import type { Variant } from '../form/hooks/useVariants'; | |
import useVariant from '../form/hooks/useVariants'; | ||
import Spin from '../spin'; | ||
import useStyle from './style'; | ||
import KeyCode from 'rc-util/lib/KeyCode'; | ||
|
||
export const { Option } = RcMentions; | ||
|
||
|
@@ -45,6 +46,7 @@ export interface MentionProps extends Omit<RcMentionsProps, 'suffix'> { | |
status?: InputStatus; | ||
options?: MentionsOptionProps[]; | ||
popupClassName?: string; | ||
itemOnceDelete?: boolean; | ||
/** | ||
* @since 5.13.0 | ||
* @default "outlined" | ||
|
@@ -75,13 +77,15 @@ const InternalMentions = React.forwardRef<MentionsRef, MentionProps>((props, ref | |
children, | ||
notFoundContent, | ||
options, | ||
itemOnceDelete = false, | ||
status: customStatus, | ||
allowClear = false, | ||
popupClassName, | ||
style, | ||
variant: customVariant, | ||
...restProps | ||
} = props; | ||
const [data, setData] = React.useState<string>(props.value ?? props.defaultValue ?? ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const [focused, setFocused] = React.useState(false); | ||
const innerRef = React.useRef<MentionsRef>(null); | ||
const mergedRef = composeRef(ref, innerRef); | ||
|
@@ -121,6 +125,18 @@ const InternalMentions = React.forwardRef<MentionsRef, MentionProps>((props, ref | |
setFocused(false); | ||
}; | ||
|
||
const onChange = (value: string) => { | ||
setData(value); | ||
}; | ||
|
||
const onKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => { | ||
if (e.keyCode === KeyCode.BACKSPACE && itemOnceDelete) { | ||
if (data) { | ||
setData(data.split('@').slice(0, -1).join('@')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. working on it |
||
} | ||
} | ||
}; | ||
|
||
const notFoundContentEle = React.useMemo<React.ReactNode>(() => { | ||
if (notFoundContent !== undefined) { | ||
return notFoundContent; | ||
|
@@ -181,8 +197,11 @@ const InternalMentions = React.forwardRef<MentionsRef, MentionProps>((props, ref | |
allowClear={mergedAllowClear} | ||
direction={direction} | ||
style={{ ...contextMentions?.style, ...style }} | ||
value={data} | ||
{...restProps} | ||
filterOption={mentionsfilterOption} | ||
onKeyDown={onKeyDown} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 事件丢了,应该还需要透一下 |
||
onChange={onChange} | ||
onFocus={onFocus} | ||
onBlur={onBlur} | ||
dropdownClassName={classNames(popupClassName, rootClassName, hashId, cssVarCls, rootCls)} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 prop 不符合 antd 的 naming standard,可以先看看现有的 API 命名有没有可以复用的