Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dropdown): correct the top of the dropdown menu when has panelTopContent #3106

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/dropdown/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const DropdownMenu: React.FC<DropdownProps> = (props) => {
const optionItem = { ...(menu as DropdownOption) };
const onViewIdx = Math.ceil(calcScrollTopMap[deep] / 30);
const isOverflow = idx >= onViewIdx;
// 只有第一层子节点需要加上 panelTopContent 的高度
const shouldCalcPanelTopContent = panelTopContent && deep > 0;

const itemIdx = isOverflow ? idx - onViewIdx : idx;
if (optionItem.children) {
optionItem.children = renderOptions(optionItem.children, deep + 1);
Expand Down Expand Up @@ -97,7 +100,7 @@ const DropdownMenu: React.FC<DropdownProps> = (props) => {
})}
style={{
position: 'absolute',
top: `${itemIdx * 30 + (isOverflow ? 0 : panelTopContentHeight)}px`,
top: `${itemIdx * 30 + (shouldCalcPanelTopContent ? 0 : panelTopContentHeight)}px`,
}}
>
<div
Expand Down
19 changes: 18 additions & 1 deletion src/dropdown/_example/child.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,24 @@ export default function BasicDropdown() {
MessagePlugin.success(`选中【${data.value}】`);
};
return (
<Dropdown minColumnWidth={100} trigger="click">
<Dropdown
minColumnWidth={100}
trigger="click"
panelTopContent={
<div
style={{
height: 48,
backgroundColor: 'var(--td-bg-color-component)',
borderRadius: '6px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
Top Content
</div>
}
>
<Button variant="text" suffix={<Icon name="chevron-down" size="16" />}>
更多
</Button>
Expand Down
Loading