diff --git a/examples/basic.tsx b/examples/basic.tsx index 4ccc7bb1..4a3b124b 100644 --- a/examples/basic.tsx +++ b/examples/basic.tsx @@ -134,8 +134,7 @@ class Demo extends React.Component { return true; }; - filterTreeNode = (input, child) => - String(child.props.title).indexOf(input) === 0; + filterTreeNode = (input, child) => String(child.props.title).indexOf(input) === 0; render() { const { @@ -152,11 +151,7 @@ class Demo extends React.Component { return (

tree-select in dialog

- {visible ? ( @@ -280,7 +275,7 @@ class Demo extends React.Component { showCheckedStrategy={SHOW_PARENT} onChange={this.onChange} onSelect={this.onSelect} - maxTagCount={2} + maxTagCount="responsive" maxTagPlaceholder={valueList => { console.log('Max Tag Rest Value:', valueList); return `${valueList.length} rest...`; @@ -368,12 +363,7 @@ class Demo extends React.Component { - + { onMouseEnter: () => void; } -const OptionList: React.RefForwardingComponent> = ( - props, - ref, -) => { +type ReviseRefOptionListProps = Omit & { scrollTo: ScrollTo }; + +const OptionList: React.RefForwardingComponent< + ReviseRefOptionListProps, + OptionListProps +> = (props, ref) => { const { prefixCls, height, @@ -190,6 +192,7 @@ const OptionList: React.RefForwardingComponent ({ + scrollTo: treeRef.current?.scrollTo, onKeyDown: event => { const { which } = event; switch (which) { @@ -280,7 +283,9 @@ 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..6d7ac9c6 100644 --- a/src/TreeSelect.tsx +++ b/src/TreeSelect.tsx @@ -124,8 +124,6 @@ export interface TreeSelectProps searchValue?: string; autoClearSearchValue?: boolean; - maxTagTextLength?: number; - maxTagCount?: number; maxTagPlaceholder?: (omittedValues: LabelValueType[]) => React.ReactNode; loadData?: (dataNode: LegacyDataNode) => Promise; @@ -202,6 +200,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, })); diff --git a/src/utils/valueUtil.ts b/src/utils/valueUtil.ts index 7701a8c4..760504b8 100644 --- a/src/utils/valueUtil.ts +++ b/src/utils/valueUtil.ts @@ -13,6 +13,8 @@ import { import { fillLegacyProps } from './legacyUtil'; import { SkipType } from '../hooks/useKeyValueMapping'; +type CompatibleDataNode = Omit; + export function toArray(value: T | T[]): T[] { if (Array.isArray(value)) { return value; @@ -20,7 +22,7 @@ export function toArray(value: T | T[]): T[] { return value !== undefined ? [value] : []; } -export function findValueOption(values: RawValueType[], options: FlattenDataNode[]): DataNode[] { +export function findValueOption(values: RawValueType[], options: CompatibleDataNode[]): DataNode[] { const optionMap: Map = new Map(); options.forEach(flattenItem => { @@ -31,7 +33,7 @@ export function findValueOption(values: RawValueType[], options: FlattenDataNode return values.map(val => fillLegacyProps(optionMap.get(val))); } -export function isValueDisabled(value: RawValueType, options: FlattenDataNode[]): boolean { +export function isValueDisabled(value: RawValueType, options: CompatibleDataNode[]): boolean { const option = findValueOption([value], options)[0]; if (option) { return option.disabled; 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..cb461788 100644 --- a/tests/__snapshots__/Select.checkable.spec.js.snap +++ b/tests/__snapshots__/Select.checkable.spec.js.snap @@ -8,94 +8,118 @@ exports[`TreeSelect.checkable uncheck remove by selector not treeCheckStrictly 1
- - - 0 - - - - - - 0-0 - -