Skip to content

Commit d3076dd

Browse files
committed
feat: onMotionEnd provides the key
1 parent b9d3333 commit d3076dd

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/CSSMotionList.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
parseKeys,
1212
KeyObject,
1313
} from './util/diff';
14+
import { ListMotionEndEventHandler } from './interface';
1415

1516
const MOTION_PROP_NAMES = [
1617
'eventProps',
@@ -35,9 +36,10 @@ const MOTION_PROP_NAMES = [
3536
'onLeaveEnd',
3637
];
3738

38-
export interface CSSMotionListProps extends CSSMotionProps {
39+
export interface CSSMotionListProps extends Omit<CSSMotionProps, 'onLeaveEnd'> {
3940
keys: (React.Key | { key: React.Key; [name: string]: any })[];
4041
component?: string | React.ComponentType | false;
42+
onLeaveEnd?: ListMotionEndEventHandler;
4143
}
4244

4345
export interface CSSMotionListState {
@@ -118,7 +120,7 @@ export function genCSSMotionList(
118120

119121
render() {
120122
const { keyEntities } = this.state;
121-
const { component, children, ...restProps } = this.props;
123+
const { component, children, onLeaveEnd, ...restProps } = this.props;
122124

123125
const Component = component || React.Fragment;
124126

@@ -140,8 +142,8 @@ export function genCSSMotionList(
140142
visible={visible}
141143
eventProps={eventProps}
142144
onLeaveEnd={(...args) => {
143-
if (motionProps.onLeaveEnd) {
144-
motionProps.onLeaveEnd(...args);
145+
if (onLeaveEnd) {
146+
onLeaveEnd(...args, { key: eventProps.key });
145147
}
146148
this.removeKey(eventProps.key);
147149
}}

src/interface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ export type MotionEndEventHandler = (
3737
element: HTMLElement,
3838
event: MotionEvent,
3939
) => boolean | void;
40+
41+
export type ListMotionEndEventHandler = (
42+
element: HTMLElement,
43+
event: MotionEvent,
44+
info: { key: React.Key },
45+
) => void;

0 commit comments

Comments
 (0)