mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 05:05:48 +08:00
fix: remove defaultProps (#37815)
* fix: remove defaultProps * fix: remove defaultProps * fix: update snap * fix: fix * fix: fix
This commit is contained in:
parent
49206a53c5
commit
480cb3cbc3
@ -16231,7 +16231,6 @@ exports[`ConfigProvider components Input configProvider 1`] = `
|
||||
class="config-input-affix-wrapper config-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="config-input"
|
||||
type="password"
|
||||
value=""
|
||||
@ -16329,7 +16328,6 @@ exports[`ConfigProvider components Input configProvider componentDisabled 1`] =
|
||||
class="config-input-affix-wrapper config-input-affix-wrapper-disabled config-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="config-input config-input-disabled"
|
||||
disabled=""
|
||||
type="password"
|
||||
@ -16426,7 +16424,6 @@ exports[`ConfigProvider components Input configProvider componentSize large 1`]
|
||||
class="config-input-affix-wrapper config-input-password config-input-affix-wrapper-lg"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="config-input config-input-lg"
|
||||
type="password"
|
||||
value=""
|
||||
@ -16521,7 +16518,6 @@ exports[`ConfigProvider components Input configProvider componentSize middle 1`]
|
||||
class="config-input-affix-wrapper config-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="config-input"
|
||||
type="password"
|
||||
value=""
|
||||
@ -16616,7 +16612,6 @@ exports[`ConfigProvider components Input configProvider virtual and dropdownMatc
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
type="password"
|
||||
value=""
|
||||
@ -16711,7 +16706,6 @@ exports[`ConfigProvider components Input normal 1`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
type="password"
|
||||
value=""
|
||||
@ -16806,7 +16800,6 @@ exports[`ConfigProvider components Input prefixCls 1`] = `
|
||||
class="ant-input-affix-wrapper prefix-Input"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
type="password"
|
||||
value=""
|
||||
|
@ -680,7 +680,6 @@ exports[`renders ./components/form/demo/basic.md extend context correctly 1`] =
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
aria-required="true"
|
||||
class="ant-input"
|
||||
id="basic_password"
|
||||
@ -867,7 +866,6 @@ Array [
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
aria-required="true"
|
||||
class="ant-input"
|
||||
id="basic_password"
|
||||
@ -1237,7 +1235,6 @@ Array [
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
aria-required="true"
|
||||
class="ant-input"
|
||||
id="responsive_password"
|
||||
@ -6981,7 +6978,6 @@ exports[`renders ./components/form/demo/label-debug.md extend context correctly
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
id="label-ellipsis_password"
|
||||
type="password"
|
||||
@ -7997,7 +7993,6 @@ exports[`renders ./components/form/demo/register.md extend context correctly 1`]
|
||||
class="ant-input-affix-wrapper ant-input-password ant-input-affix-wrapper-has-feedback"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
aria-required="true"
|
||||
class="ant-input"
|
||||
id="register_password"
|
||||
@ -8067,7 +8062,6 @@ exports[`renders ./components/form/demo/register.md extend context correctly 1`]
|
||||
class="ant-input-affix-wrapper ant-input-password ant-input-affix-wrapper-has-feedback"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
aria-required="true"
|
||||
class="ant-input"
|
||||
id="register_confirm"
|
||||
@ -26210,7 +26204,6 @@ exports[`renders ./components/form/demo/validate-static.md extend context correc
|
||||
class="ant-input-affix-wrapper ant-input-password ant-input-affix-wrapper-status-warning ant-input-affix-wrapper-has-feedback"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
placeholder="with input password"
|
||||
type="password"
|
||||
@ -26301,7 +26294,6 @@ exports[`renders ./components/form/demo/validate-static.md extend context correc
|
||||
class="ant-input-affix-wrapper ant-input-password ant-input-affix-wrapper-status-error ant-input-affix-wrapper-has-feedback"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
placeholder="with input password and allowClear"
|
||||
type="password"
|
||||
|
@ -516,7 +516,6 @@ exports[`renders ./components/form/demo/basic.md correctly 1`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
aria-required="true"
|
||||
class="ant-input"
|
||||
id="basic_password"
|
||||
@ -703,7 +702,6 @@ Array [
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
aria-required="true"
|
||||
class="ant-input"
|
||||
id="basic_password"
|
||||
@ -966,7 +964,6 @@ Array [
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
aria-required="true"
|
||||
class="ant-input"
|
||||
id="responsive_password"
|
||||
@ -4382,7 +4379,6 @@ exports[`renders ./components/form/demo/label-debug.md correctly 1`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
id="label-ellipsis_password"
|
||||
type="password"
|
||||
@ -5398,7 +5394,6 @@ exports[`renders ./components/form/demo/register.md correctly 1`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password ant-input-affix-wrapper-has-feedback"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
aria-required="true"
|
||||
class="ant-input"
|
||||
id="register_password"
|
||||
@ -5468,7 +5463,6 @@ exports[`renders ./components/form/demo/register.md correctly 1`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password ant-input-affix-wrapper-has-feedback"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
aria-required="true"
|
||||
class="ant-input"
|
||||
id="register_confirm"
|
||||
@ -10869,7 +10863,6 @@ exports[`renders ./components/form/demo/validate-static.md correctly 1`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password ant-input-affix-wrapper-status-warning ant-input-affix-wrapper-has-feedback"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
placeholder="with input password"
|
||||
type="password"
|
||||
@ -10960,7 +10953,6 @@ exports[`renders ./components/form/demo/validate-static.md correctly 1`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password ant-input-affix-wrapper-status-error ant-input-affix-wrapper-has-feedback"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
placeholder="with input password and allowClear"
|
||||
type="password"
|
||||
|
@ -2,6 +2,7 @@ import classNames from 'classnames';
|
||||
import * as React from 'react';
|
||||
import { useContext, useMemo } from 'react';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
import type { FormItemStatusContextProps } from '../form/context';
|
||||
import { FormItemInputContext } from '../form/context';
|
||||
|
||||
export interface GroupProps {
|
||||
@ -33,7 +34,8 @@ const Group: React.FC<GroupProps> = props => {
|
||||
);
|
||||
|
||||
const formItemContext = useContext(FormItemInputContext);
|
||||
const groupFormItemContext = useMemo(
|
||||
|
||||
const groupFormItemContext = useMemo<FormItemStatusContextProps>(
|
||||
() => ({
|
||||
...formItemContext,
|
||||
isFormItemInput: false,
|
||||
|
@ -2,6 +2,7 @@ import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
|
||||
import classNames from 'classnames';
|
||||
import type { InputProps as RcInputProps, InputRef } from 'rc-input';
|
||||
import RcInput from 'rc-input';
|
||||
import type { BaseInputProps } from 'rc-input/lib/interface';
|
||||
import { composeRef } from 'rc-util/lib/ref';
|
||||
import React, { forwardRef, useContext, useEffect, useRef } from 'react';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
@ -85,7 +86,9 @@ export function triggerFocus(
|
||||
element?: HTMLInputElement | HTMLTextAreaElement,
|
||||
option?: InputFocusOptions,
|
||||
) {
|
||||
if (!element) return;
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
|
||||
element.focus(option);
|
||||
|
||||
@ -98,13 +101,12 @@ export function triggerFocus(
|
||||
case 'start':
|
||||
element.setSelectionRange(0, 0);
|
||||
break;
|
||||
|
||||
case 'end':
|
||||
element.setSelectionRange(len, len);
|
||||
break;
|
||||
|
||||
default:
|
||||
element.setSelectionRange(0, len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,7 +214,7 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
|
||||
);
|
||||
|
||||
// Allow clear
|
||||
let mergedAllowClear;
|
||||
let mergedAllowClear: BaseInputProps['allowClear'];
|
||||
if (typeof allowClear === 'object' && allowClear?.clearIcon) {
|
||||
mergedAllowClear = allowClear;
|
||||
} else if (allowClear) {
|
||||
|
@ -3,13 +3,15 @@ import EyeOutlined from '@ant-design/icons/EyeOutlined';
|
||||
import classNames from 'classnames';
|
||||
import omit from 'rc-util/lib/omit';
|
||||
import * as React from 'react';
|
||||
|
||||
import { useState } from 'react';
|
||||
import type { ConfigConsumerProps } from '../config-provider';
|
||||
import { ConfigConsumer } from '../config-provider';
|
||||
import type { InputProps, InputRef } from './Input';
|
||||
import Input from './Input';
|
||||
|
||||
const defaultIconRender = (visible: boolean) =>
|
||||
visible ? <EyeOutlined /> : <EyeInvisibleOutlined />;
|
||||
|
||||
export interface PasswordProps extends InputProps {
|
||||
readonly inputPrefixCls?: string;
|
||||
readonly action?: string;
|
||||
@ -30,13 +32,12 @@ const Password = React.forwardRef<InputRef, PasswordProps>((props, ref) => {
|
||||
if (disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
setVisible(!visible);
|
||||
setVisible(prevState => !prevState);
|
||||
};
|
||||
|
||||
const getIcon = (prefixCls: string) => {
|
||||
const { action, iconRender = () => null } = props;
|
||||
const iconTrigger = ActionMap[action!] || '';
|
||||
const { action = 'click', iconRender = defaultIconRender } = props;
|
||||
const iconTrigger = ActionMap[action] || '';
|
||||
const icon = iconRender(visible);
|
||||
const iconProps = {
|
||||
[iconTrigger]: onVisibleChange,
|
||||
@ -62,7 +63,7 @@ const Password = React.forwardRef<InputRef, PasswordProps>((props, ref) => {
|
||||
prefixCls: customizePrefixCls,
|
||||
inputPrefixCls: customizeInputPrefixCls,
|
||||
size,
|
||||
visibilityToggle,
|
||||
visibilityToggle = true,
|
||||
...restProps
|
||||
} = props;
|
||||
|
||||
@ -92,12 +93,6 @@ const Password = React.forwardRef<InputRef, PasswordProps>((props, ref) => {
|
||||
return <ConfigConsumer>{renderPassword}</ConfigConsumer>;
|
||||
});
|
||||
|
||||
Password.defaultProps = {
|
||||
action: 'click',
|
||||
visibilityToggle: true,
|
||||
iconRender: (visible: boolean) => (visible ? <EyeOutlined /> : <EyeInvisibleOutlined />),
|
||||
};
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
Password.displayName = 'Password';
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ exports[`Input.Password rtl render component should be rendered correctly in RTL
|
||||
class="ant-input-affix-wrapper ant-input-password ant-input-affix-wrapper-rtl"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input ant-input-rtl"
|
||||
type="password"
|
||||
value=""
|
||||
@ -45,7 +44,6 @@ exports[`Input.Password should change type when click 1`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
type="password"
|
||||
value="111"
|
||||
@ -85,7 +83,6 @@ exports[`Input.Password should change type when click 2`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
type="text"
|
||||
value="111"
|
||||
@ -122,7 +119,6 @@ exports[`Input.Password should change type when click 3`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
type="password"
|
||||
value="111"
|
||||
@ -162,7 +158,6 @@ exports[`Input.Password should support size 1`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password ant-input-password-large ant-input-affix-wrapper-lg"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input ant-input-lg"
|
||||
type="password"
|
||||
value=""
|
||||
|
@ -8678,7 +8678,6 @@ exports[`renders ./components/input/demo/password-input.md extend context correc
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
placeholder="input password"
|
||||
type="password"
|
||||
@ -8720,7 +8719,6 @@ exports[`renders ./components/input/demo/password-input.md extend context correc
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
placeholder="input password"
|
||||
type="password"
|
||||
|
@ -2483,7 +2483,6 @@ exports[`renders ./components/input/demo/password-input.md correctly 1`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
placeholder="input password"
|
||||
type="password"
|
||||
@ -2525,7 +2524,6 @@ exports[`renders ./components/input/demo/password-input.md correctly 1`] = `
|
||||
class="ant-input-affix-wrapper ant-input-password"
|
||||
>
|
||||
<input
|
||||
action="click"
|
||||
class="ant-input"
|
||||
placeholder="input password"
|
||||
type="password"
|
||||
|
@ -7,6 +7,7 @@ import Input from '..';
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
import rtlTest from '../../../tests/shared/rtlTest';
|
||||
import Form from '../../form';
|
||||
import { triggerFocus } from '../Input';
|
||||
|
||||
describe('Input', () => {
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
@ -433,7 +434,7 @@ describe('Input allowClear', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('typescript types ', () => {
|
||||
describe('typescript types', () => {
|
||||
it('InputProps type should support data-* attributes', () => {
|
||||
const props: InputProps = {
|
||||
value: 123,
|
||||
@ -448,3 +449,11 @@ describe('typescript types ', () => {
|
||||
expect(input?.getAttribute('data-id')).toBe('12345');
|
||||
});
|
||||
});
|
||||
|
||||
describe('triggerFocus', () => {
|
||||
it('triggerFocus correctly run when element is null', () => {
|
||||
expect(() => {
|
||||
triggerFocus();
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
@ -5,6 +5,6 @@
|
||||
*/
|
||||
import React from 'react';
|
||||
|
||||
const AppShell = () => <div />;
|
||||
const AppShell: React.FC = () => <div />;
|
||||
|
||||
export default AppShell;
|
@ -1,5 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
const BrowserFrame = ({ children }) => <div className="browser-mockup with-url">{children}</div>;
|
||||
|
||||
export default BrowserFrame;
|
11
site/theme/template/BrowserFrame.tsx
Normal file
11
site/theme/template/BrowserFrame.tsx
Normal file
@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
|
||||
interface BrowserFrameProps {
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
const BrowserFrame: React.FC<BrowserFrameProps> = ({ children }) => (
|
||||
<div className="browser-mockup with-url">{children}</div>
|
||||
);
|
||||
|
||||
export default BrowserFrame;
|
Loading…
Reference in New Issue
Block a user