Skip to content

Commit

Permalink
fix: fix deprecated menu config for dropdown
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Dropdown doesn't need a full antd Menu component any more.
Instead of this, an object of type MenuProps is expected now.
  • Loading branch information
annarieger committed Dec 5, 2022
1 parent 6cdcef4 commit 8d293fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/UserChip/UserChip.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ describe('<UserChip />', () => {
});

it('should render a dropdown', async () => {
render(<UserChip userName="Shinji Kagawa" userMenu={<div role="menu">Example menu</div>} />);
const exampleMenu = {
items: [{
label: <div role="menu">Example menu</div>,
key: 'example'
}]
};
render(<UserChip userName="Shinji Kagawa" userMenu={exampleMenu}/>);
const chip = screen.getByText('SK').parentElement;
await userEvent.click(chip);
const menu = screen.getByText('Example menu');
Expand All @@ -45,7 +51,7 @@ describe('<UserChip />', () => {
});

it('should not render a dropdown for invalid configuration', () => {
render(<UserChip userName="Shinji Kagawa" userMenu={null} />);
render(<UserChip userName="Shinji Kagawa" userMenu={undefined} />);
const menu = screen.queryByRole('menu');
expect(menu).not.toBeInTheDocument();
});
Expand Down
11 changes: 6 additions & 5 deletions src/UserChip/UserChip.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import {
Avatar,
Dropdown
Dropdown,
MenuProps
} from 'antd';

import { AvatarProps } from 'antd/lib/avatar';
Expand All @@ -22,9 +23,9 @@ export interface BaseProps {
*/
imageSrc?: string;
/**
* The react element representing the user menu
* The user menu
*/
userMenu?: React.ReactNode;
userMenu?: MenuProps;
/**
* The user name.
*/
Expand Down Expand Up @@ -136,10 +137,10 @@ class UserChip extends React.Component<UserChipProps> {
userMenu
} = this.props;

if (userMenu && React.isValidElement(userMenu)) {
if (userMenu?.items) {
return (
<Dropdown
overlay={userMenu}
menu={userMenu}
trigger={['click']}
getPopupContainer={() => {
return document.getElementsByClassName(this._className)[0] as HTMLElement;
Expand Down

0 comments on commit 8d293fd

Please sign in to comment.