Skip to content

Commit

Permalink
Make the site-wide sidebar more screen-reader friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Jul 29, 2021
1 parent 5990477 commit 272f4cb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/furo/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit 272f4cb

Please sign in to comment.