diff --git a/django/contrib/admin/static/admin/css/nav_sidebar.css b/django/contrib/admin/static/admin/css/nav_sidebar.css
index 5fd2ff0bde..f76e6ce485 100644
--- a/django/contrib/admin/static/admin/css/nav_sidebar.css
+++ b/django/contrib/admin/static/admin/css/nav_sidebar.css
@@ -59,8 +59,13 @@
content: '\00AB';
}
+.main > #nav-sidebar {
+ visibility: hidden;
+}
+
.main.shifted > #nav-sidebar {
margin-left: 0;
+ visibility: visible;
}
[dir="rtl"] .main.shifted > #nav-sidebar {
diff --git a/django/contrib/admin/static/admin/js/nav_sidebar.js b/django/contrib/admin/static/admin/js/nav_sidebar.js
index 261a9d4992..7e735db15c 100644
--- a/django/contrib/admin/static/admin/js/nav_sidebar.js
+++ b/django/contrib/admin/static/admin/js/nav_sidebar.js
@@ -2,47 +2,24 @@
{
const toggleNavSidebar = document.getElementById('toggle-nav-sidebar');
if (toggleNavSidebar !== null) {
- const navLinks = document.querySelectorAll('#nav-sidebar a');
- function disableNavLinkTabbing() {
- for (const navLink of navLinks) {
- navLink.tabIndex = -1;
- }
- }
- function enableNavLinkTabbing() {
- for (const navLink of navLinks) {
- navLink.tabIndex = 0;
- }
- }
- function disableNavFilterTabbing() {
- document.getElementById('nav-filter').tabIndex = -1;
- }
- function enableNavFilterTabbing() {
- document.getElementById('nav-filter').tabIndex = 0;
- }
-
+ const navSidebar = document.getElementById('nav-sidebar');
const main = document.getElementById('main');
let navSidebarIsOpen = localStorage.getItem('django.admin.navSidebarIsOpen');
if (navSidebarIsOpen === null) {
navSidebarIsOpen = 'true';
}
- if (navSidebarIsOpen === 'false') {
- disableNavLinkTabbing();
- disableNavFilterTabbing();
- }
main.classList.toggle('shifted', navSidebarIsOpen === 'true');
+ navSidebar.setAttribute('aria-expanded', navSidebarIsOpen);
toggleNavSidebar.addEventListener('click', function() {
if (navSidebarIsOpen === 'true') {
navSidebarIsOpen = 'false';
- disableNavLinkTabbing();
- disableNavFilterTabbing();
} else {
navSidebarIsOpen = 'true';
- enableNavLinkTabbing();
- enableNavFilterTabbing();
}
localStorage.setItem('django.admin.navSidebarIsOpen', navSidebarIsOpen);
main.classList.toggle('shifted');
+ navSidebar.setAttribute('aria-expanded', navSidebarIsOpen);
});
}
diff --git a/django/contrib/admin/templates/admin/nav_sidebar.html b/django/contrib/admin/templates/admin/nav_sidebar.html
index 6ddff01d63..a413e23754 100644
--- a/django/contrib/admin/templates/admin/nav_sidebar.html
+++ b/django/contrib/admin/templates/admin/nav_sidebar.html
@@ -1,6 +1,6 @@
{% load i18n %}
-