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

Regression in d915dd1c58.

Follow up to 780473d756.
This commit is contained in:
Sankalp 2022-05-20 19:51:31 +05:30 committed by Mariusz Felisiak
parent 78bf1565c3
commit 90dcf27114
4 changed files with 21 additions and 0 deletions

View File

@ -13,6 +13,12 @@
navLink.tabIndex = 0; navLink.tabIndex = 0;
} }
} }
function disableNavFilterTabbing() {
document.getElementById('nav-filter').tabIndex = -1;
}
function enableNavFilterTabbing() {
document.getElementById('nav-filter').tabIndex = 0;
}
const main = document.getElementById('main'); const main = document.getElementById('main');
let navSidebarIsOpen = localStorage.getItem('django.admin.navSidebarIsOpen'); let navSidebarIsOpen = localStorage.getItem('django.admin.navSidebarIsOpen');
@ -21,6 +27,7 @@
} }
if (navSidebarIsOpen === 'false') { if (navSidebarIsOpen === 'false') {
disableNavLinkTabbing(); disableNavLinkTabbing();
disableNavFilterTabbing();
} }
main.classList.toggle('shifted', navSidebarIsOpen === 'true'); main.classList.toggle('shifted', navSidebarIsOpen === 'true');
@ -28,9 +35,11 @@
if (navSidebarIsOpen === 'true') { if (navSidebarIsOpen === 'true') {
navSidebarIsOpen = 'false'; navSidebarIsOpen = 'false';
disableNavLinkTabbing(); disableNavLinkTabbing();
disableNavFilterTabbing();
} else { } else {
navSidebarIsOpen = 'true'; navSidebarIsOpen = 'true';
enableNavLinkTabbing(); enableNavLinkTabbing();
enableNavFilterTabbing();
} }
localStorage.setItem('django.admin.navSidebarIsOpen', navSidebarIsOpen); localStorage.setItem('django.admin.navSidebarIsOpen', navSidebarIsOpen);
main.classList.toggle('shifted'); 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 * Fixed a bug in Django 4.0 that caused a crash of ``QuerySet.filter()`` on
``IsNull()`` expressions (:ticket:`33705`). ``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 filesystems
flatpage flatpage
flatpages flatpages
focusable
fooapp fooapp
formatter formatter
formatters formatters

View File

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