Skip to content

Commit

Permalink
fix(space): 修复t-space在嵌套使用时,使用v-if隐藏会产生冗余空格的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Luffy-developer committed Oct 17, 2024
1 parent aa94731 commit afe4259
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
18 changes: 18 additions & 0 deletions src/space/_example/combination.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<t-space direction="vertical">
<t-button>Button</t-button>
<t-button>Button</t-button>
<t-button>Button</t-button>
<t-space>
<template v-if="true">
<t-button>Button</t-button>
<t-button>Button</t-button>
<t-button v-if="false">Button</t-button>
<t-button>Button</t-button>
<!-- <t-button v-if="false">Button</t-button> -->
<t-button v-if="true">Button</t-button>
</template>
<t-button>Button</t-button>
</t-space>
</t-space>
</template>
24 changes: 13 additions & 11 deletions src/space/space.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineComponent, computed, CSSProperties, Fragment } from 'vue';
import { defineComponent, computed, CSSProperties, Fragment, Comment, isVNode } from 'vue';
import props from './props';
import { usePrefixClass } from '../hooks/useConfig';
import { useTNodeJSX } from '../hooks/tnode';
Expand Down Expand Up @@ -57,16 +57,18 @@ export default defineComponent({
function renderChildren() {
const children = getChildSlots();
const separatorContent = renderTNodeJSX('separator');
return children.map((child, index) => {
// filter last child
const showSeparator = index + 1 !== children.length && separatorContent;
return (
<Fragment>
<div class={`${COMPONENT_NAME.value}-item`}>{child}</div>
{showSeparator && <div class={`${COMPONENT_NAME.value}-item-separator`}>{separatorContent}</div>}
</Fragment>
);
});
return children
.filter((child) => (isVNode(child) ? child.type !== Comment : true))
.map((child, index) => {
// filter last child
const showSeparator = index + 1 !== children.length && separatorContent;
return (
<Fragment>
<div class={`${COMPONENT_NAME.value}-item`}>{child}</div>
{showSeparator && <div class={`${COMPONENT_NAME.value}-item-separator`}>{separatorContent}</div>}
</Fragment>
);
});
}

return () => {
Expand Down

0 comments on commit afe4259

Please sign in to comment.