Skip to content
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

fix(CustomSelect): Fix input focus on arrow click on touch device #7816

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions packages/vkui/src/components/CustomSelect/CustomSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -707,19 +707,6 @@ export function CustomSelect<OptionInterfaceT extends CustomSelectOptionInterfac
}, [emptyText, options, renderDropdown, renderOption]);

const selectInputRef = useExternRef(getSelectInputRef);
const focusOnInputTimerRef = React.useRef<ReturnType<typeof setTimeout>>();
const focusOnInput = React.useCallback(() => {
clearTimeout(focusOnInputTimerRef.current);

focusOnInputTimerRef.current = setTimeout(() => {
selectInputRef.current && selectInputRef.current.focus();
}, 0);
}, [selectInputRef]);
useIsomorphicLayoutEffect(function clearFocusOnInputTimer() {
return () => {
clearTimeout(focusOnInputTimerRef.current);
};
}, []);

const controlledValueSet = isControlledOutside && props.value !== '';
const uncontrolledValueSet = !isControlledOutside && nativeSelectValue !== '';
Expand All @@ -737,7 +724,7 @@ export function CustomSelect<OptionInterfaceT extends CustomSelectOptionInterfac
onClick={function clearSelectState() {
setNativeSelectValue('');
setInputValue('');
focusOnInput();
selectInputRef.current && selectInputRef.current.focus();
}}
disabled={restProps.disabled}
data-testid={clearButtonTestId}
Expand All @@ -749,7 +736,7 @@ export function CustomSelect<OptionInterfaceT extends CustomSelectOptionInterfac
iconProp,
restProps.disabled,
clearButtonTestId,
focusOnInput,
selectInputRef,
]);

const icon = React.useMemo(() => {
Expand Down Expand Up @@ -794,11 +781,11 @@ export function CustomSelect<OptionInterfaceT extends CustomSelectOptionInterfac

const inputIsNotFocused = document.activeElement !== selectInputRef.current;
if (inputIsNotFocused) {
focusOnInput();
selectInputRef.current.focus();
}
}
},
[document, focusOnInput, selectInputRef],
[document, selectInputRef],
);

const preventInputBlurWhenClickInsideFocusedSelectArea = (
Expand Down
Loading