@@ -232,14 +232,18 @@ export function Events(Base) {
232
232
const topMargin = config ( ) . topMargin ;
233
233
// Use [id='1234'] instead of #id to handle special cases such as reserved characters and pure number id
234
234
// https://stackoverflow.com/questions/37270787/uncaught-syntaxerror-failed-to-execute-queryselector-on-document
235
- const section = dom . find ( " [id='" + id + "']" ) ;
235
+ const section = dom . find ( ` [id=" ${ id } "]` ) ;
236
236
section && this . #scrollTo( section , topMargin ) ;
237
237
238
- const li = this . #nav[ this . #getNavKey( path , id ) ] ;
239
238
const sidebar = dom . getNode ( '.sidebar' ) ;
240
- const active = dom . find ( sidebar , 'li.active' ) ;
241
- active && active . classList . remove ( 'active' ) ;
242
- li && li . classList . add ( 'active' ) ;
239
+ const oldActive = dom . find ( sidebar , 'li.active' ) ;
240
+ const oldPage = dom . find ( sidebar , `[aria-current]` ) ;
241
+ const newActive = this . #nav[ this . #getNavKey( path , id ) ] ;
242
+ const newPage = dom . find ( sidebar , `[href$="${ path } "]` ) ?. parentNode ;
243
+ oldActive ?. classList . remove ( 'active' ) ;
244
+ oldPage ?. removeAttribute ( 'aria-current' ) ;
245
+ newActive ?. classList . add ( 'active' ) ;
246
+ newPage ?. setAttribute ( 'aria-current' , 'page' ) ;
243
247
}
244
248
245
249
#scrollEl = dom . $ . scrollingElement || dom . $ . documentElement ;
@@ -257,7 +261,15 @@ export function Events(Base) {
257
261
* @void
258
262
*/
259
263
#btn( el ) {
260
- const toggle = _ => dom . body . classList . toggle ( 'close' ) ;
264
+ const toggle = _ => {
265
+ dom . body . classList . toggle ( 'close' ) ;
266
+
267
+ const isClosed = isMobile
268
+ ? dom . body . classList . contains ( 'close' )
269
+ : ! dom . body . classList . contains ( 'close' ) ;
270
+
271
+ el . setAttribute ( 'aria-expanded' , isClosed ) ;
272
+ } ;
261
273
262
274
el = dom . getNode ( el ) ;
263
275
if ( el === null || el === undefined ) {
@@ -342,8 +354,10 @@ export function Events(Base) {
342
354
if ( hash . indexOf ( href ) === 0 && ! target ) {
343
355
target = a ;
344
356
dom . toggleClass ( node , 'add' , 'active' ) ;
357
+ node . setAttribute ( 'aria-current' , 'page' ) ;
345
358
} else {
346
359
dom . toggleClass ( node , 'remove' , 'active' ) ;
360
+ node . removeAttribute ( 'aria-current' ) ;
347
361
}
348
362
} ) ;
349
363
0 commit comments