Skip to content

Commit

Permalink
fix: transition event bubbling (#1153)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicleo authored Nov 10, 2023
1 parent 669081f commit 5589d79
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/zarm/src/transition/Transition.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as React from 'react';
import classnames from 'classnames';
import * as React from 'react';
import { Transition as InternalTransition } from 'react-transition-group';
import { noop } from '../utils';
import Events from '../utils/events';
import type { HTMLProps } from '../utils/utilityTypes';
import type { BaseTransitionProps } from './interface';
import Events from '../utils/events';

export interface TransitionChildrenProps extends Required<HTMLProps> {
visible?: boolean;
Expand Down Expand Up @@ -58,7 +58,7 @@ const Transition: React.FC<TransitionProps> = (props) => {
} = props;
const nodeRef = React.useRef<HTMLElement | null>();
const [state, setState] = React.useState(TransitionState.UNMOUNTED);
const callbackRef = React.useRef(noop);
const callbackRef = React.useRef<(event: Event) => void>(noop);

const unmounted = TransitionState.UNMOUNTED === state;
const enter = TransitionState.ENTER === state;
Expand Down Expand Up @@ -105,7 +105,11 @@ const Transition: React.FC<TransitionProps> = (props) => {
in={visible}
addEndListener={(next) => {
if (!nodeRef.current) return;
callbackRef.current = next;
callbackRef.current = (event: Event) => {
const target = event.target as HTMLElement;
if (!target.contains(nodeRef.current)) return;
next();
};
Events.on(nodeRef.current, animationEndName, callbackRef.current);
Events.on(nodeRef.current, transitionEndName, callbackRef.current);
}}
Expand Down

1 comment on commit 5589d79

@vercel
Copy link

@vercel vercel bot commented on 5589d79 Nov 10, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

zarm – ./

zarm-zhongantech.vercel.app
zarm-git-master-zhongantech.vercel.app

Please sign in to comment.