Skip to content

Commit

Permalink
fix(dropdown): set padding of List in the Dropdown to be zero (#1559)
Browse files Browse the repository at this point in the history
Co-authored-by: maxin <maxin@growingio.com>
  • Loading branch information
nnmax and maxin committed Nov 30, 2021
1 parent 32de45b commit 9a2af8d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ export function Dropdown<T = HTMLElement>(props: DropdownProps, ref: React.Forwa
});
};

const withoutPadding = (contentNode: DropdownProps['content']) => {
if (React.isValidElement(contentNode)) {
return React.cloneElement(contentNode, {
className: classnames(`${prefixCls}-p-0`, contentNode.props.className),
});
}
return contentNode;
};

const withOnClick = (contentNode: DropdownProps['content']) => {
const close = () => {
setControlledVisible(false);
Expand Down Expand Up @@ -67,7 +76,7 @@ export function Dropdown<T = HTMLElement>(props: DropdownProps, ref: React.Forwa
arrowPointAtCenter
placement={placement}
visible={controlledVisible}
content={withOnClick(content)}
content={withOnClick(withoutPadding(content))}
overlayClassName={classnames(prefixCls, overlayClassName)}
onVisibleChange={(changedVisible) => {
setControlledVisible(changedVisible);
Expand Down
6 changes: 3 additions & 3 deletions src/dropdown/demos/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const Demo = () => (
<h3>Use Case -1看板中“更多”按钮</h3>
<Dropdown
content={
<List style={{ padding: 0 }}>
<List>
<Item prefix={<ReloadOutlined size="14px" />} value="1">
刷新数据
</Item>
Expand Down Expand Up @@ -77,7 +77,7 @@ export const Demo = () => (
<h3>Use Case -2列表/卡片中的操作菜单</h3>
<Dropdown
content={
<List style={{ padding: 0 }}>
<List>
<Item prefix={<ReloadOutlined size="14px" />} value="1">
添加到看板
</Item>
Expand All @@ -100,7 +100,7 @@ const Template: Story<DropdownProps> = (args) => <Dropdown {...args} />;
export const Default = Template.bind({});
Default.args = {
content: (
<List style={{ padding: 0 }}>
<List>
<Item prefix={<ReloadOutlined size="14px" />} value="1">
刷新数据
</Item>
Expand Down
3 changes: 3 additions & 0 deletions src/dropdown/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
padding: 8px;
overflow: visible;
background-color: @gray-0;
&-p-0 {
padding: 0;
}
.border(4);
.elevation(2);
}

1 comment on commit 9a2af8d

@vercel
Copy link

@vercel vercel bot commented on 9a2af8d Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.