From 87f613c5d5a8b1b0f329a5218b29b5f115cc0729 Mon Sep 17 00:00:00 2001 From: atzcl Date: Mon, 16 Nov 2020 21:14:49 +0800 Subject: [PATCH 01/12] fix(typings): add onDropdownVisibleChange type --- src/TreeSelect.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TreeSelect.tsx b/src/TreeSelect.tsx index 4701ad4d..2e1cbafe 100644 --- a/src/TreeSelect.tsx +++ b/src/TreeSelect.tsx @@ -155,6 +155,7 @@ export interface TreeSelectProps onChange?: (value: ValueType, labelList: React.ReactNode[], extra: ChangeEventExtra) => void; onTreeExpand?: (expandedKeys: Key[]) => void; onTreeLoad?: (loadedKeys: Key[]) => void; + onDropdownVisibleChange?: (open: boolean) => void; // Legacy /** `searchPlaceholder` has been removed since search box has been merged into input box */ From fcebb886669ed37eb01f1ec50fa3cc6ddd7e576c Mon Sep 17 00:00:00 2001 From: atzcl Date: Tue, 17 Nov 2020 16:13:36 +0800 Subject: [PATCH 02/12] feat: mount scrollTo on ref --- src/OptionList.tsx | 9 ++++++--- src/TreeSelect.tsx | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/OptionList.tsx b/src/OptionList.tsx index a3e9a986..7d2080a9 100644 --- a/src/OptionList.tsx +++ b/src/OptionList.tsx @@ -3,7 +3,7 @@ import KeyCode from 'rc-util/lib/KeyCode'; import useMemo from 'rc-util/lib/hooks/useMemo'; import { RefOptionListProps } from 'rc-select/lib/OptionList'; import Tree, { TreeProps } from 'rc-tree'; -import { EventDataNode } from 'rc-tree/lib/interface'; +import { EventDataNode, ScrollTo } from 'rc-tree/lib/interface'; import { FlattenDataNode, RawValueType, DataNode, TreeDataNode, Key } from './interface'; import { SelectContext } from './Context'; import useKeyValueMapping from './hooks/useKeyValueMapping'; @@ -52,7 +52,9 @@ export interface OptionListProps { onMouseEnter: () => void; } -const OptionList: React.RefForwardingComponent> = ( +type ReviseRefOptionListProps = Omit & { scrollTo: ScrollTo }; + +const OptionList: React.RefForwardingComponent> = ( props, ref, ) => { @@ -190,6 +192,7 @@ const OptionList: React.RefForwardingComponent ({ + scrollTo: treeRef.current.scrollTo, onKeyDown: event => { const { which } = event; switch (which) { @@ -280,7 +283,7 @@ const OptionList: React.RefForwardingComponent>(OptionList); +const RefOptionList = React.forwardRef>(OptionList); RefOptionList.displayName = 'OptionList'; export default RefOptionList; diff --git a/src/TreeSelect.tsx b/src/TreeSelect.tsx index 2e1cbafe..817d95d1 100644 --- a/src/TreeSelect.tsx +++ b/src/TreeSelect.tsx @@ -202,6 +202,7 @@ const RefTreeSelect = React.forwardRef((props, const selectRef = React.useRef(null); React.useImperativeHandle(ref, () => ({ + scrollTo: selectRef.current.scrollTo, focus: selectRef.current.focus, blur: selectRef.current.blur, })); From ff26bb733ed26a3c7fb249329d7bf7bd818c3804 Mon Sep 17 00:00:00 2001 From: atzcl Date: Tue, 17 Nov 2020 16:35:27 +0800 Subject: [PATCH 03/12] fix: lint error --- src/OptionList.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/OptionList.tsx b/src/OptionList.tsx index 7d2080a9..f6de71cf 100644 --- a/src/OptionList.tsx +++ b/src/OptionList.tsx @@ -54,10 +54,10 @@ export interface OptionListProps { type ReviseRefOptionListProps = Omit & { scrollTo: ScrollTo }; -const OptionList: React.RefForwardingComponent> = ( - props, - ref, -) => { +const OptionList: React.RefForwardingComponent< + ReviseRefOptionListProps, + OptionListProps +> = (props, ref) => { const { prefixCls, height, @@ -283,7 +283,9 @@ const OptionList: React.RefForwardingComponent>(OptionList); +const RefOptionList = React.forwardRef>( + OptionList, +); RefOptionList.displayName = 'OptionList'; export default RefOptionList; From e3510b010d6a99872ecddc87b5c249ee8af8f20e Mon Sep 17 00:00:00 2001 From: zombiej Date: Wed, 18 Nov 2020 11:12:06 +0800 Subject: [PATCH 04/12] 4.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e65e6b4b..2702bfaf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-tree-select", - "version": "4.1.2", + "version": "4.1.3", "description": "tree-select ui component for react", "keywords": [ "react", From ac2f1b9fdacc7633639975835a7cafe6c745c410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 30 Nov 2020 11:22:03 +0800 Subject: [PATCH 05/12] chore: Bump tree (#303) * test: Update snapshot * test: Fix select test cae --- package.json | 2 +- tests/Select.checkable.spec.js | 48 ++---- tests/Select.spec.js | 1 + .../Select.checkable.spec.js.snap | 68 +++++++++ tests/__snapshots__/Select.spec.js.snap | 139 ++++++++++++++++++ 5 files changed, 222 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index 2702bfaf..9a68bdde 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "@babel/runtime": "^7.10.1", "classnames": "2.x", "rc-select": "^11.1.1", - "rc-tree": "^3.8.0", + "rc-tree": "^4.0.0", "rc-util": "^5.0.5" } } diff --git a/tests/Select.checkable.spec.js b/tests/Select.checkable.spec.js index 184e0992..fad39e94 100644 --- a/tests/Select.checkable.spec.js +++ b/tests/Select.checkable.spec.js @@ -117,11 +117,7 @@ describe('TreeSelect.checkable', () => { onChange={this.handleChange} disabled={disabled} /> - this.switch(e.target.checked)} - id="checkbox" - />{' '} + this.switch(e.target.checked)} id="checkbox" />{' '} 禁用 ); @@ -335,9 +331,7 @@ describe('TreeSelect.checkable', () => { ], }, ]; - const wrapper = mount( - , - ); + const wrapper = mount(); wrapper.search('58'); wrapper.selectNode(2); expect(wrapper.getSelection()).toHaveLength(1); @@ -402,11 +396,7 @@ describe('TreeSelect.checkable', () => { wrapper.search('0-0'); wrapper.selectNode(0); - expect(onChange).toHaveBeenCalledWith( - ['0-1-0', '0-1-2'], - expect.anything(), - expect.anything(), - ); + expect(onChange).toHaveBeenCalledWith(['0-1-0', '0-1-2'], expect.anything(), expect.anything()); }); // https://github.com/ant-design/ant-design/issues/13328 @@ -443,11 +433,7 @@ describe('TreeSelect.checkable', () => { wrapper.search('0-0-1'); wrapper.selectNode(1); - expect(onChange).toHaveBeenCalledWith( - ['0-0-1'], - expect.anything(), - expect.anything(), - ); + expect(onChange).toHaveBeenCalledWith(['0-0-1'], expect.anything(), expect.anything()); expect( wrapper @@ -615,14 +601,10 @@ describe('TreeSelect.checkable', () => { }, ]; - const wrapper = mount( - , - ); + const wrapper = mount(); expect(wrapper.getSelection().length).toBeTruthy(); - expect( - wrapper.find('.rc-tree-select-selection-item-remove').length, - ).toBeFalsy(); + expect(wrapper.find('.rc-tree-select-selection-item-remove').length).toBeFalsy(); }); it('treeCheckStrictly can set halfChecked', () => { @@ -634,26 +616,22 @@ describe('TreeSelect.checkable', () => { value={[{ value: 'half', halfChecked: true }]} open onChange={onChange} - treeData={[ - { value: 'half', title: 'Half Check' }, - { value: 'full', title: 'Full Check' }, - ]} + treeData={[{ value: 'half', title: 'Half Check' }, { value: 'full', title: 'Full Check' }]} />, ); function getTreeNode(index) { - return wrapper.find('.rc-tree-select-tree-treenode').at(index); + return wrapper + .find('.rc-tree-select-tree-treenode') + .not('[aria-hidden]') + .at(index); } expect( - getTreeNode(0).hasClass( - 'rc-tree-select-tree-treenode-checkbox-indeterminate', - ), + getTreeNode(0).hasClass('rc-tree-select-tree-treenode-checkbox-indeterminate'), ).toBeTruthy(); expect( - getTreeNode(1).hasClass( - 'rc-tree-select-tree-treenode-checkbox-indeterminate', - ), + getTreeNode(1).hasClass('rc-tree-select-tree-treenode-checkbox-indeterminate'), ).toBeFalsy(); wrapper.selectNode(1); diff --git a/tests/Select.spec.js b/tests/Select.spec.js index a5ad656f..806c8753 100644 --- a/tests/Select.spec.js +++ b/tests/Select.spec.js @@ -313,6 +313,7 @@ describe('TreeSelect.basic', () => { expect( wrapper .find('.rc-tree-select-tree-treenode') + .not('[aria-hidden]') .at(1) .hasClass('rc-tree-select-tree-treenode-switcher-open'), ).toBeTruthy(); diff --git a/tests/__snapshots__/Select.checkable.spec.js.snap b/tests/__snapshots__/Select.checkable.spec.js.snap index 205a8e54..7c61d2a8 100644 --- a/tests/__snapshots__/Select.checkable.spec.js.snap +++ b/tests/__snapshots__/Select.checkable.spec.js.snap @@ -116,6 +116,19 @@ exports[`TreeSelect.checkable uncheck remove by selector not treeCheckStrictly 1 value="" /> +