From 49ff4b9810fdf0aa84e383737ef2b4abd0f02c52 Mon Sep 17 00:00:00 2001 From: hextion <100ishundred@gmail.com> Date: Wed, 17 Jul 2024 12:07:08 +0300 Subject: [PATCH] fix(select): fixed scroll on item click with search enabled on Safari --- .changeset/plenty-peaches-shop.md | 5 +++++ .../src/components/base-select/Component.tsx | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 .changeset/plenty-peaches-shop.md diff --git a/.changeset/plenty-peaches-shop.md b/.changeset/plenty-peaches-shop.md new file mode 100644 index 0000000000..a48c0986f4 --- /dev/null +++ b/.changeset/plenty-peaches-shop.md @@ -0,0 +1,5 @@ +--- +'@alfalab/core-components-select': patch +--- + +Исправлен скролл при клике на вариант выбора в браузере Safari diff --git a/packages/select/src/components/base-select/Component.tsx b/packages/select/src/components/base-select/Component.tsx index 87e9bf22c6..1fa81331c6 100644 --- a/packages/select/src/components/base-select/Component.tsx +++ b/packages/select/src/components/base-select/Component.tsx @@ -50,10 +50,10 @@ const itemToString = (option: OptionShape | null) => (option ? option.key : ''); const isItemDisabled = (option: OptionShape | null) => Boolean(option?.disabled); -export const BaseSelect = forwardRef( +export const BaseSelect = forwardRef( // TODO: 😭 // eslint-disable-next-line complexity - (props: ComponentProps, ref) => { + (props, ref) => { const { dataTestId, className, @@ -108,7 +108,7 @@ export const BaseSelect = forwardRef( bottomSheetProps, limitDynamicOptionGroupSize, } = props; - + const shouldSearchBlurRef = useRef(true); const rootRef = useRef(null); const fieldRef = useRef(null); const listRef = useRef(null); @@ -436,6 +436,13 @@ export const BaseSelect = forwardRef( index, item: option, onMouseDown: (event: MouseEvent) => event.preventDefault(), + onClick: () => { + if (view === 'mobile' || !showSearch || multiple) return; + shouldSearchBlurRef.current = false; + searchRef.current?.blur(); + shouldSearchBlurRef.current = true; + fieldRef.current?.focus(); + }, }), multiple, index, @@ -533,6 +540,7 @@ export const BaseSelect = forwardRef( }; const handleBlur = (event: FocusEvent) => { + if (!shouldSearchBlurRef.current) return; searchProps.componentProps?.onBlur?.(event); handleFieldBlur(event); };