File tree Expand file tree Collapse file tree 3 files changed +25
-10
lines changed
Expand file tree Collapse file tree 3 files changed +25
-10
lines changed Original file line number Diff line number Diff line change 1212 aria-controls ="{{ include.accordion_id }} "
1313 >
1414 {{ include.title }}
15+ < a href ="#{{ include.id }} "
16+ class ="accordion-link "
17+ aria-label ="anchor "
18+ aria-describedby ="{{ include.id }} "
19+ > #</ a >
1520 </ button >
1621</ dt >
1722< dd id ="{{ include.accordion_id }} " class ="usa-accordion__content usa-prose ">
Original file line number Diff line number Diff line change 11( ( ) => {
2- const onChange = ( _event ) => {
3- const urlHash = new URL ( document . URL ) . hash ;
4- const idFromHash = urlHash . match ( / ^ ( # [ A - Z a - z 0 - 9 _ - ] + ) $ / ) ;
5- if ( idFromHash ) {
6- const accordionHeading = document . querySelector (
7- `${ idFromHash [ 1 ] } .usa-accordion__heading > button` ,
2+ const jumpToAccordion = ( _event ) => {
3+ const accordionId = new URL ( document . URL ) . hash ;
4+ if ( accordionId ) {
5+ const accordionButton = document . querySelector (
6+ `${ accordionId } .usa-accordion__heading > button` ,
87 ) ;
9- if ( accordionHeading ) {
10- accordionHeading . click ( ) ;
8+ const accordionBody = document . querySelector ( `${ accordionId } .usa-accordion__heading + dd` ) ;
9+ if ( accordionButton && accordionBody . hidden ) {
10+ accordionButton . click ( ) ;
1111 }
1212 }
1313 } ;
14- document . addEventListener ( 'DOMContentLoaded' , onChange ) ;
15- window . addEventListener ( 'hashchange' , onChange ) ;
14+
15+ document . addEventListener ( 'DOMContentLoaded' , jumpToAccordion ) ;
16+ window . addEventListener ( 'hashchange' , jumpToAccordion ) ;
1617} ) ( ) ;
Original file line number Diff line number Diff line change @@ -165,6 +165,15 @@ button.code-button:hover {
165165 height : 1.3rem ;
166166}
167167
168+ .accordion-link {
169+ display : none ;
170+ text-decoration : none ;
171+ }
172+
173+ .usa-accordion__heading :hover .accordion-link {
174+ display : inline ;
175+ }
176+
168177@media (min-width : 1024px ) {
169178 .code-snippet-column {
170179 background-color : transparent ;
You can’t perform that action at this time.
0 commit comments