Skip to content

Fix adding undefined to class #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2020
Merged
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
11 changes: 7 additions & 4 deletions src/CSSTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ class CSSTransition extends React.Component {

addClass(node, type, phase) {
let className = this.getClassNames(type)[`${phase}ClassName`];
const { doneClassName } = this.getClassNames('enter');

if (type === 'appear' && phase === 'done') {
className += ` ${this.getClassNames('enter').doneClassName}`;
if (type === 'appear' && phase === 'done' && doneClassName) {
className += ` ${doneClassName}`;
}

// This is for to force a repaint,
Expand All @@ -176,8 +177,10 @@ class CSSTransition extends React.Component {
node && node.scrollTop;
}

this.appliedClasses[type][phase] = className
addClass(node, className)
if (className) {
this.appliedClasses[type][phase] = className
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be outside the conditional, no? we want to e.g. reset old values

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taion I think that it is unnecessary to add falsy value to object and run addClass function, i can remove this conditional if you think that it will be better approach

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, we want to clear any previous value that was there, no? e.g. if this already ran a transition, and the class mappings are dynamic, then we don't want to keep around an old stale value from the last time the transition ran?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

className will be undefined for this case (when doneClassName is undefined), so if it is undefined we could pass through:

this.appliedClasses[type][phase] = className

appliedClasses is used in removeClasses function, and it also check for undefined

also we can pass through:

addClass(node, className)

cause it check if className is falsy.
So I suppose it is equivalent, but with this condition, we can skip addClass and pass undefined value to appliedClasses

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess we wipe it in

this.appliedClasses[type] = {};
anyway

addClass(node, className)
}
}

removeClasses(node, type) {
Expand Down
24 changes: 23 additions & 1 deletion test/CSSTransition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,29 @@ describe('CSSTransition', () => {
<div />
</CSSTransition>
)
})
});

it('should not add undefined when appearDone is not defined', done => {
mount(
<CSSTransition
timeout={10}
classNames={{ appear: 'appear-test' }}
in={true}
appear={true}
onEnter={(node, isAppearing) => {
expect(isAppearing).toEqual(true);
expect(node.className).toEqual('appear-test');
}}
onEntered={(node, isAppearing) => {
expect(isAppearing).toEqual(true);
expect(node.className).toEqual('');
done();
}}
>
<div/>
</CSSTransition>
);
});

it('should not be appearing in normal enter mode', done => {
let count = 0;
Expand Down