Skip to content

Commit 305de55

Browse files
committed
fix: depreacted api
1 parent 430ad8a commit 305de55

10 files changed

+311
-138
lines changed

README.md

+52-52
Large diffs are not rendered by default.

examples/basic.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class Demo extends React.Component {
124124
console.log(args);
125125
};
126126

127-
onDropdownVisibleChange = visible => {
127+
onPopupVisibleChange = visible => {
128128
const { value } = this.state;
129129
console.log(visible, value);
130130
if (Array.isArray(value) && value.length > 1 && value.length < 3) {
@@ -205,8 +205,8 @@ class Demo extends React.Component {
205205
console.log('onChange', val, ...args);
206206
this.setState({ value: val });
207207
}}
208-
onDropdownVisibleChange={v => {
209-
console.log('single onDropdownVisibleChange', v);
208+
onPopupVisibleChange={v => {
209+
console.log('single onPopupVisibleChange', v);
210210
this.setState({
211211
tsOpen: v,
212212
});
@@ -263,7 +263,7 @@ class Demo extends React.Component {
263263
overflow: { adjustY: 0, adjustX: 0 },
264264
offset: [0, 2],
265265
}}
266-
onDropdownVisibleChange={this.onDropdownVisibleChange}
266+
onPopupVisibleChange={this.onPopupVisibleChange}
267267
placeholder={<i>请下拉选择</i>}
268268
treeLine
269269
maxTagTextLength={10}

examples/width.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import TreeSelect, { TreeNode } from '../src';
44

55
function Demo() {
66
return (
7-
<TreeSelect style={{ width: 120 }} dropdownMatchSelectWidth={false} treeDefaultExpandAll>
7+
<TreeSelect style={{ width: 120 }} popupMatchSelectWidth={false} treeDefaultExpandAll>
88
<TreeNode value="parent 1" title="parent 1">
99
<TreeNode value="parent 1-0 sdfsdfsdsdfsd" title="parent 1-0 sdfsdfsd">
1010
<TreeNode value="leaf1 sdfsdf" title="leaf1" />

src/OptionList.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
4343
treeData,
4444
fieldNames,
4545
onSelect,
46-
dropdownMatchSelectWidth,
46+
popupMatchSelectWidth,
4747
treeExpandAction,
4848
treeTitleRender,
4949
onPopupScroll,
@@ -347,7 +347,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
347347
height={listHeight}
348348
itemHeight={listItemHeight}
349349
itemScrollOffset={listItemScrollOffset}
350-
virtual={virtual !== false && dropdownMatchSelectWidth !== false}
350+
virtual={virtual !== false && popupMatchSelectWidth !== false}
351351
multiple={multiple}
352352
icon={treeIcon}
353353
showIcon={showTreeIcon}

src/TreeSelect.tsx

+11-20
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export interface TreeSelectProps<ValueType = any, OptionType extends DataNode =
9393
listHeight?: number;
9494
listItemHeight?: number;
9595
listItemScrollOffset?: number;
96-
onDropdownVisibleChange?: (open: boolean) => void;
96+
onPopupVisibleChange?: (open: boolean) => void;
9797
treeTitleRender?: (node: OptionType) => React.ReactNode;
9898

9999
// >>> Tree
@@ -163,8 +163,8 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
163163
listItemHeight = 20,
164164
listItemScrollOffset = 0,
165165

166-
onDropdownVisibleChange,
167-
dropdownMatchSelectWidth = true,
166+
onPopupVisibleChange,
167+
popupMatchSelectWidth = true,
168168

169169
// Tree
170170
treeLine,
@@ -582,22 +582,13 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
582582
);
583583

584584
// ========================== Dropdown ==========================
585-
const onInternalDropdownVisibleChange = React.useCallback(
585+
const onInternalPopupVisibleChange = React.useCallback(
586586
(open: boolean) => {
587-
if (onDropdownVisibleChange) {
588-
const legacyParam = {};
589-
590-
Object.defineProperty(legacyParam, 'documentClickClose', {
591-
get() {
592-
warning(false, 'Second param of `onDropdownVisibleChange` has been removed.');
593-
return false;
594-
},
595-
});
596-
597-
(onDropdownVisibleChange as any)(open, legacyParam);
587+
if (onPopupVisibleChange) {
588+
onPopupVisibleChange(open);
598589
}
599590
},
600-
[onDropdownVisibleChange],
591+
[onPopupVisibleChange],
601592
);
602593

603594
// ====================== Display Change ========================
@@ -619,7 +610,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
619610
const treeSelectContext = React.useMemo<TreeSelectContextProps>(() => {
620611
return {
621612
virtual,
622-
dropdownMatchSelectWidth,
613+
popupMatchSelectWidth,
623614
listHeight,
624615
listItemHeight,
625616
listItemScrollOffset,
@@ -636,7 +627,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
636627
};
637628
}, [
638629
virtual,
639-
dropdownMatchSelectWidth,
630+
popupMatchSelectWidth,
640631
listHeight,
641632
listItemHeight,
642633
listItemScrollOffset,
@@ -716,8 +707,8 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
716707
// >>> Options
717708
OptionList={OptionList}
718709
emptyOptions={!mergedTreeData.length}
719-
onDropdownVisibleChange={onInternalDropdownVisibleChange}
720-
dropdownMatchSelectWidth={dropdownMatchSelectWidth}
710+
onPopupVisibleChange={onInternalPopupVisibleChange}
711+
popupMatchSelectWidth={popupMatchSelectWidth}
721712
/>
722713
</LegacyContext.Provider>
723714
</TreeSelectContext.Provider>

src/TreeSelectContext.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type useDataEntities from './hooks/useDataEntities';
55

66
export interface TreeSelectContextProps {
77
virtual?: boolean;
8-
dropdownMatchSelectWidth?: boolean | number;
8+
popupMatchSelectWidth?: boolean | number;
99
listHeight: number;
1010
listItemHeight: number;
1111
listItemScrollOffset?: number;

tests/Select.props.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ describe('TreeSelect.props', () => {
556556
expect(onSelect).toHaveBeenCalledWith('smart', nodeMatcher(0));
557557
});
558558

559-
it('dropdownMatchSelectWidth={false} should turn off virtual list', () => {
559+
it('popupMatchSelectWidth={false} should turn off virtual list', () => {
560560
const wrapper = mount(
561561
<TreeSelect style={{ width: 120 }} open treeDefaultExpandAll>
562562
<TreeNode value="parent 1" title="parent 1">
@@ -583,7 +583,7 @@ describe('TreeSelect.props', () => {
583583
</TreeSelect>,
584584
);
585585
expect(wrapper.find(Tree).props().virtual).toBe(true);
586-
wrapper.setProps({ dropdownMatchSelectWidth: false });
586+
wrapper.setProps({ popupMatchSelectWidth: false });
587587
expect(wrapper.find(Tree).props().virtual).toBe(false);
588588
});
589589
});

tests/Select.spec.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,18 @@ describe('TreeSelect.basic', () => {
6060
});
6161

6262
it('renders tree correctly', () => {
63-
const wrapper = mount(
63+
const { container } = render(
6464
<TreeSelect
6565
popupClassName="awesome"
6666
popupStyle={{ width: 300 }}
6767
multiple
6868
treeCheckable
6969
treeDefaultExpandAll
7070
treeData={treeData}
71+
open
7172
/>,
7273
);
73-
expect(wrapper.render()).toMatchSnapshot();
74+
expect(container).toMatchSnapshot();
7475
});
7576

7677
it('not crash if no children', () => {

tests/Select.warning.spec.js

-16
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,6 @@ describe('TreeSelect.warning', () => {
5656
);
5757
});
5858

59-
it('documentClickClose should removed', () => {
60-
const wrapper = mount(
61-
<TreeSelect
62-
onDropdownVisibleChange={(_, { documentClickClose }) => {
63-
expect(documentClickClose).toBeFalsy();
64-
}}
65-
/>,
66-
);
67-
68-
wrapper.openSelect();
69-
70-
expect(spy).toHaveBeenCalledWith(
71-
'Warning: Second param of `onDropdownVisibleChange` has been removed.',
72-
);
73-
});
74-
7559
it('warns on using maxCount with showCheckedStrategy=SHOW_ALL when treeCheckStrictly=false', () => {
7660
mount(<TreeSelect maxCount={2} showCheckedStrategy="SHOW_ALL" />);
7761
expect(spy).toHaveBeenCalledWith(

0 commit comments

Comments
 (0)