From a4804e0ab9aabb08553d6dfb06728292403b0554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Souk=C3=A9ina=20Bojabza?= Date: Tue, 30 Jan 2024 15:18:38 +0000 Subject: [PATCH] [FIX] website: outline the hoverable dropdowns when using the Tab key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since commit [1], there is no outline when focusing a hoverable dropdown by using the Tab key. This happens because of a CSS rule that was added so no outline would appear when hovering the dropdown menus with the mouse. However, it should still be displayed when using the keyboard, for accessibility reasons. This commit fixes that by always allowing the focus on the hoverable dropdowns, except when they are hovered. If a focus was present on an element in the document when hovering, its focus is kept (to have the same behavior as in previous versions). Steps to reproduce: - Add a submenu and a mega menu with the menu editor. - In edit mode, set the dropdowns as hoverable (set the "Sub Menus" option to "On Hover") and save. - Use the Tab key to navigate through the menus. => The simple menus have an outline but this is not the case for the dropdowns. [1]: https://github.com/odoo/odoo/commit/5846a05fe7bf587d3bfb3ace3e863cb4abd52132 task-3709755 closes odoo/odoo#154505 X-original-commit: a8b3e589cd7e6c9ecfd33ba4ae9883e7ade2e599 Signed-off-by: Soukéina Bojabza (sobo) Signed-off-by: Robin Lejeune (role) --- addons/website/static/src/js/content/menu.js | 12 ++++++++++++ addons/website/static/src/scss/website.scss | 4 ---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/addons/website/static/src/js/content/menu.js b/addons/website/static/src/js/content/menu.js index d8565b2d2e1..1e698488a54 100644 --- a/addons/website/static/src/js/content/menu.js +++ b/addons/website/static/src/js/content/menu.js @@ -623,9 +623,21 @@ publicWidget.registry.hoverableDropdown = animations.Animation.extend({ return; } } + // Get the previously focused element of the page. + const focusedEl = this.el.ownerDocument.querySelector(":focus") + || window.frameElement && window.frameElement.ownerDocument.querySelector(":focus"); + // The user must click on the dropdown if he is on mobile (no way to // hover) or if the dropdown is the (or in the) extra menu ('+'). this._updateDropdownVisibility(ev, true); + + // Keep the focus on the previously focused element if any, otherwise do + // not focus the dropdown on hover. + if (focusedEl) { + focusedEl.focus(); + } else { + ev.currentTarget.querySelector(".dropdown-toggle").blur(); + } }, /** * @private diff --git a/addons/website/static/src/scss/website.scss b/addons/website/static/src/scss/website.scss index c53079cd376..01f5e3a88b5 100644 --- a/addons/website/static/src/scss/website.scss +++ b/addons/website/static/src/scss/website.scss @@ -996,10 +996,6 @@ $-transition-duration: 200ms; } } -.o_hoverable_dropdown .nav-link.dropdown-toggle:focus { - outline: none; -} - // Navbar .navbar .o_extra_menu_items > .show { > li {