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

[FIX] web: focus on close button when before closing a modal #32038

Closed

Conversation

d-fence
Copy link
Contributor

@d-fence d-fence commented Mar 22, 2019

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).

@robodoo robodoo added the CI 🤖 Robodoo has seen passing statuses label Mar 22, 2019
@d-fence d-fence requested a review from mgeubelle March 22, 2019 08:10
@C3POdoo C3POdoo added the RD research & development, internal work label Mar 22, 2019
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');
Copy link
Contributor

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.

Copy link
Contributor

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();
Copy link
Contributor

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 ?

Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

camelcase

Copy link
Contributor

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

Copy link
Contributor Author

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).
@d-fence d-fence force-pushed the master-fix-click-all-datetime-moc branch from 0190b5f to ba30bb9 Compare March 22, 2019 10:28
@robodoo robodoo added CI 🤖 Robodoo has seen passing statuses and removed CI 🤖 Robodoo has seen passing statuses labels Mar 22, 2019
@d-fence
Copy link
Contributor Author

d-fence commented Mar 22, 2019

@robodoo r+

robodoo pushed a commit that referenced this pull request Mar 22, 2019
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>
@robodoo
Copy link
Contributor

robodoo commented Mar 22, 2019

Merged, thanks!

@robodoo robodoo closed this Mar 22, 2019
@fw-bot fw-bot deleted the master-fix-click-all-datetime-moc branch October 19, 2019 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI 🤖 Robodoo has seen passing statuses RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants