Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: form missing motion validate #38962

Merged
merged 2 commits into from Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions components/form/ErrorList.tsx
Expand Up @@ -2,12 +2,13 @@ import classNames from 'classnames';
import CSSMotion, { CSSMotionList } from 'rc-motion';
import * as React from 'react';
import { useMemo } from 'react';
import { ConfigContext } from '../config-provider';
import initCollapseMotion from '../_util/motion';
import { FormItemPrefixContext } from './context';
import type { ValidateStatus } from './FormItem';
import useDebounce from './hooks/useDebounce';

import useStyle from './style';

const EMPTY_LIST: React.ReactNode[] = [];

interface ErrorEntity {
Expand Down Expand Up @@ -49,12 +50,12 @@ export default function ErrorList({
onVisibleChanged,
}: ErrorListProps) {
const { prefixCls } = React.useContext(FormItemPrefixContext);
const { getPrefixCls } = React.useContext(ConfigContext);

const baseClassName = `${prefixCls}-item-explain`;
const rootPrefixCls = getPrefixCls();

const collapseMotion = useMemo(() => initCollapseMotion(rootPrefixCls), [rootPrefixCls]);
const [, hashId] = useStyle(prefixCls);

const collapseMotion = useMemo(() => initCollapseMotion(prefixCls), [prefixCls]);

// We have to debounce here again since somewhere use ErrorList directly still need no shaking
// ref: https://github.com/ant-design/ant-design/issues/36336
Expand Down Expand Up @@ -82,9 +83,8 @@ export default function ErrorList({

return (
<CSSMotion
{...collapseMotion}
motionDeadline={collapseMotion.motionDeadline}
motionName={`${rootPrefixCls}-show-help`}
motionName={`${prefixCls}-show-help`}
visible={!!fullKeyList.length}
onVisibleChanged={onVisibleChanged}
>
Expand All @@ -94,14 +94,14 @@ export default function ErrorList({
return (
<div
{...helpProps}
className={classNames(baseClassName, holderClassName, rootClassName)}
className={classNames(baseClassName, holderClassName, rootClassName, hashId)}
style={holderStyle}
role="alert"
>
<CSSMotionList
keys={fullKeyList}
{...initCollapseMotion(rootPrefixCls)}
motionName={`${rootPrefixCls}-show-help-item`}
{...initCollapseMotion(prefixCls)}
motionName={`${prefixCls}-show-help-item`}
component={false}
>
{(itemProps) => {
Expand Down
56 changes: 56 additions & 0 deletions components/form/style/explain.tsx
@@ -0,0 +1,56 @@
import type { FormToken } from '.';
import type { GenerateStyle } from '../../theme/internal';

const genFormValidateMotionStyle: GenerateStyle<FormToken> = (token) => {
const { componentCls } = token;

const helpCls = `${componentCls}-show-help`;
const helpItemCls = `${componentCls}-show-help-item`;

return {
[helpCls]: {
// Explain holder
transition: `opacity ${token.motionDurationSlow} ${token.motionEaseInOut}`,

'&-appear, &-enter': {
opacity: 0,

'&-active': {
opacity: 1,
},
},

'&-leave': {
opacity: 1,

'&-active': {
opacity: 0,
},
},

// Explain
[helpItemCls]: {
overflow: 'hidden',
transition: `height ${token.motionDurationSlow} ${token.motionEaseInOut},
opacity ${token.motionDurationSlow} ${token.motionEaseInOut},
transform ${token.motionDurationSlow} ${token.motionEaseInOut} !important`,

[`&${helpItemCls}-appear, &${helpItemCls}-enter`]: {
transform: `translateY(-5px)`,
opacity: 0,

[`&-active`]: {
transform: 'translateY(0)',
opacity: 1,
},
},

[`&${helpItemCls}-leave-active`]: {
transform: `translateY(-5px)`,
},
},
},
};
};

export default genFormValidateMotionStyle;
59 changes: 4 additions & 55 deletions components/form/style/index.tsx
Expand Up @@ -3,8 +3,9 @@ import { genCollapseMotion, zoomIn } from '../../style/motion';
import type { AliasToken, FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
import { resetComponent } from '../../style';
import genFormValidateMotionStyle from './explain';

interface FormToken extends FullToken<'Form'> {
export interface FormToken extends FullToken<'Form'> {
formItemCls: string;
rootPrefixCls: string;
}
Expand Down Expand Up @@ -261,7 +262,6 @@ const genFormItemStyle: GenerateStyle<FormToken> = (token) => {
color: token.colorTextDescription,
fontSize: token.fontSize,
lineHeight: token.lineHeight,
transition: `color ${token.motionDurationMid} ${token.motionEaseOut}`, // sync input color transition
},

'&-explain-connected': {
Expand All @@ -270,6 +270,7 @@ const genFormItemStyle: GenerateStyle<FormToken> = (token) => {

'&-extra': {
minHeight: token.controlHeightSM,
transition: `color ${token.motionDurationMid} ${token.motionEaseOut}`, // sync input color transition
},

'&-explain': {
Expand Down Expand Up @@ -320,58 +321,6 @@ const genFormItemStyle: GenerateStyle<FormToken> = (token) => {
};
};

const genFormMotionStyle: GenerateStyle<FormToken> = (token) => {
const { componentCls, rootPrefixCls } = token;

return {
[componentCls]: {
// Explain holder
[`.${rootPrefixCls}-show-help`]: {
transition: `opacity ${token.motionDurationSlow} ${token.motionEaseInOut}`,

'&-appear, &-enter': {
opacity: 0,

'&-active': {
opacity: 1,
},
},

'&-leave': {
opacity: 1,

'&-active': {
opacity: 0,
},
},
},

// Explain
[`.${rootPrefixCls}-show-help-item`]: {
overflow: 'hidden',
transition: `height ${token.motionDurationSlow} ${token.motionEaseInOut},
opacity ${token.motionDurationSlow} ${token.motionEaseInOut},
transform ${token.motionDurationSlow} ${token.motionEaseInOut} !important`,

[`&-appear,
&-enter`]: {
transform: `translateY(-5px)`,
opacity: 0,

'&-active': {
transform: 'translateY(0)',
opacity: 1,
},
},

'&-leave-active': {
transform: `translateY(-5px)`,
},
},
},
};
};

const genHorizontalStyle: GenerateStyle<FormToken> = (token) => {
const { componentCls, formItemCls, rootPrefixCls } = token;

Expand Down Expand Up @@ -543,7 +492,7 @@ export default genComponentStyleHook('Form', (token, { rootPrefixCls }) => {
return [
genFormStyle(formToken),
genFormItemStyle(formToken),
genFormMotionStyle(formToken),
genFormValidateMotionStyle(formToken),
genHorizontalStyle(formToken),
genInlineStyle(formToken),
genVerticalStyle(formToken),
Expand Down