Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ function DropdownNavbarItemDesktop({
const [showDropdown, setShowDropdown] = useState(false);

useEffect(() => {
const handleClickOutside = (event: MouseEvent | TouchEvent) => {
const handleClickOutside = (
event: MouseEvent | TouchEvent | FocusEvent,
) => {
if (
!dropdownRef.current ||
dropdownRef.current.contains(event.target as Node)
Expand All @@ -66,10 +68,12 @@ function DropdownNavbarItemDesktop({

document.addEventListener('mousedown', handleClickOutside);
document.addEventListener('touchstart', handleClickOutside);
document.addEventListener('focusin', handleClickOutside);

return () => {
document.removeEventListener('mousedown', handleClickOutside);
document.removeEventListener('touchstart', handleClickOutside);
document.removeEventListener('focusin', handleClickOutside);
};
}, [dropdownRef]);

Expand Down Expand Up @@ -100,22 +104,6 @@ function DropdownNavbarItemDesktop({
{items.map((childItemProps, i) => (
<NavbarItem
isDropdownItem
onKeyDown={(e) => {
if (i === items.length - 1 && e.key === 'Tab') {
e.preventDefault();
setShowDropdown(false);
const nextNavbarItem = dropdownRef.current!.nextElementSibling;
if (nextNavbarItem) {
const targetItem =
nextNavbarItem instanceof HTMLAnchorElement
? nextNavbarItem
: // Next item is another dropdown; focus on the inner
// anchor element instead so there's outline
nextNavbarItem.querySelector('a')!;
targetItem.focus();
}
}
}}
activeClassName="dropdown__link--active"
{...childItemProps}
key={i}
Expand Down
11 changes: 11 additions & 0 deletions website/_dogfooding/_pages tests/navbar-dropdown-tests.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# navbar-dropdown-tests

<div id="navbar-dropdown-tests">

1. Make sure that the theme switcher is placed immediately after the language switcher in the navbar.
2. Press `Tab` several times to focus language switcher.
3. Press `Enter` to open language switcher.
4. Press `Tab` several times to exit language switcher.
5. Check if the theme selection button is in focus immediately after the last item.

</div>
4 changes: 4 additions & 0 deletions website/_dogfooding/dogfooding.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ html.plugin-pages.plugin-id-pages-tests .navbar {
#z-index-test {
z-index: 100;
}

html:has(#navbar-dropdown-tests) .navbar__item.dropdown ~ a {
display: none;
}