diff --git a/components/modal/Modal.tsx b/components/modal/Modal.tsx index f10059d8d4..e3db3ee237 100644 --- a/components/modal/Modal.tsx +++ b/components/modal/Modal.tsx @@ -80,6 +80,7 @@ export interface ModalFuncProps { type?: string; keyboard?: boolean; getContainer?: (instance: React.ReactInstance) => HTMLElement; + autoFocusButton?: null | 'ok' | 'cancel'; } export type ModalFunc = (props: ModalFuncProps) => { diff --git a/components/modal/confirm.tsx b/components/modal/confirm.tsx index 5818336ce8..73ab1686f9 100644 --- a/components/modal/confirm.tsx +++ b/components/modal/confirm.tsx @@ -9,6 +9,7 @@ import { getConfirmLocale } from './locale'; interface ConfirmDialogProps extends ModalFuncProps { afterClose?: () => void; close: (...args: any[]) => void; + autoFocusButton?: null | 'ok' | 'cancel'; } const IS_REACT_16 = !!ReactDOM.createPortal; @@ -28,6 +29,7 @@ const ConfirmDialog = (props: ConfirmDialogProps) => { const okText = props.okText || (okCancel ? runtimeLocale.okText : runtimeLocale.justOkText); const cancelText = props.cancelText || runtimeLocale.cancelText; + const autoFocusButton = props.autoFocusButton === null ? false : props.autoFocusButton || 'ok'; const classString = classNames( prefixCls, @@ -36,7 +38,7 @@ const ConfirmDialog = (props: ConfirmDialogProps) => { ); const cancelButton = okCancel && ( - + {cancelText} ); @@ -68,7 +70,7 @@ const ConfirmDialog = (props: ConfirmDialogProps) => {
{cancelButton} - + {okText}
diff --git a/components/modal/index.en-US.md b/components/modal/index.en-US.md index dbcea893f7..1c9db5e31f 100644 --- a/components/modal/index.en-US.md +++ b/components/modal/index.en-US.md @@ -62,6 +62,7 @@ The properties of the object are follows: | Property | Description | Type | Default | | -------- | ----------- | ---- | ------- | +| autoFocusButton | Specify which button to autofocus | null\|string: `ok` `cancel` | `ok` | | cancelText | Text of the Cancel button | string | `Cancel` | | centered | Centered Modal | Boolean | `false` | | className | className of container | string | - | diff --git a/components/modal/index.zh-CN.md b/components/modal/index.zh-CN.md index 21660f99d1..bcad53e8b6 100644 --- a/components/modal/index.zh-CN.md +++ b/components/modal/index.zh-CN.md @@ -61,6 +61,7 @@ title: Modal | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | +| autoFocusButton | 指定自动获得焦点的按钮 | null\|string: `ok` `cancel` | `ok` | | cancelText | 取消按钮文字 | string | 取消 | | centered | 垂直居中展示 Modal | Boolean | `false` | | className | 容器类名 | string | - |