-
-
Notifications
You must be signed in to change notification settings - Fork 937
feat(Sender): tag slot add clear btn #1317
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
Open
IsDyh01
wants to merge
7
commits into
ant-design:next
Choose a base branch
from
IsDyh01:feat/tag-add-clear-btn
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
35675fd
feat(Sender): tag slot add clear btn
IsDyh01 3d20d90
docs(Sender): update tag slot docs
IsDyh01 ad19484
fix(docs): fix docs
IsDyh01 b8be7f8
test: add test case
IsDyh01 59dfe1a
fix: delete log
IsDyh01 6e3d0a4
test: add test case
IsDyh01 a616827
Merge branch 'next' into feat/tag-add-clear-btn
kimteayon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||
| import { CaretDownFilled } from '@ant-design/icons'; | ||||||||||||||
| import { CaretDownFilled, CloseOutlined } from '@ant-design/icons'; | ||||||||||||||
| import { Dropdown, Input, InputRef } from 'antd'; | ||||||||||||||
| import classnames from 'classnames'; | ||||||||||||||
| import pickAttrs from 'rc-util/lib/pickAttrs'; | ||||||||||||||
|
|
@@ -137,6 +137,29 @@ const SlotTextArea = React.forwardRef<SlotTextAreaRef>((_, ref) => { | |||||||||||||
| } | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| const removeTagSlot = (key: string, e?: EventType) => { | ||||||||||||||
| const span = getSlotDom(key); | ||||||||||||||
| if (span && editableRef.current && editableRef.current.contains(span)) { | ||||||||||||||
| editableRef.current.removeChild(span); | ||||||||||||||
| } | ||||||||||||||
| slotDomMap.current.delete(key); | ||||||||||||||
| // 移除配置与值 | ||||||||||||||
| slotConfigRef.current = (slotConfigRef.current || []).filter((item) => item.key !== key); | ||||||||||||||
| setSlotValues((prev) => { | ||||||||||||||
| const next = { ...prev }; | ||||||||||||||
| delete next[key]; | ||||||||||||||
| return next; | ||||||||||||||
| }); | ||||||||||||||
| setSlotPlaceholders((prev) => { | ||||||||||||||
| const next = new Map(prev); | ||||||||||||||
| next.delete(key); | ||||||||||||||
| return next; | ||||||||||||||
| }); | ||||||||||||||
| // 触发 onChange | ||||||||||||||
| const newValue = getEditorValue(); | ||||||||||||||
| onChange?.(newValue.value, e, newValue.config); | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| const renderSlot = (node: SlotConfigType, slotSpan: HTMLSpanElement) => { | ||||||||||||||
| if (!node.key) return null; | ||||||||||||||
| const value = getSlotValues()[node.key]; | ||||||||||||||
|
|
@@ -194,8 +217,38 @@ const SlotTextArea = React.forwardRef<SlotTextAreaRef>((_, ref) => { | |||||||||||||
| </span> | ||||||||||||||
| </Dropdown> | ||||||||||||||
| ); | ||||||||||||||
| case 'tag': | ||||||||||||||
| return <div className={`${prefixCls}-slot-tag`}>{node.props?.label || ''}</div>; | ||||||||||||||
| case 'tag': { | ||||||||||||||
| const allowClear = | ||||||||||||||
| typeof node.props?.allowClear === 'boolean' | ||||||||||||||
| ? node.props?.allowClear | ||||||||||||||
| : node.props?.allowClear?.clearIcon; | ||||||||||||||
| const clearIcon = | ||||||||||||||
| typeof node.props?.allowClear === 'object' ? ( | ||||||||||||||
| node.props?.allowClear?.clearIcon ? ( | ||||||||||||||
| node.props?.allowClear?.clearIcon | ||||||||||||||
| ) : ( | ||||||||||||||
| <CloseOutlined /> | ||||||||||||||
| ) | ||||||||||||||
| ) : ( | ||||||||||||||
| <CloseOutlined /> | ||||||||||||||
| ); | ||||||||||||||
| return ( | ||||||||||||||
| <div className={`${prefixCls}-slot-tag`}> | ||||||||||||||
| <span className={`${prefixCls}-slot-tag-label`}>{node.props?.label || ''}</span> | ||||||||||||||
| {!readOnly && allowClear && ( | ||||||||||||||
| <span | ||||||||||||||
| className={`${prefixCls}-slot-tag-clear-icon`} | ||||||||||||||
| onMouseDown={(e) => e.preventDefault()} | ||||||||||||||
| onClick={(e) => { | ||||||||||||||
| removeTagSlot(node.key as string, e as unknown as EventType); | ||||||||||||||
| }} | ||||||||||||||
|
Comment on lines
+242
to
+244
Contributor
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. Following the change in
Suggested change
|
||||||||||||||
| > | ||||||||||||||
| {clearIcon} | ||||||||||||||
| </span> | ||||||||||||||
| )} | ||||||||||||||
| </div> | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| case 'custom': | ||||||||||||||
| return node.customRender?.( | ||||||||||||||
| value, | ||||||||||||||
|
|
@@ -318,6 +371,7 @@ const SlotTextArea = React.forwardRef<SlotTextAreaRef>((_, ref) => { | |||||||||||||
| } | ||||||||||||||
| const currentRange = selection?.rangeCount > 0 ? selection?.getRangeAt?.(0) : null; | ||||||||||||||
| const range = lastSelectionRef.current || currentRange; | ||||||||||||||
|
|
||||||||||||||
| if (range) { | ||||||||||||||
| if ((range.endContainer as HTMLElement)?.className?.includes(`${prefixCls}-slot`)) { | ||||||||||||||
| return { | ||||||||||||||
|
|
@@ -468,6 +522,7 @@ const SlotTextArea = React.forwardRef<SlotTextAreaRef>((_, ref) => { | |||||||||||||
| if (!editableDom || !selection) return; | ||||||||||||||
| const slotNode = getSlotListNode(slotConfig); | ||||||||||||||
| const { type, range: lastRage } = getInsertPosition(position); | ||||||||||||||
|
|
||||||||||||||
| let range: Range = document.createRange(); | ||||||||||||||
| slotConfigRef.current = [...slotConfigRef.current, ...slotConfig]; | ||||||||||||||
| setSlotValues(slotConfig); | ||||||||||||||
|
|
||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.