-
Notifications
You must be signed in to change notification settings - Fork 358
fix(Input): avoid blur and focus when click icon #3996
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
RylanBot
wants to merge
7
commits into
develop
Choose a base branch
from
rylan/fix/input/blur
base: develop
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.
+41
−45
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2b5ae13
fix(Input): avoid blur and focus when click icon
RylanBot 8cde111
fix: add timeout for blur test
RylanBot 6775691
chore: remove redundant logic
RylanBot dc11c70
refactor: bind `onMouseDown` to the outer div
RylanBot 3bc92ee
Merge remote-tracking branch 'origin' into rylan/fix/input/blur
RylanBot be29357
fix(Input): prevent focus loss only on non-input elements
RylanBot da08bef
Merge remote-tracking branch 'origin' into rylan/fix/input/blur
RylanBot 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
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 |
|---|---|---|
|
|
@@ -37,7 +37,6 @@ export default function useMultiple(props: SelectInputProps) { | |
| const [tInputValue, setTInputValue] = useControlled(props, 'inputValue', props.onInputChange); | ||
|
|
||
| const tagInputRef = useRef<InputRef>(null); | ||
| const blurTimeoutRef = useRef(null); | ||
|
|
||
| const iKeys: SelectInputKeys = { ...DEFAULT_KEYS, ...props.keys }; | ||
|
|
||
|
|
@@ -61,30 +60,17 @@ export default function useMultiple(props: SelectInputProps) { | |
|
|
||
| const renderSelectMultiple = (p: RenderSelectMultipleParams) => { | ||
| const handleBlur = (value: SelectInputValue, context: { e: React.FocusEvent<HTMLInputElement> }) => { | ||
| if (blurTimeoutRef.current) { | ||
| clearTimeout(blurTimeoutRef.current); | ||
| if (!p.popupVisible) { | ||
| p.onInnerBlur(context); | ||
| } else if (!props.panel) { | ||
| props.onBlur?.(value, { e: context.e, inputValue: tInputValue, tagInputValue: tags }); | ||
| } | ||
| // 强制把 popupVisible 设置为 false 时,点击 input,会出现 blur -> focus 的情况,因此忽略前面短暂的 blur 事件 | ||
|
Collaborator
Author
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. 之前没搞懂的 blur → focus 的情况...这次找到了源头 |
||
| blurTimeoutRef.current = setTimeout(() => { | ||
| if (blurTimeoutRef.current) { | ||
| if (!p.popupVisible) { | ||
| p.onInnerBlur(context); | ||
| } else if (!props.panel) { | ||
| props.onBlur?.(value, { e: context.e, inputValue: tInputValue, tagInputValue: tags }); | ||
| } | ||
| } | ||
| blurTimeoutRef.current = null; | ||
| }, 150); | ||
| }; | ||
|
|
||
| const handleFocus = ( | ||
| val: TagInputValue, | ||
| context: { e: React.FocusEvent<HTMLInputElement>; inputValue: string }, | ||
| ) => { | ||
| if (blurTimeoutRef.current) { | ||
| clearTimeout(blurTimeoutRef.current); | ||
| blurTimeoutRef.current = null; | ||
| } | ||
| props.onFocus?.(props.value, { ...context, tagInputValue: val }); | ||
| }; | ||
|
|
||
|
|
||
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.
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.
handleMousedown 阻止默认行为估计会有很多没有考虑的影响 还是input这么底层的组件本身
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.
确实...原先的写法会导致 input 无法选中文本进行复制 🤔
我限制了一下范围...input 本体正常,只阻止其它 (div) 元素,影响应该还好 (?)