From 272f4cb54dc79422d2d981ec704a5013b7ed14ae Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Thu, 29 Jul 2021 21:52:33 +0100 Subject: [PATCH] Make the site-wide sidebar more screen-reader friendly --- src/furo/navigation.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/furo/navigation.py b/src/furo/navigation.py index db330e496..be69d9aff 100644 --- a/src/furo/navigation.py +++ b/src/furo/navigation.py @@ -48,8 +48,20 @@ def get_navigation_tree(toctree_html: str) -> str: checkbox_name = f"toctree-checkbox-{toctree_checkbox_count}" # Add the "label" for the checkbox which will get filled. - label = soup.new_tag("label", attrs={"for": checkbox_name}) + label = soup.new_tag( + "label", + attrs={ + "for": checkbox_name, + }, + ) + screen_reader_label = soup.new_tag( + "div", + attrs={"class": "visually-hidden"}, + ) + screen_reader_label.string = "Toggle child pages in navigation" + label.append(screen_reader_label) label.append(_get_navigation_expand_image(soup)) + element.insert(1, label) # Add the checkbox that's used to store expanded/collapsed state. @@ -60,6 +72,7 @@ def get_navigation_tree(toctree_html: str) -> str: "class": ["toctree-checkbox"], "id": checkbox_name, "name": checkbox_name, + "role": "switch", }, ) # if this has a "current" class, be expanded by default (by checking the checkbox)