Skip to content

Commit a24ab44

Browse files
authored
fix(Carousel): fix crossfade animation (react-bootstrap#5671)
1 parent a4d6f98 commit a24ab44

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/Carousel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import useUpdateEffect from '@restart/hooks/useUpdateEffect';
33
import useCommittedRef from '@restart/hooks/useCommittedRef';
44
import useTimeout from '@restart/hooks/useTimeout';
55
import classNames from 'classnames';
6-
import transitionEnd from 'dom-helpers/transitionEnd';
76
import Transition from 'react-transition-group/Transition';
87
import PropTypes from 'prop-types';
98
import React, {
@@ -20,6 +19,7 @@ import CarouselItem from './CarouselItem';
2019
import { map, forEach } from './ElementChildren';
2120
import SafeAnchor from './SafeAnchor';
2221
import { useBootstrapPrefix } from './ThemeProvider';
22+
import transitionEndListener from './transitionEndListener';
2323
import triggerBrowserReflow from './triggerBrowserReflow';
2424
import {
2525
BsPrefixPropsWithChildren,
@@ -567,7 +567,7 @@ function CarouselFunc(uncontrolledProps: CarouselProps, ref) {
567567
in={isActive}
568568
onEnter={isActive ? handleEnter : undefined}
569569
onEntered={isActive ? handleEntered : undefined}
570-
addEndListener={transitionEnd}
570+
addEndListener={transitionEndListener}
571571
>
572572
{(status) =>
573573
React.cloneElement(child, {

src/transitionEndListener.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1+
import css from 'dom-helpers/css';
12
import transitionEnd from 'dom-helpers/transitionEnd';
23

4+
function parseDuration(
5+
node: HTMLElement,
6+
property: 'transitionDuration' | 'transitionDelay',
7+
) {
8+
const str = css(node, property) || '';
9+
const mult = str.indexOf('ms') === -1 ? 1000 : 1;
10+
return parseFloat(str) * mult;
11+
}
12+
313
export default function transitionEndListener(
414
element: HTMLElement,
515
handler: (e: TransitionEvent) => void,
616
) {
7-
const remove = transitionEnd(element, (e) => {
8-
if (e.target === element) {
9-
remove();
10-
handler(e);
11-
}
12-
});
17+
const duration = parseDuration(element, 'transitionDuration');
18+
const delay = parseDuration(element, 'transitionDelay');
19+
const remove = transitionEnd(
20+
element,
21+
(e) => {
22+
if (e.target === element) {
23+
remove();
24+
handler(e);
25+
}
26+
},
27+
duration + delay,
28+
);
1329
}

0 commit comments

Comments
 (0)