[FIX] website: outline the hoverable dropdowns when using the Tab key

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) <sobo@odoo.com>
Signed-off-by: Robin Lejeune (role) <role@odoo.com>
This commit is contained in:
Soukéina Bojabza
2024-02-19 09:06:56 +00:00
parent 9ae0291ce2
commit a4804e0ab9
2 changed files with 12 additions and 4 deletions
@@ -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
@@ -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 {