Browse Source

fix: Menu transition finished by opacity (#25341)

pull/25351/head
二货机器人 4 years ago
committed by GitHub
parent
commit
cfcd990efd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      components/_util/motion.tsx

16
components/_util/motion.tsx

@ -1,6 +1,7 @@
import * as React from 'react'; import * as React from 'react';
type MotionFunc = (element: HTMLElement) => React.CSSProperties; type MotionFunc = (element: HTMLElement) => React.CSSProperties;
type MotionEndFunc = (element: HTMLElement, event: TransitionEvent) => boolean;
interface Motion { interface Motion {
visible?: boolean; visible?: boolean;
@ -14,13 +15,13 @@ interface Motion {
leavedClassName?: string; leavedClassName?: string;
onAppearStart?: MotionFunc; onAppearStart?: MotionFunc;
onAppearActive?: MotionFunc; onAppearActive?: MotionFunc;
onAppearEnd?: MotionFunc; onAppearEnd?: MotionEndFunc;
onEnterStart?: MotionFunc; onEnterStart?: MotionFunc;
onEnterActive?: MotionFunc; onEnterActive?: MotionFunc;
onEnterEnd?: MotionFunc; onEnterEnd?: MotionEndFunc;
onLeaveStart?: MotionFunc; onLeaveStart?: MotionFunc;
onLeaveActive?: MotionFunc; onLeaveActive?: MotionFunc;
onLeaveEnd?: MotionFunc; onLeaveEnd?: MotionEndFunc;
} }
// ================== Collapse Motion ================== // ================== Collapse Motion ==================
@ -28,6 +29,10 @@ const getCollapsedHeight: MotionFunc = () => ({ height: 0, opacity: 0 });
const getRealHeight: MotionFunc = node => ({ height: node.scrollHeight, opacity: 1 }); const getRealHeight: MotionFunc = node => ({ height: node.scrollHeight, opacity: 1 });
const getCurrentHeight: MotionFunc = node => ({ height: node.offsetHeight }); const getCurrentHeight: MotionFunc = node => ({ height: node.offsetHeight });
function skipOpacityTransition(_: HTMLElement, event: TransitionEvent) {
return event.propertyName === 'height';
}
const collapseMotion: Motion = { const collapseMotion: Motion = {
motionName: 'ant-motion-collapse', motionName: 'ant-motion-collapse',
onAppearStart: getCollapsedHeight, onAppearStart: getCollapsedHeight,
@ -36,6 +41,11 @@ const collapseMotion: Motion = {
onEnterActive: getRealHeight, onEnterActive: getRealHeight,
onLeaveStart: getCurrentHeight, onLeaveStart: getCurrentHeight,
onLeaveActive: getCollapsedHeight, onLeaveActive: getCollapsedHeight,
onAppearEnd: skipOpacityTransition,
onEnterEnd: skipOpacityTransition,
onLeaveEnd: skipOpacityTransition,
motionDeadline: 500, motionDeadline: 500,
}; };

Loading…
Cancel
Save