From 413a37931284b2fb4a045c42c4b0e5b5bd339596 Mon Sep 17 00:00:00 2001 From: divdavem Date: Wed, 9 Sep 2015 16:55:03 +0200 Subject: [PATCH] fix #1530 MultiSelect does not prevent default action with arrow down key This commit makes sure the default action when pressing the arrow down key (usually: scrolling the document) is prevented when the focus is inside the aria:MultiSelect widget. AT-1162 PTR 10390760 --- .../controllers/DropDownListController.js | 2 +- .../controllers/MultiSelectController.js | 13 ++-- .../form/multiselect/MultiselectTestSuite.js | 1 + .../downArrowKeyPreventDef/MSDownArrowKey.js | 74 +++++++++++++++++++ .../MSDownArrowKeyTpl.tpl | 55 ++++++++++++++ test/attester-nophantom.yml | 1 + test/attester-packaged.yml | 1 + 7 files changed, 141 insertions(+), 6 deletions(-) create mode 100644 test/aria/widgets/form/multiselect/downArrowKeyPreventDef/MSDownArrowKey.js create mode 100644 test/aria/widgets/form/multiselect/downArrowKeyPreventDef/MSDownArrowKeyTpl.tpl diff --git a/src/aria/widgets/controllers/DropDownListController.js b/src/aria/widgets/controllers/DropDownListController.js index 1ce31274a..fb7e9fd11 100644 --- a/src/aria/widgets/controllers/DropDownListController.js +++ b/src/aria/widgets/controllers/DropDownListController.js @@ -201,7 +201,7 @@ module.exports = Aria.classDefinition({ report = new ariaWidgetsControllersReportsDropDownControllerReport(); } // domEvent.KC_ESCAPE for issue#697 on FF - if (report && keyCode != domEvent.KC_TAB) { + if (report && keyCode != domEvent.KC_TAB && keyCode != domEvent.KC_ARROW_DOWN) { // domEvent.KC_ESCAPE for issue#697 on FF report.cancelKeyStroke = (keyCode == domEvent.KC_ESCAPE); } diff --git a/src/aria/widgets/controllers/MultiSelectController.js b/src/aria/widgets/controllers/MultiSelectController.js index afd7f160f..c0e9d2617 100644 --- a/src/aria/widgets/controllers/MultiSelectController.js +++ b/src/aria/widgets/controllers/MultiSelectController.js @@ -310,13 +310,16 @@ module.exports = Aria.classDefinition({ * @return {aria.widgets.controllers.reports.DropDownControllerReport} */ _checkInputKey : function (charCode, keyCode, currentText, caretPosStart, caretPosEnd) { + var report; if (ariaDomEvent.KC_ARROW_DOWN === keyCode) { - return this.toggleDropdown(currentText, false); + report = this.toggleDropdown(currentText, false); + report.cancelKeyStroke = true; + } else { + report = new ariaWidgetsControllersReportsDropDownControllerReport(); + report.ok = true; + report.cancelKeyStroke = false; + report.displayDropDown = false; } - var report = new ariaWidgetsControllersReportsDropDownControllerReport(); - report.ok = true; - report.cancelKeyStroke = false; - report.displayDropDown = false; return report; }, diff --git a/test/aria/widgets/form/multiselect/MultiselectTestSuite.js b/test/aria/widgets/form/multiselect/MultiselectTestSuite.js index 19a71f0ad..9c34e6a5b 100644 --- a/test/aria/widgets/form/multiselect/MultiselectTestSuite.js +++ b/test/aria/widgets/form/multiselect/MultiselectTestSuite.js @@ -24,6 +24,7 @@ Aria.classDefinition({ "test.aria.widgets.form.multiselect.deleteFieldValue.test1.MultiSelect", "test.aria.widgets.form.multiselect.deleteFieldValue.test2.MultiSelect", "test.aria.widgets.form.multiselect.downArrowKey.MultiSelect", + "test.aria.widgets.form.multiselect.downArrowKeyPreventDef.MSDownArrowKey", "test.aria.widgets.form.multiselect.instantbind.InstantBindTestCase", "test.aria.widgets.form.multiselect.invalidcontent.MultiSelect", "test.aria.widgets.form.multiselect.issue223.MultiSelect", diff --git a/test/aria/widgets/form/multiselect/downArrowKeyPreventDef/MSDownArrowKey.js b/test/aria/widgets/form/multiselect/downArrowKeyPreventDef/MSDownArrowKey.js new file mode 100644 index 000000000..bdb176b18 --- /dev/null +++ b/test/aria/widgets/form/multiselect/downArrowKeyPreventDef/MSDownArrowKey.js @@ -0,0 +1,74 @@ +/* + * Copyright 2013 Amadeus s.a.s. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Aria.classDefinition({ + $classpath : "test.aria.widgets.form.multiselect.downArrowKeyPreventDef.MSDownArrowKey", + $extends : "aria.jsunit.RobotTestCase", + $dependencies : ["aria.utils.Dom"], + $prototype : { + runTemplateTest : function () { + var self = this; + var scrollableItem = aria.utils.Dom.getDocumentScrollElement(); + + function step1() { + self.testDiv.style.position = "absolute"; + scrollableItem.scrollTop = 3000; + var happyMS = self.getInputField("happyMS"); + self.synEvent.execute([["click", happyMS], ["waitFocus", happyMS], ["type", null, "[down]"]], step2); + } + + function step2() { + self.assertEquals(scrollableItem.scrollTop, 3000); + self.waitFor({ + condition: function () { + return !!self.getWidgetDropDownPopup("happyMS"); + }, + callback: step3 + }); + } + + function step3() { + self.synEvent.execute([["type", null, " [up]"]], step4); + } + + function step4() { + self.assertEquals(scrollableItem.scrollTop, 3000); + var happyMS = self.getInputField("happyMS"); + self.synEvent.execute([["click", happyMS], ["waitFocus", happyMS], ["type", null, "[down][down]"]], step5); + } + + function step5() { + self.assertEquals(scrollableItem.scrollTop, 3000); + self.waitFor({ + condition: function () { + return !!self.getWidgetDropDownPopup("happyMS"); + }, + callback: step6 + }); + } + + function step6() { + self.synEvent.execute([["type", null, " [up][up]"]], step7); + } + + function step7() { + self.assertEquals(scrollableItem.scrollTop, 3000); + self.end(); + } + + step1(); + } + } +}); diff --git a/test/aria/widgets/form/multiselect/downArrowKeyPreventDef/MSDownArrowKeyTpl.tpl b/test/aria/widgets/form/multiselect/downArrowKeyPreventDef/MSDownArrowKeyTpl.tpl new file mode 100644 index 000000000..76bec76c5 --- /dev/null +++ b/test/aria/widgets/form/multiselect/downArrowKeyPreventDef/MSDownArrowKeyTpl.tpl @@ -0,0 +1,55 @@ +/* + * Copyright 2015 Amadeus s.a.s. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{Template { + $classpath:"test.aria.widgets.form.multiselect.downArrowKeyPreventDef.MSDownArrowKeyTpl", + $hasScript:false +}} + + {macro main()} +
+

This test needs focus

+ {@aria:MultiSelect { + id :"happyMS", + label : "What do you need to be happy?", + labelWidth : 200, + width: 650, + numberOfRows:4, + displayOptions : { + listDisplay : "label" + }, + items : [ + {label : "God", value : "God"}, + {label : "Love", value : "Love"}, + {label : "Forgiveness", value : "Forgiveness"}, + {label : "Hope", value : "Hope"}, + {label : "A spouse", value : "spouse"}, + {label : "Good friends", value : "goodfriends"}, + {label : "Food", value : "Food"}, + {label : "Clothing", value : "Clothing"}, + {label : "Shelter", value : "Shelter"}, + {label : "A good job", value : "goodjob"}, + {label : "A car", value : "car"}, + {label : "A good computer", value : "goodcomputer"}, + {label : "A smartphone", value: "smartphone"}, + {label : "JavaScript", value : "Javascript"}, + {label : "A good browser", value: "goodbrowser"}, + {label : "Aria Templates", value : "ariatemplates"} + ] + }/} +
+ {/macro} + +{/Template} diff --git a/test/attester-nophantom.yml b/test/attester-nophantom.yml index c8ca53041..e26aeedcb 100644 --- a/test/attester-nophantom.yml +++ b/test/attester-nophantom.yml @@ -22,6 +22,7 @@ tests: - test.aria.widgets.container.dialog.resize.test5.OverlayOnResizeScrollTestCase - test.aria.utils.overlay.loadingIndicator.scrollableBody.ScrollableBodyTest - test.aria.utils.DomScrollIntoView + - test.aria.widgets.form.multiselect.downArrowKeyPreventDef.MSDownArrowKey - test.aria.widgets.container.dialog.container.DialogContainerTestSuite - test.aria.widgets.container.dialog.indicators.DialogTestCase # This test works in Firefox and Chrome locally but not on Travis... It is removed in .travis.yml diff --git a/test/attester-packaged.yml b/test/attester-packaged.yml index 52d6d4e6f..ec0f4b584 100644 --- a/test/attester-packaged.yml +++ b/test/attester-packaged.yml @@ -24,6 +24,7 @@ tests: - test.aria.widgets.container.dialog.resize.test5.OverlayOnResizeScrollTestCase - test.aria.utils.overlay.loadingIndicator.scrollableBody.ScrollableBodyTest - test.aria.utils.DomScrollIntoView + - test.aria.widgets.form.multiselect.downArrowKeyPreventDef.MSDownArrowKey - test.aria.widgets.container.dialog.container.DialogContainerTestSuite - test.aria.widgets.container.dialog.indicators.DialogTestCase - test.aria.widgets.container.dialog.movable.test5.MovableDialogTestCaseFive