Skip to content

Commit 976a7e9

Browse files
committed
fix: blur should use latest onCancel again
1 parent 9f818a2 commit 976a7e9

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/hooks/usePickerInput.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ 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;
4137

4238
const inputProps: React.DOMAttributes<HTMLInputElement> = {
4339
onMouseDown: () => {
@@ -102,7 +98,7 @@ export default function usePickerInput({
10298
if (blurToCancel) {
10399
setTimeout(() => {
104100
if (isClickOutside(document.activeElement)) {
105-
cancelRef.current.onCancel();
101+
onCancel();
106102
}
107103
}, 0);
108104
} else {

src/hooks/useTextValueMapping.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ export default function useTextValueMapping<ValueType>({
99
onTextChange: (text: string) => void;
1010
}): [string, (text: string) => void, () => void] {
1111
const [text, setInnerText] = React.useState('');
12+
const valueTextsRef = React.useRef<string[]>([]);
13+
valueTextsRef.current = valueTexts;
1214

1315
function triggerTextChange(value: string) {
1416
setInnerText(value);
1517
onTextChange(value);
1618
}
1719

1820
function resetText() {
19-
setInnerText(valueTexts[0]);
21+
setInnerText(valueTextsRef.current[0]);
2022
}
2123

2224
React.useEffect(() => {

0 commit comments

Comments
 (0)