Skip to content

Commit

Permalink
fix: incorrect warning (#38446)
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan committed Nov 9, 2022
1 parent 4ad7c76 commit fe9ac7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions components/dropdown/__tests__/dropdown-button.test.tsx
Expand Up @@ -131,4 +131,16 @@ describe('DropdownButton', () => {
'ant-btn',
);
});
it('should throw Error then `overlay` in props', () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
render(<DropdownButton overlay={<div>test</div>} />);
expect(errSpy).toHaveBeenCalledWith(
'Warning: [antd: Dropdown] `overlay` is deprecated. Please use `menu` instead.',
);
});
it('should not throw Error then `overlay` not in props', () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
render(<DropdownButton />);
expect(errSpy).toHaveBeenCalled();
});
});
6 changes: 5 additions & 1 deletion components/dropdown/dropdown-button.tsx
Expand Up @@ -79,7 +79,6 @@ const DropdownButton: DropdownButtonInterface = props => {
arrow,
autoFocus,
align,
overlay,
disabled,
trigger: disabled ? [] : trigger,
onOpenChange: onOpenChange || onVisibleChange,
Expand All @@ -90,10 +89,15 @@ const DropdownButton: DropdownButtonInterface = props => {
overlayStyle,
destroyPopupOnHide,
};

const { compactSize, compactItemClassnames } = useCompactItemContext(prefixCls, direction);

const classes = classNames(prefixCls, compactItemClassnames, className);

if ('overlay' in props) {
dropdownProps.overlay = overlay;
}

if ('open' in props) {
dropdownProps.open = open;
} else if ('visible' in props) {
Expand Down

0 comments on commit fe9ac7b

Please sign in to comment.