-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(modal): submit and hide modal on enter #3542
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,10 @@ export const props = { | |
type: Boolean, | ||
default: false | ||
}, | ||
noSubmitOnEnter: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
noEnforceFocus: { | ||
type: Boolean, | ||
default: false | ||
|
@@ -600,11 +604,15 @@ export const BModal = /*#__PURE__*/ Vue.extend({ | |
onClose() { | ||
this.hide('headerclose') | ||
}, | ||
onEsc(evt) { | ||
onKeyDown(evt) { | ||
// If ESC pressed, hide modal | ||
if (evt.keyCode === KeyCodes.ESC && this.isVisible && !this.noCloseOnEsc) { | ||
this.hide('esc') | ||
} | ||
// If Enter pressed, submit modal | ||
if (evt.keyCode === KeyCodes.ENTER && this.isVisible && !this.noSubmitOnEnter) { | ||
this.onOk() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would close the modal even in there are cancel buttons, etc. It assumes the user wants the default action to be OK (and not Cancel) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it ok to pass the default action via props? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would probably be better to have some option(s) to specify which default rendered buttons have focus when the modal opens (defaulting to no buttons having focus, as autofocusing an input or button on a modal will usually only announce the button/input but not the modal content when using screen readers. A more robust approach is to have users listen for the The |
||
}, | ||
// Document focusin listener | ||
focusHandler(evt) { | ||
|
@@ -850,7 +858,7 @@ export const BModal = /*#__PURE__*/ Vue.extend({ | |
'aria-hidden': this.isVisible ? null : 'true', | ||
'aria-modal': this.isVisible ? 'true' : null | ||
}, | ||
on: { keydown: this.onEsc, click: this.onClickOut } | ||
on: { keydown: this.onKeyDown, click: this.onClickOut } | ||
}, | ||
[modalDialog] | ||
) | ||
|
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.
This also assumes people want to close modal on ENTER, which is currently not the default behavior and would be considered a breaking change.
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.
Also,
submit
assumes a form is being used... so its probably not the best name for the prop, as modals don't "submit"