diff --git a/components/config-provider/__tests__/components.test.js b/components/config-provider/__tests__/components.test.js index 436308dfe6..3b1a67cd85 100644 --- a/components/config-provider/__tests__/components.test.js +++ b/components/config-provider/__tests__/components.test.js @@ -392,7 +392,7 @@ describe('ConfigProvider', () => { // Modal testPair('Modal', props => (
- + Bamboo is Little Light
diff --git a/components/config-provider/demo/direction.md b/components/config-provider/demo/direction.md index 6b9fcd79d4..1cacb536f7 100644 --- a/components/config-provider/demo/direction.md +++ b/components/config-provider/demo/direction.md @@ -108,7 +108,7 @@ type Placement = 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight'; const Page: React.FC<{ popupPlacement: Placement }> = ({ popupPlacement }) => { const [currentStep, setCurrentStep] = useState(0); - const [modalVisible, setModalVisible] = useState(false); + const [modalOpen, setModalOpen] = useState(false); const [badgeCount, setBadgeCount] = useState(5); const [showBadge, setShowBadge] = useState(true); @@ -139,17 +139,17 @@ const Page: React.FC<{ popupPlacement: Placement }> = ({ popupPlacement }) => { // ==== Modal ==== const showModal = () => { - setModalVisible(true); + setModalOpen(true); }; const handleOk = (e: React.MouseEvent) => { console.log(e); - setModalVisible(false); + setModalOpen(false); }; const handleCancel = (e: React.MouseEvent) => { console.log(e); - setModalVisible(false); + setModalOpen(false); }; // ==== End Modal ==== @@ -378,12 +378,7 @@ const Page: React.FC<{ popupPlacement: Placement }> = ({ popupPlacement }) => { - +

نگاشته‌های خود را اینجا قراردهید

نگاشته‌های خود را اینجا قراردهید

نگاشته‌های خود را اینجا قراردهید

diff --git a/components/config-provider/demo/locale.md b/components/config-provider/demo/locale.md index 8bd720d01e..b00d209db0 100644 --- a/components/config-provider/demo/locale.md +++ b/components/config-provider/demo/locale.md @@ -58,14 +58,14 @@ const columns = [ ]; const Page = () => { - const [visible, setVisible] = useState(false); + const [open, setOpen] = useState(false); const showModal = () => { - setVisible(true); + setOpen(true); }; const hideModal = () => { - setVisible(false); + setOpen(false); }; const info = () => { @@ -115,7 +115,7 @@ const Page = () => {
- +

Locale Modal

diff --git a/components/form/__tests__/index.test.js b/components/form/__tests__/index.test.js index dd4db602bc..31243c9ab6 100644 --- a/components/form/__tests__/index.test.js +++ b/components/form/__tests__/index.test.js @@ -1232,7 +1232,7 @@ describe('Form', () => { const Demo = () => (
- + @@ -79,14 +79,14 @@ const ModalForm: React.FC = ({ visible, onCancel }) => { }; const App: React.FC = () => { - const [visible, setVisible] = useState(false); + const [open, setOpen] = useState(false); const showUserModal = () => { - setVisible(true); + setOpen(true); }; const hideUserModal = () => { - setVisible(false); + setOpen(false); }; const onFinish = (values: any) => { @@ -100,7 +100,7 @@ const App: React.FC = () => { const { basicForm } = forms; const users = basicForm.getFieldValue('users') || []; basicForm.setFieldsValue({ users: [...users, values] }); - setVisible(false); + setOpen(false); } }} > @@ -140,7 +140,7 @@ const App: React.FC = () => { - + ); }; diff --git a/components/form/demo/form-in-modal.md b/components/form/demo/form-in-modal.md index a1f3b14626..145902bb38 100644 --- a/components/form/demo/form-in-modal.md +++ b/components/form/demo/form-in-modal.md @@ -26,20 +26,20 @@ interface Values { } interface CollectionCreateFormProps { - visible: boolean; + open: boolean; onCreate: (values: Values) => void; onCancel: () => void; } const CollectionCreateForm: React.FC = ({ - visible, + open, onCreate, onCancel, }) => { const [form] = Form.useForm(); return ( = ({ }; const App: React.FC = () => { - const [visible, setVisible] = useState(false); + const [open, setOpen] = useState(false); const onCreate = (values: any) => { console.log('Received values of form: ', values); - setVisible(false); + setOpen(false); }; return ( @@ -96,16 +96,16 @@ const App: React.FC = () => { { - setVisible(false); + setOpen(false); }} /> diff --git a/components/locale-provider/__tests__/index.test.js b/components/locale-provider/__tests__/index.test.js index 0114a0a4bd..29781a6672 100644 --- a/components/locale-provider/__tests__/index.test.js +++ b/components/locale-provider/__tests__/index.test.js @@ -191,7 +191,7 @@ const App = () => ( item.title} />
- +

Locale Modal

diff --git a/components/modal/ConfirmDialog.tsx b/components/modal/ConfirmDialog.tsx index 2af9d95b4e..3a8e5bb9fc 100644 --- a/components/modal/ConfirmDialog.tsx +++ b/components/modal/ConfirmDialog.tsx @@ -24,6 +24,7 @@ const ConfirmDialog = (props: ConfirmDialogProps) => { zIndex, afterClose, visible, + open, keyboard, centered, getContainer, @@ -90,8 +91,8 @@ const ConfirmDialog = (props: ConfirmDialogProps) => { { [`${contentPrefixCls}-centered`]: !!props.centered }, wrapClassName, )} - onCancel={() => close({ triggerCancel: true })} - visible={visible} + onCancel={() => close?.({ triggerCancel: true })} + open={open || visible} title="" footer="" transitionName={getTransitionName(rootPrefixCls, 'zoom', props.transitionName)} diff --git a/components/modal/Modal.tsx b/components/modal/Modal.tsx index d2d1d950cc..8872686571 100644 --- a/components/modal/Modal.tsx +++ b/components/modal/Modal.tsx @@ -12,6 +12,7 @@ import { NoFormStyle } from '../form/context'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; import { getTransitionName } from '../_util/motion'; import { canUseDocElement } from '../_util/styleChecker'; +import warning from '../_util/warning'; import { getConfirmLocale } from './locale'; let mousePosition: { x: number; y: number } | null; @@ -37,7 +38,12 @@ if (canUseDocElement()) { export interface ModalProps { /** 对话框是否可见 */ + /** + * @deprecated `visible` is deprecated which will be removed in next major version. Please use + * `open` instead. + */ visible?: boolean; + open?: boolean; /** 确定按钮 loading */ confirmLoading?: boolean; /** 标题 */ @@ -92,7 +98,12 @@ type getContainerFunc = () => HTMLElement; export interface ModalFuncProps { prefixCls?: string; className?: string; + /** + * @deprecated `visible` is deprecated which will be removed in next major version. Please use + * `open` instead. + */ visible?: boolean; + open?: boolean; title?: React.ReactNode; closable?: boolean; content?: React.ReactNode; @@ -151,6 +162,12 @@ const Modal: React.FC = props => { onOk?.(e); }; + warning( + !('visible' in props), + 'Modal', + `\`visible\` will be removed in next major version, please use \`open\` instead.`, + ); + const renderFooter = (locale: ModalLocale) => { const { okText, okType, cancelText, confirmLoading } = props; return ( @@ -174,6 +191,7 @@ const Modal: React.FC = props => { prefixCls: customizePrefixCls, footer, visible, + open, wrapClassName, centered, getContainer, @@ -211,7 +229,7 @@ const Modal: React.FC = props => { prefixCls={prefixCls} wrapClassName={wrapClassNameExtended} footer={footer === undefined ? defaultFooter : footer} - visible={visible} + visible={open || visible} mousePosition={mousePosition} onClose={handleCancel} closeIcon={closeIconToRender} @@ -226,7 +244,7 @@ const Modal: React.FC = props => { Modal.defaultProps = { width: 520, confirmLoading: false, - visible: false, + open: false, okType: 'primary' as LegacyButtonType, }; diff --git a/components/modal/__tests__/Modal.test.tsx b/components/modal/__tests__/Modal.test.tsx index 177a5f131c..18a75da560 100644 --- a/components/modal/__tests__/Modal.test.tsx +++ b/components/modal/__tests__/Modal.test.tsx @@ -4,14 +4,15 @@ import Modal from '..'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; import { fireEvent, render } from '../../../tests/utils'; +import { resetWarned } from '../../_util/warning'; jest.mock('rc-util/lib/Portal'); -class ModalTester extends React.Component { - state = { visible: false }; +class ModalTester extends React.Component { + state = { open: false }; componentDidMount() { - this.setState({ visible: true }); // eslint-disable-line react/no-did-mount-set-state + this.setState({ open: true }); // eslint-disable-line react/no-did-mount-set-state } container = React.createRef(); @@ -19,11 +20,11 @@ class ModalTester extends React.Component { getContainer = () => this.container?.current!; render() { - const { visible } = this.state; + const { open } = this.state; return (
- + Here is content of Modal
@@ -36,7 +37,7 @@ describe('Modal', () => { rtlTest(Modal); it('support closeIcon', () => { - render(closeIcon} visible />); + render(closeIcon} open />); expect(document.body.querySelectorAll('.ant-modal-root')[0]).toMatchSnapshot(); }); @@ -52,35 +53,35 @@ describe('Modal', () => { it('onCancel should be called', () => { const onCancel = jest.fn(); - render(); + render(); fireEvent.click(document.body.querySelectorAll('.ant-btn')[0]); expect(onCancel).toHaveBeenCalled(); }); it('onOk should be called', () => { const onOk = jest.fn(); - render(); + render(); const btns = document.body.querySelectorAll('.ant-btn'); fireEvent.click(btns[btns.length - 1]); expect(onOk).toHaveBeenCalled(); }); it('danger type', () => { - render(); + render(); const btns = document.body.querySelectorAll('.ant-btn'); expect(btns[btns.length - 1].classList.contains('ant-btn-dangerous')).toBeTruthy(); }); it('mouse position', () => { const Demo = () => { - const [visible, setVisible] = React.useState(false); + const [open, setOpen] = React.useState(false); const containerRef = React.useRef(null); return (
-
setVisible(true)}> +
setOpen(true)}> click me
- containerRef.current!} /> + containerRef.current!} />
); }; @@ -90,4 +91,18 @@ describe('Modal', () => { (container.querySelectorAll('.ant-modal')[0] as HTMLDivElement).style.transformOrigin, ).toBeTruthy(); }); + + it('deprecated warning', () => { + resetWarned(); + const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + + render(); + expect(errSpy).toHaveBeenCalledWith( + 'Warning: [antd: Modal] `visible` will be removed in next major version, please use `open` instead.', + ); + + expect(document.querySelector('.ant-modal')).toBeTruthy(); + + errSpy.mockRestore(); + }); }); diff --git a/components/modal/confirm.tsx b/components/modal/confirm.tsx index bfa807ff94..a8e05c9574 100644 --- a/components/modal/confirm.tsx +++ b/components/modal/confirm.tsx @@ -29,7 +29,7 @@ export type ModalStaticFunctions = Record, M export default function confirm(config: ModalFuncProps) { const container = document.createDocumentFragment(); // eslint-disable-next-line @typescript-eslint/no-use-before-define - let currentConfig = { ...config, close, visible: true } as any; + let currentConfig = { ...config, close, open: true } as any; function destroy(...args: any[]) { const triggerCancel = args.some(param => param && param.triggerCancel); @@ -79,7 +79,7 @@ export default function confirm(config: ModalFuncProps) { function close(...args: any[]) { currentConfig = { ...currentConfig, - visible: false, + open: false, afterClose: () => { if (typeof config.afterClose === 'function') { config.afterClose(); diff --git a/components/modal/demo/async.md b/components/modal/demo/async.md index 52dc80605d..e5dded5ac6 100644 --- a/components/modal/demo/async.md +++ b/components/modal/demo/async.md @@ -18,26 +18,26 @@ import { Button, Modal } from 'antd'; import React, { useState } from 'react'; const App: React.FC = () => { - const [visible, setVisible] = useState(false); + const [open, setOpen] = useState(false); const [confirmLoading, setConfirmLoading] = useState(false); const [modalText, setModalText] = useState('Content of the modal'); const showModal = () => { - setVisible(true); + setOpen(true); }; const handleOk = () => { setModalText('The modal will be closed after two seconds'); setConfirmLoading(true); setTimeout(() => { - setVisible(false); + setOpen(false); setConfirmLoading(false); }, 2000); }; const handleCancel = () => { console.log('Clicked cancel button'); - setVisible(false); + setOpen(false); }; return ( @@ -47,7 +47,7 @@ const App: React.FC = () => { { - const [isModalVisible, setIsModalVisible] = useState(false); + const [isModalOpen, setIsModalOpen] = useState(false); const showModal = () => { - setIsModalVisible(true); + setIsModalOpen(true); }; const handleOk = () => { - setIsModalVisible(false); + setIsModalOpen(false); }; const handleCancel = () => { - setIsModalVisible(false); + setIsModalOpen(false); }; return ( @@ -37,7 +37,7 @@ const App: React.FC = () => { - +

Some contents...

Some contents...

Some contents...

diff --git a/components/modal/demo/button-props.md b/components/modal/demo/button-props.md index de6ec2d2af..da61638ae2 100644 --- a/components/modal/demo/button-props.md +++ b/components/modal/demo/button-props.md @@ -18,20 +18,20 @@ import { Button, Modal } from 'antd'; import React, { useState } from 'react'; const App: React.FC = () => { - const [visible, setVisible] = useState(false); + const [open, setOpen] = useState(false); const showModal = () => { - setVisible(true); + setOpen(true); }; const handleOk = (e: React.MouseEvent) => { console.log(e); - setVisible(false); + setOpen(false); }; const handleCancel = (e: React.MouseEvent) => { console.log(e); - setVisible(false); + setOpen(false); }; return ( @@ -41,7 +41,7 @@ const App: React.FC = () => { ( ); export default () => { - const [visible, setVisible] = useState(false); + const [open, setOpen] = useState(false); const [targetKeys, setTargetKeys] = useState(oriTargetKeys); const [selectedKeys, setSelectedKeys] = useState([]); const [disabled, setDisabled] = useState(false); @@ -329,17 +329,17 @@ export default () => { }; const showModal = () => { - setVisible(true); + setOpen(true); }; const handleOk = e => { console.log(e); - setVisible(false); + setOpen(false); }; const handleCancel = e => { console.log(e); - setVisible(false); + setOpen(false); }; const columns = [ @@ -385,7 +385,7 @@ export default () => { - + { const [loading, setLoading] = useState(false); - const [visible, setVisible] = useState(false); + const [open, setOpen] = useState(false); const showModal = () => { - setVisible(true); + setOpen(true); }; const handleOk = () => { setLoading(true); setTimeout(() => { setLoading(false); - setVisible(false); + setOpen(false); }, 3000); }; const handleCancel = () => { - setVisible(false); + setOpen(false); }; return ( @@ -47,7 +47,7 @@ const App: React.FC = () => { Open Modal with customized footer { - const [visible, setVisible] = useState(false); + const [open, setOpen] = useState(false); const showModal = () => { - setVisible(true); + setOpen(true); }; const hideModal = () => { - setVisible(false); + setOpen(false); }; return ( @@ -36,7 +36,7 @@ const LocalizedModal = () => { { - const [visible, setVisible] = useState(false); + const [open, setOpen] = useState(false); const [disabled, setDisabled] = useState(false); const [bounds, setBounds] = useState({ left: 0, top: 0, bottom: 0, right: 0 }); const draggleRef = useRef(null); const showModal = () => { - setVisible(true); + setOpen(true); }; const handleOk = (e: React.MouseEvent) => { console.log(e); - setVisible(false); + setOpen(false); }; const handleCancel = (e: React.MouseEvent) => { console.log(e); - setVisible(false); + setOpen(false); }; const onStart = (_event: DraggableEvent, uiData: DraggableData) => { @@ -80,7 +80,7 @@ const App: React.FC = () => { Draggable Modal
} - visible={visible} + open={open} onOk={handleOk} onCancel={handleCancel} modalRender={modal => ( diff --git a/components/modal/demo/position.md b/components/modal/demo/position.md index 6f8e368ab9..636e6a6b4b 100644 --- a/components/modal/demo/position.md +++ b/components/modal/demo/position.md @@ -18,20 +18,20 @@ import { Button, Modal } from 'antd'; import React, { useState } from 'react'; const App: React.FC = () => { - const [modal1Visible, setModal1Visible] = useState(false); - const [modal2Visible, setModal2Visible] = useState(false); + const [modal1Open, setModal1Open] = useState(false); + const [modal2Open, setModal2Open] = useState(false); return ( <> - setModal1Visible(false)} - onCancel={() => setModal1Visible(false)} + visible={modal1Open} + onOk={() => setModal1Open(false)} + onCancel={() => setModal1Open(false)} >

some contents...

some contents...

@@ -39,15 +39,15 @@ const App: React.FC = () => {


- setModal2Visible(false)} - onCancel={() => setModal2Visible(false)} + visible={modal2Open} + onOk={() => setModal2Open(false)} + onCancel={() => setModal2Open(false)} >

some contents...

some contents...

diff --git a/components/modal/demo/width.md b/components/modal/demo/width.md index 6e9f2cf26d..5a3e29a8e5 100644 --- a/components/modal/demo/width.md +++ b/components/modal/demo/width.md @@ -18,19 +18,19 @@ import { Button, Modal } from 'antd'; import React, { useState } from 'react'; const App: React.FC = () => { - const [visible, setVisible] = useState(false); + const [open, setOpen] = useState(false); return ( <> - setVisible(false)} - onCancel={() => setVisible(false)} + open={open} + onOk={() => setOpen(false)} + onCancel={() => setOpen(false)} width={1000} >

some contents...

diff --git a/components/modal/index.en-US.md b/components/modal/index.en-US.md index 85d8a8caf6..e4e63d97bb 100644 --- a/components/modal/index.en-US.md +++ b/components/modal/index.en-US.md @@ -38,7 +38,7 @@ When requiring users to interact with the application, but without jumping to a | okType | Button `type` of the OK button | string | `primary` | | | style | Style of floating layer, typically used at least for adjusting the position | CSSProperties | - | | | title | The modal dialog's title | ReactNode | - | | -| visible | Whether the modal dialog is visible or not | boolean | false | | +| open | Whether the modal dialog is visible or not | boolean | false | 4.23.0 | | width | Width of the modal dialog | string \| number | 520 | | | wrapClassName | The class name of the container of the modal dialog | string | - | | | zIndex | The `z-index` of the Modal | number | 1000 | | diff --git a/components/modal/index.zh-CN.md b/components/modal/index.zh-CN.md index 0308d2aa13..fb936d0ad0 100644 --- a/components/modal/index.zh-CN.md +++ b/components/modal/index.zh-CN.md @@ -41,7 +41,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/3StSdUlSH/Modal.svg | okType | 确认按钮类型 | string | `primary` | | | style | 可用于设置浮层的样式,调整浮层位置等 | CSSProperties | - | | | title | 标题 | ReactNode | - | | -| visible | 对话框是否可见 | boolean | - | | +| open | 对话框是否可见 | boolean | - | 4.23.0 | | width | 宽度 | string \| number | 520 | | | wrapClassName | 对话框外层容器的类名 | string | - | | | zIndex | 设置 Modal 的 `z-index` | number | 1000 | | diff --git a/components/modal/useModal/HookModal.tsx b/components/modal/useModal/HookModal.tsx index e911805ae7..35c0d992e1 100644 --- a/components/modal/useModal/HookModal.tsx +++ b/components/modal/useModal/HookModal.tsx @@ -25,7 +25,7 @@ const HookModal: React.ForwardRefRenderFunction = { afterClose, config }, ref, ) => { - const [visible, setVisible] = React.useState(true); + const [open, setOpen] = React.useState(true); const [innerConfig, setInnerConfig] = React.useState(config); const { direction, getPrefixCls } = React.useContext(ConfigContext); @@ -33,7 +33,7 @@ const HookModal: React.ForwardRefRenderFunction = const rootPrefixCls = getPrefixCls(); const close = (...args: any[]) => { - setVisible(false); + setOpen(false); const triggerCancel = args.some(param => param && param.triggerCancel); if (innerConfig.onCancel && triggerCancel) { innerConfig.onCancel(() => {}, ...args.slice(1)); @@ -58,7 +58,7 @@ const HookModal: React.ForwardRefRenderFunction = rootPrefixCls={rootPrefixCls} {...innerConfig} close={close} - visible={visible} + open={open} afterClose={afterClose} okText={ innerConfig.okText || diff --git a/components/upload/demo/file-type.md b/components/upload/demo/file-type.md index c185ea6bd7..8244164424 100644 --- a/components/upload/demo/file-type.md +++ b/components/upload/demo/file-type.md @@ -37,7 +37,7 @@ const getBase64 = (file: RcFile): Promise => }); const App: React.FC = () => { - const [previewVisible, setPreviewVisible] = useState(false); + const [previewOpen, setPreviewOpen] = useState(false); const [previewImage, setPreviewImage] = useState(''); const [fileList, setFileList] = useState([ { @@ -69,14 +69,14 @@ const App: React.FC = () => { }, ]); - const handleCancel = () => setPreviewVisible(false); + const handleCancel = () => setPreviewOpen(false); const handlePreview = async (file: UploadFile) => { if (!file.url && !file.preview) { file.preview = await getBase64(file.originFileObj as RcFile); } - setPreviewVisible(true); + setPreviewOpen(true); setPreviewImage(file.url || (file.preview as string)); }; @@ -128,7 +128,7 @@ const App: React.FC = () => { > {fileList.length >= 8 ? null : uploadButton} - + example diff --git a/components/upload/demo/picture-card.md b/components/upload/demo/picture-card.md index d048d143d8..dde1bb464b 100644 --- a/components/upload/demo/picture-card.md +++ b/components/upload/demo/picture-card.md @@ -29,7 +29,7 @@ const getBase64 = (file: RcFile): Promise => }); const App: React.FC = () => { - const [previewVisible, setPreviewVisible] = useState(false); + const [previewOpen, setPreviewOpen] = useState(false); const [previewImage, setPreviewImage] = useState(''); const [previewTitle, setPreviewTitle] = useState(''); const [fileList, setFileList] = useState([ @@ -71,7 +71,7 @@ const App: React.FC = () => { }, ]); - const handleCancel = () => setPreviewVisible(false); + const handleCancel = () => setPreviewOpen(false); const handlePreview = async (file: UploadFile) => { if (!file.url && !file.preview) { @@ -79,7 +79,7 @@ const App: React.FC = () => { } setPreviewImage(file.url || (file.preview as string)); - setPreviewVisible(true); + setPreviewOpen(true); setPreviewTitle(file.name || file.url!.substring(file.url!.lastIndexOf('/') + 1)); }; @@ -103,7 +103,7 @@ const App: React.FC = () => { > {fileList.length >= 8 ? null : uploadButton} - + example diff --git a/site/theme/template/IconDisplay/IconPicSearcher.tsx b/site/theme/template/IconDisplay/IconPicSearcher.tsx index cad8154044..2478058436 100644 --- a/site/theme/template/IconDisplay/IconPicSearcher.tsx +++ b/site/theme/template/IconDisplay/IconPicSearcher.tsx @@ -23,7 +23,7 @@ interface PicSearcherProps { interface PicSearcherState { loading: boolean; - modalVisible: boolean; + modalOpen: boolean; popoverVisible: boolean; icons: iconObject[]; fileList: any[]; @@ -40,7 +40,7 @@ const PicSearcher: React.FC = ({ intl }) => { const { messages } = intl; const [state, setState] = useState({ loading: false, - modalVisible: false, + modalOpen: false, popoverVisible: false, icons: [], fileList: [], @@ -104,7 +104,7 @@ const PicSearcher: React.FC = ({ intl }) => { const toggleModal = useCallback(() => { setState(prev => ({ ...prev, - modalVisible: !prev.modalVisible, + modalOpen: !prev.modalOpen, popoverVisible: false, fileList: [], icons: [], @@ -146,7 +146,7 @@ const PicSearcher: React.FC = ({ intl }) => {