From f5669c694928d75bf45deb5864cb57bb46f255cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <7971419+crazyair@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:57:20 +0800 Subject: [PATCH] fix: search no scroll (#532) Co-authored-by: afc163 --- src/OptionList/Column.tsx | 4 +- src/OptionList/List.tsx | 6 ++- tests/index.spec.tsx | 81 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 6 deletions(-) diff --git a/src/OptionList/Column.tsx b/src/OptionList/Column.tsx index 82ec25c..5805ab1 100644 --- a/src/OptionList/Column.tsx +++ b/src/OptionList/Column.tsx @@ -23,7 +23,6 @@ export interface ColumnProps; loadingKeys: React.Key[]; isSelectable: (option: DefaultOptionType) => boolean; - searchValue?: string; } export default function Column({ @@ -39,7 +38,6 @@ export default function Column) { const menuPrefixCls = `${prefixCls}-menu`; const menuItemPrefixCls = `${prefixCls}-menu-item`; @@ -117,7 +115,7 @@ export default function Column { // >>>>> Open const triggerOpenPath = () => { - if (disabled || searchValue) { + if (disabled) { return; } const nextValueCells = [...fullPath]; diff --git a/src/OptionList/List.tsx b/src/OptionList/List.tsx index 4beedd0..0850b01 100644 --- a/src/OptionList/List.tsx +++ b/src/OptionList/List.tsx @@ -166,6 +166,9 @@ const RawOptionList = React.forwardRef(( // >>>>> Active Scroll React.useEffect(() => { + if (searchValue) { + return; + } for (let i = 0; i < activeValueCells.length; i += 1) { const cellPath = activeValueCells.slice(0, i + 1); const cellKeyPath = toPathKey(cellPath); @@ -176,7 +179,7 @@ const RawOptionList = React.forwardRef(( scrollIntoParentView(ele); } } - }, [activeValueCells]); + }, [activeValueCells, searchValue]); // ========================== Render ========================== // >>>>> Empty @@ -213,7 +216,6 @@ const RawOptionList = React.forwardRef(( { let selectedValue: any; @@ -1022,6 +1022,85 @@ describe('Cascader.Basic', () => { wrapper.find(`li[data-path-key]`).at(0).simulate('click'); wrapper.find(`li[data-path-key]`).at(1).simulate('click'); }); + it('hover + search', () => { + let getOffesetTopTimes = 0; + const spyElement = spyElementPrototypes(HTMLElement, { + offsetTop: { + get: () => (getOffesetTopTimes++ % 2 === 0 ? 100 : 0), + }, + scrollTop: { + get: () => 0, + }, + offsetHeight: { + get: () => 10, + }, + }); + + const wrapper = render( + , + ); + fireEvent.change(wrapper.container.querySelector('input') as HTMLElement, { + target: { value: 'w' }, + }); + const items = wrapper.container.querySelectorAll('.rc-cascader-menu-item'); + fireEvent.mouseEnter(items[9]); + expect(mockScrollTo).toHaveBeenCalledTimes(0); + + spyElement.mockRestore(); + }); }); it('not crash when value type is not array', () => {