Skip to content
Open
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
12 changes: 6 additions & 6 deletions src/CSSTransitionGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


import { h, cloneElement, Component } from 'preact';
import { getKey, filterNullChildren } from './util';
import { getKey, filterUnrenderableChildren } from './util';
import { mergeChildMappings, isShownInChildren, isShownInChildrenByKey, inChildren, inChildrenByKey } from './TransitionChildMapping';
import { CSSTransitionGroupChild } from './CSSTransitionGroupChild';

Expand Down Expand Up @@ -42,10 +42,10 @@ export class CSSTransitionGroup extends Component {
}

componentWillReceiveProps({ children, exclusive, showProp }) {
let nextChildMapping = filterNullChildren(children || []).slice();
let nextChildMapping = filterUnrenderableChildren(children || []).slice();

// last props children if exclusive
let prevChildMapping = filterNullChildren(exclusive ? this.props.children : this.state.children);
let prevChildMapping = filterUnrenderableChildren(exclusive ? this.props.children : this.state.children);

let newChildren = mergeChildMappings(
prevChildMapping,
Expand Down Expand Up @@ -118,7 +118,7 @@ export class CSSTransitionGroup extends Component {

_handleDoneEntering(key) {
delete this.currentlyTransitioningKeys[key];
let currentChildMapping = filterNullChildren(this.props.children),
let currentChildMapping = filterUnrenderableChildren(this.props.children),
showProp = this.props.showProp;
if (!currentChildMapping || (
!showProp && !inChildrenByKey(currentChildMapping, key)
Expand Down Expand Up @@ -157,7 +157,7 @@ export class CSSTransitionGroup extends Component {
_handleDoneLeaving(key) {
delete this.currentlyTransitioningKeys[key];
let showProp = this.props.showProp,
currentChildMapping = filterNullChildren(this.props.children);
currentChildMapping = filterUnrenderableChildren(this.props.children);
if (showProp && currentChildMapping &&
isShownInChildrenByKey(currentChildMapping, key, showProp)) {
this.performEnter(key);
Expand Down Expand Up @@ -202,7 +202,7 @@ export class CSSTransitionGroup extends Component {
render({ component:Component, transitionName, transitionEnter, transitionLeave, transitionEnterTimeout, transitionLeaveTimeout, children:c, ...props }, { children }) {
return (
<Component {...props}>
{ filterNullChildren(children).map(this.renderChild) }
{ filterUnrenderableChildren(children).map(this.renderChild) }
</Component>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export function onlyChild(children) {
return children && children[0];
}

export function filterNullChildren(children) {
return children && children.filter(i => i !== null);
export function filterUnrenderableChildren(children) {
return children && children.filter(i => i !== null && i !== undefined && typeof i !== 'boolean');
}
3 changes: 3 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class NullChildren extends Component {
<div className='root'>
<CSSTransitionGroup transitionName="example">
{null}
{false}
{true}
{undefined}

{ items.map( ({displayed, item}, i) => (
displayed ? <Todo key={item} onClick={this.toggleDisplay.bind(this, i)}>
Expand Down