Skip to content

Commit

Permalink
Set aria-selected and active properly when clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-collier committed Nov 9, 2023
1 parent 1c27606 commit e99a5e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</section>
</div>
</aside>
<div class='sul-embed-body sul-embed-media'>
<div class='sul-embed-body sul-embed-media' id='sul-embed-body'>
<%= render Embed::MediaTagComponent.with_collection(resources_with_primary_file,
include_transcripts:,
druid:,
Expand Down
10 changes: 10 additions & 0 deletions app/javascript/src/controllers/thumbnail_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,15 @@ export default class extends Controller {
evt.preventDefault();
const event = new CustomEvent('thumbnail-clicked', { detail: { index: evt.params.index } })
window.dispatchEvent(event)

const tabs = this.element.closest('[role="tablist"]').querySelectorAll('[role="tab"]')
tabs.forEach((target) => {
target.classList.remove('active')
target.setAttribute("aria-selected", false)
})

const target = this.element
target.classList.add('active')
target.setAttribute("aria-selected", true)
}
}
2 changes: 1 addition & 1 deletion app/javascript/src/modules/media_thumbnail_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function(dataset, index) {
const fileLabel = dataset.fileLabel || '';
const duration = dataset.duration || '';
// Note: the "position: relative" is required for the stretched-link style.
return `<li class="sul-embed-media-slider-thumb ${activeClass}" data-controller="thumbnail" data-action="click->thumbnail#activate" data-thumbnail-index-param="${index}" style="position: relative;" role="tab">
return `<li class="sul-embed-media-slider-thumb ${activeClass}" data-controller="thumbnail" data-action="click->thumbnail#activate" data-thumbnail-index-param="${index}" style="position: relative;" aria-controls="sul-embed-body" role="tab">
<a class="sul-embed-stretched-link" href="#">
${thumbnailIcon}
<span class="${labelClass}">
Expand Down

0 comments on commit e99a5e6

Please sign in to comment.