From 95c957791ed613a5bc477e8954712bcbb221a85e Mon Sep 17 00:00:00 2001 From: Pedro Jordao Date: Mon, 8 Apr 2024 12:57:00 -0300 Subject: [PATCH] MDL-80195 forms: Keep dropdown menu open when tabbing into datepicker When accessing a datepicker that is within a dropdown menu using the tab key, the navigation sequence was changed since the datepicker code is not rendered within the dropdown menu element, thus the dropdown was closed as it was understood that we were not more inside it. Furthermore, when exiting the datepicker by pressing tab, as the dropdown was closed, the navigation jumped to the first element on the page, which is the link to Skip to main content. To resolve this, a validation was added that keeps the dropdown menu open if the datepicker is open and accessed via the tab key. --- .../moodle-form-dateselector-debug.js | 11 +++++++++++ .../moodle-form-dateselector-min.js | 4 ++-- .../moodle-form-dateselector.js | 11 +++++++++++ lib/form/yui/src/dateselector/js/calendar.js | 11 +++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-debug.js b/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-debug.js index 1b5d4b821ce..ace194f94dc 100644 --- a/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-debug.js +++ b/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-debug.js @@ -316,6 +316,17 @@ CALENDAR.prototype = { // When the user tab out the calendar, close it. Y.one(document.body).on('keyup', function(e) { + // If the calendar is open and we try to access it by pressing tab, we check if it is inside a Bootstrap dropdown-menu, + // if so, we keep the dropdown open while navigation takes place in the calendar. + if (M.form.dateselector.currentowner && e.keyCode === 9) { + e.stopPropagation(); + var calendarimageelement = document.getElementById(M.form.dateselector.currentowner.calendarimage.get('id')); + if (M.form.dateselector.calendar.get('focused') && calendarimageelement.closest('.dropdown-menu') && + !calendarimageelement.closest('.dropdown-menu').classList.contains("show")) { + calendarimageelement.closest('.dropdown-menu').classList.add('show'); + } + } + // hide the calendar if we press a key and the calendar is not focussed, or if we press ESC in the calendar. if ((M.form.dateselector.currentowner === this && !M.form.dateselector.calendar.get('focused')) || ((e.keyCode === 27) && M.form.dateselector.calendar.get('focused'))) { diff --git a/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-min.js b/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-min.js index 9d10b424e20..8c16c43bd61 100644 --- a/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-min.js +++ b/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-min.js @@ -1,2 +1,2 @@ -YUI.add("moodle-form-dateselector",function(n,e){var t,a;n.mix(n.Node.prototype,{firstOptionValue:function(){return"select"===this.get("nodeName").toLowerCase()&&this.one("option").get("value")},lastOptionValue:function(){return"select"===this.get("nodeName").toLowerCase()&&this.all("option").item(this.optionSize()-1).get("value")},optionSize:function(){return"select"===this.get("nodeName").toLowerCase()&&parseInt(this.all("option").size(),10)},selectedOptionValue:function(){return"select"===this.get("nodeName").toLowerCase()&&this.all("option").item(this.get("selectedIndex")).get("value")}}),M.form=M.form||{},M.form.dateselector={panel:null,calendar:null,currentowner:null,hidetimeout:null,repositiontimeout:null,init_date_selectors:function(e){null===this.panel&&this.initPanel(e),n.all(".fdate_time_selector").each(function(){e.node=this,new t(e)}),n.all(".fdate_selector").each(function(){e.node=this,new t(e)})},initPanel:function(e){this.panel=new n.Overlay({visible:!1,bodyContent:n.Node.create('
'),id:"dateselector-calendar-panel",constrain:!0}),this.panel.render(document.body),this.panel.on("focus",function(){var e,t=0;n.all(" [role=dialog], [role=menubar], .moodle-has-zindex").each(function(e){e=this.findZIndex(e);t'),id:"dateselector-calendar-panel",constrain:!0}),this.panel.render(document.body),this.panel.on("focus",function(){var e,t=0;n.all(" [role=dialog], [role=menubar], .moodle-has-zindex").each(function(e){e=this.findZIndex(e);t