-
-
Notifications
You must be signed in to change notification settings - Fork 486
chore: adjust open order #1169
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
chore: adjust open order #1169
Changes from all 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 |
|---|---|---|
|
|
@@ -570,7 +570,9 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref) | |
| } | ||
|
|
||
| if (!disabled) { | ||
| triggerOpen(false); | ||
| triggerOpen(false, { | ||
| lazy: true, | ||
| }); | ||
| onBlur?.(event); | ||
| } | ||
| }; | ||
|
|
@@ -582,7 +584,9 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref) | |
| // We should give focus back to selector if clicked item is not focusable | ||
| if (popupElement?.contains(target as HTMLElement) && triggerOpen) { | ||
| // Tell `open` not to close since it's safe in the popup | ||
| triggerOpen(true, true); | ||
| triggerOpen(true, { | ||
| ignoreNext: true, | ||
| }); | ||
|
Comment on lines
586
to
+589
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. |
||
| } | ||
|
|
||
| onMouseDown?.(event, ...restArgs); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,13 @@ const macroTask = (fn: VoidFunction, times = 1) => { | |
| * Trigger by latest open call, if nextOpen is undefined, means toggle. | ||
| * ignoreNext will skip next call in the macro task queue. | ||
| */ | ||
| export type TriggerOpenType = (nextOpen?: boolean, ignoreNext?: boolean) => void; | ||
| export type TriggerOpenType = ( | ||
| nextOpen?: boolean, | ||
| config?: { | ||
| ignoreNext?: boolean; | ||
| lazy?: boolean; | ||
| }, | ||
| ) => void; | ||
|
Comment on lines
+25
to
+31
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. |
||
|
|
||
| /** | ||
| * When `open` is controlled, follow the controlled value; | ||
|
|
@@ -61,30 +67,34 @@ export default function useOpen( | |
| internalSetOpen(nextOpen); | ||
| }); | ||
|
|
||
| const toggleOpen = useEvent<TriggerOpenType>((nextOpen?: boolean, ignoreNext = false) => { | ||
| const toggleOpen = useEvent<TriggerOpenType>((nextOpen, config = {}) => { | ||
| const { ignoreNext = false, lazy = false } = config; | ||
|
|
||
|
Comment on lines
+70
to
+72
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. |
||
| taskIdRef.current += 1; | ||
| const id = taskIdRef.current; | ||
|
|
||
| const nextOpenVal = typeof nextOpen === 'boolean' ? nextOpen : !mergedOpen; | ||
|
|
||
| // Since `mergedOpen` is post-processed, we need to check if the value really changed | ||
| if (nextOpenVal) { | ||
| triggerEvent(true); | ||
|
|
||
| // Lock if needed | ||
| if (ignoreNext) { | ||
| taskLockRef.current = ignoreNext; | ||
|
|
||
| macroTask(() => { | ||
| taskLockRef.current = false; | ||
| }, 2); | ||
| if (nextOpenVal || !lazy) { | ||
| if (!taskLockRef.current) { | ||
| triggerEvent(nextOpenVal); | ||
|
|
||
| // Lock if needed | ||
| if (ignoreNext) { | ||
| taskLockRef.current = ignoreNext; | ||
|
|
||
| macroTask(() => { | ||
| taskLockRef.current = false; | ||
| }, 2); | ||
| } | ||
| } | ||
|
Comment on lines
+79
to
91
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. The logic for opening the dropdown has been modified to include a check for the |
||
| return; | ||
| } | ||
|
|
||
| macroTask(() => { | ||
| if (id === taskIdRef.current && !taskLockRef.current) { | ||
| triggerEvent(false); | ||
| triggerEvent(nextOpenVal); | ||
|
Comment on lines
95
to
+97
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 comment
The reason will be displayed to describe this comment to others. Learn more.
The
triggerOpenfunction is now called with alazyoption set totrue. This introduces a delay in closing the dropdown on blur. Ensure this delay does not negatively impact the user experience, especially in scenarios where immediate feedback is expected.