Skip to content

Commit

Permalink
fix(dropdown): flat children as item children
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Oct 17, 2022
1 parent d0316ec commit b0f258b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/dropdown/_example/slot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</t-dropdown-menu>
</t-dropdown-item>

<t-dropdown-item :value="2"> 操作二 </t-dropdown-item>
<t-dropdown-item :value="2">操作二 </t-dropdown-item>

<t-dropdown-item :value="3">操作三</t-dropdown-item>
</t-dropdown-menu>
Expand All @@ -73,7 +73,7 @@ import { MessagePlugin } from 'tdesign-vue-next';
const clickHandler = (data) => {
console.log(data, 'data');
if (data.value !== 212) MessagePlugin.success(`选中【${data.content}`);
if (data.value !== 212) MessagePlugin.success(`选中【${data.value}`);
};
const handleClick = () => {
MessagePlugin.success(`点击 操作2-1-2`);
Expand Down
13 changes: 8 additions & 5 deletions src/dropdown/hooks/useDropdownOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ export const getOptionsFromChildren = (menuGroup: any): DropdownOption[] => {
.map((item) => {
const groupChildren = item.children?.default?.();

const contentIdx = groupChildren?.findIndex?.(
(v: VNode) => typeof v.children === 'string' && (v.type as { description: string }).description !== 'Comment',
// 当前节点的渲染内容
const contentCtx = groupChildren?.filter?.(
(v: VNode) => !['TDropdownMenu', 'TDropdownItem'].includes((v.type as { name: string })?.name),
);
const childrenContent = groupChildren?.filter?.(
// 嵌套菜单的节点
const childrenCtx = groupChildren?.filter?.(
(v: VNode) =>
typeof v.children !== 'string' &&
['TDropdownMenu', 'TDropdownItem'].includes((v.type as { name: string })?.name),
);

return {
...item.props,
content: groupChildren?.[contentIdx]?.children || groupChildren,
children: childrenContent?.length > 0 ? getOptionsFromChildren(childrenContent) : null,
content: contentCtx || groupChildren,
children: childrenCtx?.length > 0 ? getOptionsFromChildren(childrenCtx) : null,
};
})
.filter((v) => !!v.content);
Expand Down

0 comments on commit b0f258b

Please sign in to comment.