Skip to content

Commit 53071ac

Browse files
committed
fix: blur should use latest onCancel
1 parent 68ceb33 commit 53071ac

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/hooks/usePickerInput.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export default function usePickerInput({
3434
* since this will repeat trigger `onOpenChange` event.
3535
*/
3636
const preventBlurRef = React.useRef<boolean>(false);
37+
const cancelRef = React.useRef({
38+
onCancel,
39+
});
40+
cancelRef.current.onCancel = onCancel;
3741

3842
const inputProps: React.DOMAttributes<HTMLInputElement> = {
3943
onMouseDown: () => {
@@ -98,7 +102,7 @@ export default function usePickerInput({
98102
if (blurToCancel) {
99103
setTimeout(() => {
100104
if (isClickOutside(document.activeElement)) {
101-
onCancel();
105+
cancelRef.current.onCancel();
102106
}
103107
}, 0);
104108
} else {

0 commit comments

Comments
 (0)