@@ -91,7 +91,11 @@ def generate_header_nav_before_dropdown(n_links_before_dropdown):
91
91
page = toc .attributes ["parent" ] if page == "self" else page
92
92
93
93
# If this is the active ancestor page, add a class so we highlight it
94
- current = " current active" if page == active_header_page else ""
94
+ current = ""
95
+ aria_current = ""
96
+ if page == active_header_page :
97
+ current = " current active"
98
+ aria_current = ' aria-current="page"'
95
99
96
100
# sanitize page title for use in the html output if needed
97
101
if title is None :
@@ -114,7 +118,7 @@ def generate_header_nav_before_dropdown(n_links_before_dropdown):
114
118
# create the html output
115
119
links_html .append (
116
120
f"""
117
- <li class="nav-item{ current } ">
121
+ <li class="nav-item{ current } "{ aria_current } >
118
122
<a class="nav-link nav-{ link_status } " href="{ link_href } ">
119
123
{ title }
120
124
</a>
@@ -351,7 +355,7 @@ def add_collapse_checkboxes(soup: BeautifulSoup) -> None:
351
355
"""Add checkboxes to collapse children in a toctree."""
352
356
# based on https://github.com/pradyunsg/furo
353
357
354
- toctree_checkbox_count = 0
358
+ toctree_subtree_count = 0
355
359
356
360
for element in soup .find_all ("li" , recursive = True ):
357
361
# We check all "li" elements, to add a "current-page" to the correct li.
@@ -364,22 +368,35 @@ def add_collapse_checkboxes(soup: BeautifulSoup) -> None:
364
368
parentli .select ("p.caption ~ input" )[0 ].attrs ["checked" ] = ""
365
369
366
370
# Nothing more to do, unless this has "children"
367
- if not element .find ("ul" ):
371
+ subtree = element .find ("ul" )
372
+ if not subtree :
368
373
continue
369
374
370
375
# Add a class to indicate that this has children.
371
376
element ["class" ] = classes + ["has-children" ]
372
377
373
378
# We're gonna add a checkbox.
374
- toctree_checkbox_count += 1
375
- checkbox_name = f"toctree-checkbox-{ toctree_checkbox_count } "
379
+ toctree_subtree_count += 1
380
+ subtree_name = f"toctree-subtree-{ toctree_subtree_count } "
381
+ subtree ["id" ] = subtree_name
382
+ checkbox_name = f"toctree-checkbox-{ toctree_subtree_count } "
376
383
377
384
# Add the "label" for the checkbox which will get filled.
378
385
if soup .new_tag is None :
379
386
continue
380
387
388
+ section_name = element .a .get_text ()
381
389
label = soup .new_tag (
382
- "label" , attrs = {"for" : checkbox_name , "class" : "toctree-toggle" }
390
+ "label" ,
391
+ attrs = {
392
+ "role" : "button" ,
393
+ "for" : checkbox_name ,
394
+ "class" : "toctree-toggle" ,
395
+ "tabindex" : "0" ,
396
+ "aria-expanded" : "false" ,
397
+ "aria-controls" : subtree_name ,
398
+ "aria-label" : f"Expand section { section_name } " ,
399
+ },
383
400
)
384
401
label .append (soup .new_tag ("i" , attrs = {"class" : "fa-solid fa-chevron-down" }))
385
402
if "toctree-l0" in classes :
@@ -402,6 +419,8 @@ def add_collapse_checkboxes(soup: BeautifulSoup) -> None:
402
419
# (by checking the checkbox)
403
420
if "current" in classes :
404
421
checkbox .attrs ["checked" ] = ""
422
+ label .attrs ["aria-expanded" ] = "true"
423
+ label .attrs ["aria-label" ] = f"Collapse section { section_name } "
405
424
406
425
element .insert (1 , checkbox )
407
426
0 commit comments