Skip to content

timeout not behaving as expected #367

@DenisValcke

Description

@DenisValcke

Do you want to request a feature or report a bug?
Report a bug.

What is the current behavior?
If the timeout is given the same value as the duration of the transition, the timeout causes a delay on enter but not when exiting.
If the timeout is set to 0, the timeout doesn't cause a delay on enter but the component just blinks out on exit.
If the timeout is set to { enter: 0, exit: duration }, everything works as I would expect in the first scenario.

What is the expected behavior?
I would expect the timeout to be either a delay on the enter/exit or to be a property to make the component wait for the transition to end. Now it's a bit of both.

Which versions, and which browser / OS are affected by this issue? Did this work in previous versions?
v2.4.0 in Chrome 67 with React 16.3.2

My code looks like this:

import React from "react";
import Transition from "react-transition-group/Transition";
import PropTypes from "prop-types";
import Sidebar from "./Sidebar";

const AnimatedSidebar = (props) => {
	const { show, children, position } = props;
	const duration = 300;
	const defaultStyle = {
		transition: `${position} ${duration}ms ease-in-out`,
		[position === "right" ? "right" : "left"]: "-21.25rem",
	};
	const transitionStyles = {
		entering: { [position === "right" ? "right" : "left"]: "-21.25rem" },
		entered: { [position === "right" ? "right" : "left"]: "0" },
	};

	return (
		<Transition in={show} timeout={{ enter: 0, exit: duration }} unmountOnExit>
			{(state) => (
				<Sidebar style={{ ...defaultStyle, ...transitionStyles[state] }} position={position}>{children}</Sidebar>
			)}
		</Transition>
	);
};

AnimatedSidebar.propTypes = {
	show: PropTypes.bool,
	children: PropTypes.any,
	position: PropTypes.oneOf(["left", "right"]),
};

export default AnimatedSidebar;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions