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
Conversation
Deploy preview for ant-design ready! Built with commit 1d505f5 |
components/modal/confirm.tsx
Outdated
@@ -9,6 +9,7 @@ import { getConfirmLocale } from './locale'; | |||
interface ConfirmDialogProps extends ModalFuncProps { | |||
afterClose?: () => void; | |||
close: (...args: any[]) => void; | |||
autoFocusBtn: 'ok' | 'cancel'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider #11055 and we can set autoFocusBtn
to null|false|undefined
for no focused button.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
autoFocusBtn => autoFocusButton
components/modal/confirm.tsx
Outdated
@@ -28,6 +29,7 @@ const ConfirmDialog = (props: ConfirmDialogProps) => { | |||
const okText = props.okText || | |||
(okCancel ? runtimeLocale.okText : runtimeLocale.justOkText); | |||
const cancelText = props.cancelText || runtimeLocale.cancelText; | |||
const focus = props.autoFocusBtn || 'ok'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't rename autoFocusBtn;
ci failed |
@afc163 Done. |
Don't forget update API documentation. |
components/modal/confirm.tsx
Outdated
@@ -9,6 +9,7 @@ import { getConfirmLocale } from './locale'; | |||
interface ConfirmDialogProps extends ModalFuncProps { | |||
afterClose?: () => void; | |||
close: (...args: any[]) => void; | |||
autoFocusButton?: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not:
autoFocusButton?: null | 'ok' | 'cancel'
?
@afc163 Can I add this feature to Modal component aswell? |
@erwin-k That is cool |
@afc163 In the end didn't do it for Modal component cause it'd only focus on first open. |
components/modal/confirm.tsx
Outdated
@@ -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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this line? We can simply use props.autoFocusButton directly.
const { autoFocusButton = 'ok' } = this.props;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that give 'ok' when null is passed? Passing null serves to disable autofocus in this case.
@@ -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` | |
There was a problem hiding this comment.
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` |
ci is still broken. |
@afc163 I don't know about the failures, looks like it has nothing to do with these files. I have no time to investigate all that just for a pull request. |
Try rebase |
Hello everyone, Sorry, It's not related with this issue but I want to add a feature in the branch Thanks. |
Try rebase |
Sorry @afc163 , how can I rebase the |
|
Hello @afc163 , Maybe this is one of the problems with the PR of the thread:
There is a snapshot that fails:
Maybe this is the original problem and the reason because @erwin-k cannot merge 3 commits into ant-design:feature from erwin-k:feature-3.9.0. It seems that before a previous change the Treenode Switcher was closed by default and now it is opened but the snapshots have not being updated. |
Codecov Report
@@ Coverage Diff @@
## feature #11756 +/- ##
===========================================
+ Coverage 92.31% 92.31% +<.01%
===========================================
Files 211 211
Lines 5542 5543 +1
Branches 1594 1556 -38
===========================================
+ Hits 5116 5117 +1
- Misses 420 422 +2
+ Partials 6 4 -2
Continue to review full report at Codecov.
|
@picodoth