-
-
Notifications
You must be signed in to change notification settings - Fork 481
fix: blur should not trigger close when next activeElement still is input ref #1175
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
Changes from 2 commits
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 | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { clsx } from 'clsx'; | |||||||||||||||||||||||||||||||||||||||||||
| import type { ComponentsConfig } from '../hooks/useComponents'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { getDOM } from '@rc-component/util/lib/Dom/findDOMNode'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { composeRef } from '@rc-component/util/lib/ref'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { macroTask } from '../hooks/useOpen'; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| export interface SelectInputRef { | ||||||||||||||||||||||||||||||||||||||||||||
| focus: (options?: FocusOptions) => void; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -197,7 +198,13 @@ export default React.forwardRef<SelectInputRef, SelectInputProps>(function Selec | |||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const onInternalBlur: SelectInputProps['onBlur'] = (event) => { | ||||||||||||||||||||||||||||||||||||||||||||
| toggleOpen(false); | ||||||||||||||||||||||||||||||||||||||||||||
| macroTask(() => { | ||||||||||||||||||||||||||||||||||||||||||||
| const inputNode = getDOM(inputRef.current); | ||||||||||||||||||||||||||||||||||||||||||||
| if (inputNode !== document.activeElement && !inputNode.contains(document.activeElement)) { | ||||||||||||||||||||||||||||||||||||||||||||
| toggleOpen(false); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| onBlur?.(event); | ||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
200
to
212
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. blur 处理逻辑修复了焦点转移问题,但需要添加空值检查。 使用 但是, 应用以下 diff 添加空值检查: const onInternalBlur: SelectInputProps['onBlur'] = (event) => {
macroTask(() => {
const inputNode = getDOM(inputRef.current);
- if (inputNode !== document.activeElement && !inputNode.contains(document.activeElement)) {
+ if (inputNode && inputNode !== document.activeElement && !inputNode.contains(document.activeElement)) {
toggleOpen(false);
}
});
onBlur?.(event);
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
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.
This commented-out code is no longer necessary since the logic for closing the dropdown on blur has been moved to the
SelectInputcomponent. It should be removed to improve code clarity.