Skip to content

Commit

Permalink
fix(comp:transfer): empty suffix node shouldn't be rendered (#1267)
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Nov 15, 2022
1 parent 38f130a commit 4ab1ebb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
13 changes: 7 additions & 6 deletions packages/cdk/utils/src/vNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ export function hasSlot(slots: Slots, key = 'default'): boolean {
return !isNil(slots[key])
}

export function isEmptyNode(node: VNodeChild): boolean {
return (
!node ||
isComment(node) ||
(isFragment(node) && (node as any).children.length === 0) ||
(isText(node) && (node as any).children.trim() === '')
export function isEmptyNode(nodes: VNodeChild): boolean {
return convertArray(nodes).every(
node =>
!node ||
isComment(node) ||
(isFragment(node) && (node as any).children.length === 0) ||
(isText(node) && (node as any).children.trim() === ''),
)
}

Expand Down
12 changes: 7 additions & 5 deletions packages/components/transfer/src/content/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

import { type VNodeTypes, defineComponent, inject, normalizeClass, onMounted, ref, watch, withKeys } from 'vue'

import { isArray } from 'lodash-es'

import { useState } from '@idux/cdk/utils'
import { isEmptyNode, useState } from '@idux/cdk/utils'
import { ɵInput, type ɵInputInstance } from '@idux/components/_private/input'
import { IxCheckbox } from '@idux/components/checkbox'
import { IxIcon } from '@idux/components/icon'
Expand Down Expand Up @@ -142,7 +140,11 @@ export default defineComponent({
const renderSuffix = (prefixCls: string) => {
const suffix = slots.headerSuffix?.({ isSource: props.isSource })

return suffix && <span class={`${prefixCls}-suffix`}>{suffix}</span>
if (isEmptyNode(suffix)) {
return
}

return <span class={`${prefixCls}-suffix`}>{suffix}</span>
}

const renderHeader = (prefixCls: string) => {
Expand All @@ -166,7 +168,7 @@ export default defineComponent({

const children = renderHeader(prefixCls)

if (!children || (isArray(children) && children.length <= 0)) {
if (isEmptyNode(children)) {
return
}

Expand Down

0 comments on commit 4ab1ebb

Please sign in to comment.