Skip to content

Commit

Permalink
Added dynamic aria attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoensing committed Sep 8, 2023
1 parent 23addea commit 434c0a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,7 @@ function add_accordion_start($html, $attributes, $itemcount, $alignclass)
if ($isAccordionEnabled) {
enqueue_accordion_frontend();
$titleText = esc_html(trim($attributes['title_text'])) ?: __('Table of Contents', 'simpletoc');
$accordionStart = "<button type='button' class='simpletoc-collapsible'>$titleText</button>
<div class='simpletoc-content'>";
$accordionStart = '<button type="button" aria-expanded="false" aria-controls="simpletoc-content-container" class="simpletoc-collapsible">' . $titleText . '</button><div class="simpletoc-content">';
$accordionEnd = '</div>';
}

Expand Down
8 changes: 8 additions & 0 deletions src/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@ for ( const element of coll ) {
const content = this.nextElementSibling;
content.style.display =
content.style.display === 'block' ? 'none' : 'block';

// Toggle aria-expanded attribute
const ariaExpanded = this.getAttribute( 'aria-expanded' );
if ( ariaExpanded === 'true' ) {
this.setAttribute( 'aria-expanded', 'false' );
} else {
this.setAttribute( 'aria-expanded', 'true' );
}
} );
}

0 comments on commit 434c0a7

Please sign in to comment.