Skip to content

Commit 6a516c1

Browse files
committed
fix: do not forward disabled to trigger
1 parent 6dafd0f commit 6a516c1

5 files changed

Lines changed: 47 additions & 12 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
]
4545
},
4646
"dependencies": {
47-
"@rc-component/trigger": "^3.0.0",
48-
"@rc-component/util": "^1.2.1",
47+
"@rc-component/trigger": "^3.9.1",
48+
"@rc-component/util": "^1.11.1",
4949
"classnames": "^2.2.6"
5050
},
5151
"devDependencies": {

src/Dropdown.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
import type { TriggerProps } from '@rc-component/trigger';
2-
import Trigger from '@rc-component/trigger';
31
import type {
42
ActionType,
53
AlignType,
6-
AnimationType,
74
BuildInPlacements,
8-
} from '@rc-component/trigger/lib/interface';
9-
import { composeRef, getNodeRef, supportRef } from '@rc-component/util/lib/ref';
5+
TriggerProps,
6+
} from '@rc-component/trigger';
7+
import Trigger from '@rc-component/trigger';
8+
import { composeRef, getNodeRef, omit, supportRef } from '@rc-component/util';
109
import classNames from 'classnames';
1110
import React from 'react';
1211
import useAccessibility from './hooks/useAccessibility';
1312
import Overlay from './Overlay';
1413
import Placements from './placements';
1514

15+
type AnimationType = string;
16+
1617
export interface DropdownProps
1718
extends Pick<
1819
TriggerProps,
1920
| 'getPopupContainer'
20-
| 'children'
2121
| 'mouseEnterDelay'
2222
| 'mouseLeaveDelay'
2323
| 'onPopupAlign'
2424
| 'builtinPlacements'
2525
| 'autoDestroy'
2626
> {
27+
children: React.ReactElement;
2728
minOverlayWidthMatchTrigger?: boolean;
2829
arrow?: boolean;
2930
onVisibleChange?: (visible: boolean) => void;
@@ -153,7 +154,9 @@ function Dropdown(props: DropdownProps, ref) {
153154
return (
154155
<Trigger
155156
builtinPlacements={placements}
156-
{...otherProps}
157+
{...omit(otherProps as typeof otherProps & { disabled?: boolean }, [
158+
'disabled',
159+
])}
157160
prefixCls={prefixCls}
158161
ref={triggerRef}
159162
popupClassName={classNames(overlayClassName, {

src/Overlay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { composeRef, getNodeRef, supportRef } from '@rc-component/util/lib/ref';
1+
import { composeRef, getNodeRef, supportRef } from '@rc-component/util';
22
import React, { forwardRef, useMemo } from 'react';
33
import type { DropdownProps } from './Dropdown';
44

src/hooks/useAccessibility.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import KeyCode from '@rc-component/util/lib/KeyCode';
2-
import raf from '@rc-component/util/lib/raf';
1+
import { KeyCode, raf } from '@rc-component/util';
32
import * as React from 'react';
43

54
const { ESC, TAB } = KeyCode;

tests/props.test.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { render } from '@testing-library/react';
2+
import * as React from 'react';
3+
import Dropdown from '../src';
4+
5+
const mockTriggerRender = jest.fn();
6+
7+
jest.mock('@rc-component/trigger', () => {
8+
const ReactModule: typeof React = jest.requireActual('react');
9+
10+
return {
11+
__esModule: true,
12+
default: ReactModule.forwardRef<HTMLElement, Record<string, unknown>>(
13+
(props, ref) => {
14+
mockTriggerRender(props);
15+
return ReactModule.createElement('div', { ref });
16+
},
17+
),
18+
};
19+
});
20+
21+
it('does not forward disabled to Trigger', () => {
22+
const runtimeProps = { disabled: true };
23+
24+
render(
25+
<Dropdown {...runtimeProps} visible overlay={<div />}>
26+
<button type="button">open</button>
27+
</Dropdown>,
28+
);
29+
30+
const triggerProps = mockTriggerRender.mock.calls[0][0];
31+
expect(triggerProps).not.toHaveProperty('disabled');
32+
expect(triggerProps).toHaveProperty('popupVisible', true);
33+
});

0 commit comments

Comments
 (0)