Skip to content

Commit

Permalink
fix(space): 修复t-space存在冗余空格的问题
Browse files Browse the repository at this point in the history
修复了在t-space嵌套使用时,如果内层的t-space用v-if判断,条件为false,仍然会生成t-space-item元素,导致样式不正确的问题。

closed #4649
  • Loading branch information
Luffy-developer committed Oct 16, 2024
1 parent aa94731 commit a2e7034
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/space/space.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,26 @@ 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 symbol type
.filter((item) => {
if (typeof item.type === 'symbol' && typeof item.children === 'string') {

Check failure on line 64 in src/space/space.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / build

Property 'type' does not exist on type 'VNodeChild | VNode<RendererNode, RendererElement, { [key: string]: any; }>'.

Check failure on line 64 in src/space/space.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / build

Property 'children' does not exist on type 'VNodeChild | VNode<RendererNode, RendererElement, { [key: string]: any; }>'.

Check failure on line 64 in src/space/space.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Property 'type' does not exist on type 'VNodeChild | VNode<RendererNode, RendererElement, { [key: string]: any; }>'.

Check failure on line 64 in src/space/space.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Property 'children' does not exist on type 'VNodeChild | VNode<RendererNode, RendererElement, { [key: string]: any; }>'.
return false;
}
return item.type !== Comment;

Check failure on line 67 in src/space/space.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / build

Property 'type' does not exist on type 'VNodeChild | VNode<RendererNode, RendererElement, { [key: string]: any; }>'.

Check failure on line 67 in src/space/space.tsx

View workflow job for this annotation

GitHub Actions / call-test-build / test

Property 'type' does not exist on type 'VNodeChild | VNode<RendererNode, RendererElement, { [key: string]: any; }>'.
})
.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 a2e7034

Please sign in to comment.