File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 8989
9090< script >
9191/**
92- * Header dismiss – closes CSS-only checkbox menus (avatar dropdown, mobile drawer)
93- * when the user clicks or tabs outside their container.
92+ * Header progressive enhancements for CSS-only checkbox menus:
93+ * - Dismiss open menus on outside click or focus.
94+ * - Toggle menus on Enter (checkboxes only respond to Space natively).
9495 */
9596( function ( ) {
9697 'use strict' ;
9798
99+ var TOGGLE_SELECTOR = '.header__user-toggle, .header__menu-toggle' ;
100+
98101 function dismissOpenMenus ( target ) {
99102 var openUserToggles = document . querySelectorAll ( '.header__user-toggle:checked' ) ;
100103 openUserToggles . forEach ( function ( toggle ) {
120123 document . addEventListener ( 'focusin' , function ( e ) {
121124 dismissOpenMenus ( e . target ) ;
122125 } ) ;
126+
127+ document . addEventListener ( 'keydown' , function ( e ) {
128+ if ( e . key !== 'Enter' ) return ;
129+ var toggle = e . target ;
130+ if ( toggle . matches && toggle . matches ( TOGGLE_SELECTOR ) ) {
131+ e . preventDefault ( ) ;
132+ toggle . checked = ! toggle . checked ;
133+ }
134+ } ) ;
123135} ) ( ) ;
124136</ script >
Original file line number Diff line number Diff line change 1212{% url 'account_logout' as logout_url %}
1313{% url 'profile-account' as profile_url %}
1414< div class ="header__user-menu ">
15- < input type ="checkbox " id ="{{ avatar_id }}-toggle " class ="header__user-toggle " aria-label ="User menu " aria-controls ="{{ avatar_id }}-menu " aria-haspopup ="menu ">
16- < label for ="{{ avatar_id }}-toggle " class ="header__user-trigger " aria-hidden ="true ">
15+ < input type ="checkbox "
16+ id ="{{ avatar_id }}-toggle "
17+ class ="header__user-toggle "
18+ aria-label ="User account "
19+ aria-controls ="{{ avatar_id }}-menu ">
20+ < label for ="{{ avatar_id }}-toggle "
21+ class ="header__user-trigger "
22+ aria-hidden ="true ">
1723 {% include "v3/includes/_avatar_v3.html" with src=request.user.get_thumbnail_url name=request.user.display_name size="xl" %}
1824 </ label >
19- < div id ="{{ avatar_id }}-menu "
20- role ="menu "
21- aria-orientation ="vertical "
22- aria-labelledby ="{{ avatar_id }}-toggle "
23- class ="header__user-dropdown ">
25+ < div id ="{{ avatar_id }}-menu " role ="group " class ="header__user-dropdown ">
2426 {% include "v3/includes/header/_header_nav_link.html" with url=logout_url label="Logout" %}
2527 {% include "v3/includes/header/_header_nav_link.html" with url=profile_url label="My Profile" %}
2628 {% include "v3/includes/header/_header_nav_link.html" with url=profile_url label="Edit Profile" %}
You can’t perform that action at this time.
0 commit comments