-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
[FIX] web: focus on close button when before closing a modal #32038
Conversation
var isModal = false; | ||
return waitForCondition(function() { | ||
// sometimes, the app is just a modal that needs to be closed | ||
var $modal = $('.modal[role="dialog"][open="open"]'); | ||
if ($modal.length > 0) { | ||
$modal.modal('hide'); | ||
var $close_button = $('header > button.close'); |
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.
I would do something like $modal.find('header > button.close')
to be sure that your close button is in the modal.
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.
variables are camelcased in JS
var isModal = false; | ||
return waitForCondition(function() { | ||
// sometimes, the app is just a modal that needs to be closed | ||
var $modal = $('.modal[role="dialog"][open="open"]'); | ||
if ($modal.length > 0) { | ||
$modal.modal('hide'); | ||
var $close_button = $('header > button.close'); | ||
$close_button.focus(); |
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.
Is it still needed, despite your _click
function ?
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.
If it is, maybe the focus
event should be triggered in the _click
function.
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.
Yep, I tested without and it crashes as expected
trigger_mouse_event($element, "mouseup"); | ||
trigger_mouse_event($element, "click"); | ||
|
||
function trigger_mouse_event($el, type, count) { |
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.
camelcase
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.
count
is not needed in your case
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.
you're right
During the clickEverywhere test, when a modal is opened, the hide method is called to bypass it. This is not realistic and does not work in some cases. For example in Point of sale, menu "Reporting/Sales Details", a modal is opened with a DateTimePicker (tempus dominus) already opened. When hiding or closing the modal, the DateTimePicker needs to perform some cleanup. If the modal is simply hidden, the DateTimePicker is not cleanly destroyed. With this commit, a modal is closed by clicking on its close button and before that, the focus is set on the close button to let the datepicker widget do its stuff on losing focus. Also, a more realistic click is done by trigerring more events (code adapted from tour helper).
0190b5f
to
ba30bb9
Compare
@robodoo r+ |
During the clickEverywhere test, when a modal is opened, the hide method is called to bypass it. This is not realistic and does not work in some cases. For example in Point of sale, menu "Reporting/Sales Details", a modal is opened with a DateTimePicker (tempus dominus) already opened. When hiding or closing the modal, the DateTimePicker needs to perform some cleanup. If the modal is simply hidden, the DateTimePicker is not cleanly destroyed. With this commit, a modal is closed by clicking on its close button and before that, the focus is set on the close button to let the datepicker widget do its stuff on losing focus. Also, a more realistic click is done by trigerring more events (code adapted from tour helper). closes #32038 Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
Merged, thanks! |
During the clickEverywhere test, when a modal is opened, the hide method
is called to bypass it. This is not realistic and does not work in some
cases.
For example in Point of sale, menu "Reporting/Sales Details", a modal is
opened with a DateTimePicker (tempus dominus) already opened.
When hiding or closing the modal, the DateTimePicker needs to perform
some cleanup. If the modal is simply hidden, the DateTimePicker is not
cleanly destroyed.
With this commit, a modal is closed by clicking on its close button and
before that, the focus is set on the close button to let the
datepicker widget do its stuff on losing focus.
Also, a more realistic click is done by triggering more events (code
adapted from tour helper).