[4.1.x] Fixed #33725 -- Made hidden quick filter in admin's navigation sidebar not focusable.

Regression in d915dd1c58.

Follow up to 780473d756.

Backport of 90dcf27114 from main
This commit is contained in:
Sankalp 2022-05-20 19:51:31 +05:30 committed by Mariusz Felisiak
parent 51de294d77
commit 170793f0b0
4 changed files with 21 additions and 0 deletions

View File

@ -13,6 +13,12 @@
navLink.tabIndex = 0;
}
}
function disableNavFilterTabbing() {
document.getElementById('nav-filter').tabIndex = -1;
}
function enableNavFilterTabbing() {
document.getElementById('nav-filter').tabIndex = 0;
}
const main = document.getElementById('main');
let navSidebarIsOpen = localStorage.getItem('django.admin.navSidebarIsOpen');
@ -21,6 +27,7 @@
}
if (navSidebarIsOpen === 'false') {
disableNavLinkTabbing();
disableNavFilterTabbing();
}
main.classList.toggle('shifted', navSidebarIsOpen === 'true');
@ -28,9 +35,11 @@
if (navSidebarIsOpen === 'true') {
navSidebarIsOpen = 'false';
disableNavLinkTabbing();
disableNavFilterTabbing();
} else {
navSidebarIsOpen = 'true';
enableNavLinkTabbing();
enableNavFilterTabbing();
}
localStorage.setItem('django.admin.navSidebarIsOpen', navSidebarIsOpen);
main.classList.toggle('shifted');

View File

@ -14,3 +14,6 @@ Bugfixes
* Fixed a bug in Django 4.0 that caused a crash of ``QuerySet.filter()`` on
``IsNull()`` expressions (:ticket:`33705`).
* Fixed a bug in Django 4.0 where a hidden quick filter toolbar in the admin's
navigation sidebar was focusable (:ticket:`33725`).

View File

@ -170,6 +170,7 @@ filesystem
filesystems
flatpage
flatpages
focusable
fooapp
formatter
formatters

View File

@ -148,10 +148,14 @@ class SeleniumTests(AdminSeleniumTestCase):
self.assertEqual(toggle_button.get_attribute("aria-label"), "Toggle navigation")
for link in self.selenium.find_elements(By.CSS_SELECTOR, "#nav-sidebar a"):
self.assertEqual(link.get_attribute("tabIndex"), "0")
filter_input = self.selenium.find_element_by_css_selector("#nav-filter")
self.assertEqual(filter_input.get_attribute("tabIndex"), "0")
toggle_button.click()
# Hidden sidebar is not reachable via keyboard navigation.
for link in self.selenium.find_elements(By.CSS_SELECTOR, "#nav-sidebar a"):
self.assertEqual(link.get_attribute("tabIndex"), "-1")
filter_input = self.selenium.find_element_by_css_selector("#nav-filter")
self.assertEqual(filter_input.get_attribute("tabIndex"), "-1")
main_element = self.selenium.find_element(By.CSS_SELECTOR, "#main")
self.assertNotIn("shifted", main_element.get_attribute("class").split())
@ -188,9 +192,13 @@ class SeleniumTests(AdminSeleniumTestCase):
# Hidden sidebar is not reachable via keyboard navigation.
for link in self.selenium.find_elements(By.CSS_SELECTOR, "#nav-sidebar a"):
self.assertEqual(link.get_attribute("tabIndex"), "-1")
filter_input = self.selenium.find_element_by_css_selector("#nav-filter")
self.assertEqual(filter_input.get_attribute("tabIndex"), "-1")
toggle_button.click()
for link in self.selenium.find_elements(By.CSS_SELECTOR, "#nav-sidebar a"):
self.assertEqual(link.get_attribute("tabIndex"), "0")
filter_input = self.selenium.find_element_by_css_selector("#nav-filter")
self.assertEqual(filter_input.get_attribute("tabIndex"), "0")
self.assertEqual(
self.selenium.execute_script(
"return localStorage.getItem('django.admin.navSidebarIsOpen')"