Skip to content

Commit 5f4259b

Browse files
authored
refactor: Use @rc-component/trigger (#928)
* chore: init * test: update snapshot * test: update snapshot * test: update snapshot * chore: bump trigger support window scroll
1 parent b0ad83d commit 5f4259b

File tree

9 files changed

+386
-741
lines changed

9 files changed

+386
-741
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
},
4646
"dependencies": {
4747
"@babel/runtime": "^7.10.1",
48+
"@rc-component/trigger": "^1.4.0",
4849
"classnames": "2.x",
4950
"rc-motion": "^2.0.1",
5051
"rc-overflow": "^1.0.0",
51-
"rc-trigger": "^5.0.4",
5252
"rc-util": "^5.16.1",
5353
"rc-virtual-list": "^3.4.13"
5454
},

src/BaseSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from 'classnames';
2-
import type { AlignType } from 'rc-trigger/lib/interface';
2+
import type { AlignType } from '@rc-component/trigger/lib/interface';
33
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
44
import useMergedState from 'rc-util/lib/hooks/useMergedState';
55
import isMobile from 'rc-util/lib/isMobile';

src/SelectTrigger.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import * as React from 'react';
2-
import Trigger from 'rc-trigger';
3-
import type { AlignType } from 'rc-trigger/lib/interface';
1+
import Trigger from '@rc-component/trigger';
2+
import type { AlignType } from '@rc-component/trigger/lib/interface';
43
import classNames from 'classnames';
4+
import * as React from 'react';
55
import type { Placement, RenderDOMFunc } from './BaseSelect';
66

7-
const getBuiltInPlacements = (dropdownMatchSelectWidth: number | boolean) => {
7+
const getBuiltInPlacements = (
8+
dropdownMatchSelectWidth: number | boolean,
9+
): Record<string, AlignType> => {
810
// Enable horizontal overflow auto-adjustment when a custom dropdown width is provided
911
const adjustX = dropdownMatchSelectWidth === true ? 0 : 1;
1012
return {
@@ -15,6 +17,7 @@ const getBuiltInPlacements = (dropdownMatchSelectWidth: number | boolean) => {
1517
adjustX,
1618
adjustY: 1,
1719
},
20+
htmlRegion: 'scroll',
1821
},
1922
bottomRight: {
2023
points: ['tr', 'br'],
@@ -23,6 +26,7 @@ const getBuiltInPlacements = (dropdownMatchSelectWidth: number | boolean) => {
2326
adjustX,
2427
adjustY: 1,
2528
},
29+
htmlRegion: 'scroll',
2630
},
2731
topLeft: {
2832
points: ['bl', 'tl'],
@@ -31,6 +35,7 @@ const getBuiltInPlacements = (dropdownMatchSelectWidth: number | boolean) => {
3135
adjustX,
3236
adjustY: 1,
3337
},
38+
htmlRegion: 'scroll',
3439
},
3540
topRight: {
3641
points: ['br', 'tr'],
@@ -39,6 +44,7 @@ const getBuiltInPlacements = (dropdownMatchSelectWidth: number | boolean) => {
3944
adjustX,
4045
adjustY: 1,
4146
},
47+
htmlRegion: 'scroll',
4248
},
4349
};
4450
};

tests/Select.test.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { fireEvent, render as testingRender } from '@testing-library/react';
12
import { mount, render } from 'enzyme';
2-
import { render as testingRender, fireEvent } from '@testing-library/react';
33
import KeyCode from 'rc-util/lib/KeyCode';
44
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
55
import { resetWarned } from 'rc-util/lib/warning';
@@ -66,8 +66,8 @@ describe('Select.Basic', () => {
6666
});
6767

6868
it('renders dropdown correctly', () => {
69-
const wrapper = render(genSelect({ open: true }));
70-
expect(wrapper).toMatchSnapshot();
69+
const { container } = testingRender(genSelect({ open: true }));
70+
expect(container.querySelector('.rc-select-dropdown')).toMatchSnapshot();
7171
});
7272

7373
it('renders disabled select correctly', () => {
@@ -353,7 +353,7 @@ describe('Select.Basic', () => {
353353
});
354354

355355
it('should contain falsy children', () => {
356-
const wrapper = render(
356+
const { container } = testingRender(
357357
<Select value="1" open>
358358
<Option value="1">1</Option>
359359
{null}
@@ -362,7 +362,7 @@ describe('Select.Basic', () => {
362362
</Select>,
363363
);
364364

365-
expect(wrapper).toMatchSnapshot();
365+
expect(container.querySelector('.rc-select-dropdown')).toMatchSnapshot();
366366
});
367367

368368
it('open dropdown on down key press', () => {
@@ -1038,25 +1038,25 @@ describe('Select.Basic', () => {
10381038
});
10391039

10401040
it('filterOption could be true as described in default value', () => {
1041-
const wrapper = mount(
1041+
const { container } = testingRender(
10421042
<Select searchValue="3" showSearch filterOption open>
10431043
<Option value="1">1</Option>
10441044
<Option value="2">2</Option>
10451045
</Select>,
10461046
);
10471047

1048-
expect(wrapper.render()).toMatchSnapshot();
1048+
expect(container.querySelector('.rc-select-dropdown')).toMatchSnapshot();
10491049
});
10501050

10511051
it('does not filter when filterOption value is false', () => {
1052-
const wrapper = render(
1052+
const { container } = testingRender(
10531053
<Select inputValue="1" filterOption={false} open>
10541054
<Option value="1">1</Option>
10551055
<Option value="2">2</Option>
10561056
</Select>,
10571057
);
10581058

1059-
expect(wrapper).toMatchSnapshot();
1059+
expect(container.querySelector('.rc-select-dropdown')).toMatchSnapshot();
10601060
});
10611061

10621062
it('backfill', () => {
@@ -1130,7 +1130,7 @@ describe('Select.Basic', () => {
11301130
});
11311131

11321132
it('should render custom dropdown correctly', () => {
1133-
const wrapper = mount(
1133+
const { container } = testingRender(
11341134
<Select
11351135
open
11361136
dropdownRender={(menu) => (
@@ -1144,7 +1144,7 @@ describe('Select.Basic', () => {
11441144
<Option value="2">2</Option>
11451145
</Select>,
11461146
);
1147-
expect(wrapper.render()).toMatchSnapshot();
1147+
expect(container.querySelector('.rc-select-dropdown')).toMatchSnapshot();
11481148
});
11491149

11501150
it('should trigger click event in custom node', () => {

tests/Tags.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { mount } from 'enzyme';
2+
import { render } from '@testing-library/react';
23
import KeyCode from 'rc-util/lib/KeyCode';
34
import classNames from 'classnames';
45
import * as React from 'react';
@@ -406,9 +407,8 @@ describe('Select.Tags', () => {
406407
);
407408

408409
it('renders correctly', () => {
409-
const wrapper = mount(createSelect({ value: ['jack', 'foo'] }));
410-
toggleOpen(wrapper);
411-
expect(wrapper.render()).toMatchSnapshot();
410+
const { container } = render(createSelect({ value: ['jack', 'foo'], open: true }));
411+
expect(container.firstChild).toMatchSnapshot();
412412
});
413413

414414
it('renders inputValue correctly', () => {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Trigger from '@rc-component/trigger/lib/mock';
2+
3+
export default Trigger;

tests/__mocks__/rc-trigger.tsx

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)