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

Add button autofocus prop to confirm modal #11756

Merged
merged 2 commits into from Sep 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions components/modal/Modal.tsx
Expand Up @@ -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) => {
Expand Down
6 changes: 4 additions & 2 deletions components/modal/confirm.tsx
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -36,7 +38,7 @@ const ConfirmDialog = (props: ConfirmDialogProps) => {
);

const cancelButton = okCancel && (
<ActionButton actionFn={onCancel} closeModal={close}>
<ActionButton actionFn={onCancel} closeModal={close} autoFocus={autoFocusButton === 'cancel'}>
{cancelText}
</ActionButton>
);
Expand Down Expand Up @@ -68,7 +70,7 @@ const ConfirmDialog = (props: ConfirmDialogProps) => {
</div>
<div className={`${prefixCls}-btns`}>
{cancelButton}
<ActionButton type={okType} actionFn={onOk} closeModal={close} autoFocus>
<ActionButton type={okType} actionFn={onOk} closeModal={close} autoFocus={autoFocusButton === 'ok'}>
{okText}
</ActionButton>
</div>
Expand Down
1 change: 1 addition & 0 deletions components/modal/index.en-US.md
Expand Up @@ -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` |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add something like this to the corresponding place in components/modal/index.zh-CN.md

| autoFocusButton | 指定自动获得焦点的按钮 | null\|string: `ok` `cancel` | `ok` |

| cancelText | Text of the Cancel button | string | `Cancel` |
| centered | Centered Modal | Boolean | `false` |
| className | className of container | string | - |
Expand Down
1 change: 1 addition & 0 deletions components/modal/index.zh-CN.md
Expand Up @@ -61,6 +61,7 @@ title: Modal

| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| autoFocusButton | 指定自动获得焦点的按钮 | null\|string: `ok` `cancel` | `ok` |
| cancelText | 取消按钮文字 | string | 取消 |
| centered | 垂直居中展示 Modal | Boolean | `false` |
| className | 容器类名 | string | - |
Expand Down