Skip to content
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

Add support for empty classNames #481

Merged
merged 1 commit into from Apr 2, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/CSSTransition.js
Expand Up @@ -71,6 +71,9 @@ const removeClass = (node, classes) => node && classes && classes.split(' ').for
* `*-active` classes represent which styles you want to animate **to**.
*/
class CSSTransition extends React.Component {
static defaultProps = {
classNames: ''
}
onEnter = (node, appearing) => {
const { className } = this.getClassNames(appearing ? 'appear' : 'enter')

Expand Down Expand Up @@ -140,15 +143,17 @@ class CSSTransition extends React.Component {

getClassNames = (type) => {
const { classNames } = this.props;
const isStringClassNames = typeof classNames === 'string';
const prefix = isStringClassNames && classNames ? classNames + '-' : '';

let className = typeof classNames !== 'string' ?
classNames[type] : classNames + '-' + type;
let className = isStringClassNames ?
prefix + type : classNames[type]

let activeClassName = typeof classNames !== 'string' ?
classNames[type + 'Active'] : className + '-active';
let activeClassName = isStringClassNames ?
className + '-active' : classNames[type + 'Active'];

let doneClassName = typeof classNames !== 'string' ?
classNames[type + 'Done'] : className + '-done';
let doneClassName = isStringClassNames ?
className + '-done' : classNames[type + 'Done'];

return {
className,
Expand Down
33 changes: 33 additions & 0 deletions test/CSSTransition-test.js
Expand Up @@ -279,5 +279,38 @@ describe('CSSTransition', () => {
}
});
});

it('should support empty prefix', done => {
let count = 0;

const instance = mount(
<CSSTransition
in
timeout={10}
>
<div/>
</CSSTransition>
)

instance.setProps({
in: false,

onExit(node){
count++;
expect(node.className).toEqual('exit');
},

onExiting(node){
count++;
expect(node.className).toEqual('exit exit-active');
},

onExited(node){
expect(node.className).toEqual('exit-done');
expect(count).toEqual(2);
done();
}
});
});
});
});