Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-8136 accordion accessibility #570

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/js/accordion.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/js/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ window.addEventListener('hashchange', (event) => {
// If not found, look inside accordions for anchor links.
if (!accordionItemFound) {
const anchorElement = document.querySelector(`${hash}`);
if (!anchorElement) {
return;
}
const accordionItemToOpen = anchorElement.closest(`.${AccordionItem.accordionItemElement}`);
if (accordionItemToOpen) {
window.helfiAccordions.forEach((accordion) => {
Expand Down
6 changes: 2 additions & 4 deletions templates/component/accordion.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
{{ attach_library('hdbt/accordion') }}

{% set controlled_content_id = "accordion-item-content--" ~ random() %}
{% set toggle_button_labelledby_id = "accordion-item-header--" ~ random() %}
{% set close_button_labelled_by_id = "accordion-item__button--close--" ~ random() %}

<div class="accordion__wrapper helfi-accordion-item" data-accordion-id="{{heading[0]['#context']['value']|clean_class}}">
<span class="is-hidden" id="{{ toggle_button_labelledby_id }}">{{ 'Toggle element: '|t({}, {'context': 'The helper text for toggle accordion visibility button'}) }}{{ heading|default('Missing heading'|t) }}</span>
<{{ heading_level|default('h2') }} class="accordion-item__header helfi-accordion__header" data-accordion-id="{{heading[0]['#context']['value']|clean_class}}">
<button class="accordion-item__button accordion-item__button--toggle helfi-accordion__header__button" aria-expanded="true" aria-controls="{{ controlled_content_id }}" aria-labelledby="{{ toggle_button_labelledby_id }}">
<button class="accordion-item__button accordion-item__button--toggle helfi-accordion__header__button" aria-expanded="true" aria-controls="{{ controlled_content_id }}">
{% if heading_icon %}
<div class="accordion-item__icon">
{% include '@hdbt/misc/icon.twig' ignore missing with {icon: heading_icon} %}
Expand All @@ -29,7 +27,7 @@

{{ content|default('Missing content'|t) }}

<button class="accordion-item__button accordion-item__button--close" aria-expanded="true" aria-controls="{{ controlled_content_id }}" aria-labelledby="{{ close_button_labelled_by_id }}">
<button class="accordion-item__button accordion-item__button--close" aria-controls="{{ controlled_content_id }}" aria-labelledby="{{ close_button_labelled_by_id }}">
<span class="is-hidden" id="{{ close_button_labelled_by_id }}">{{ 'Close element: '|t({}, {'context': 'The helper text for close accordion visibility button'}) }}{{ heading|default('Missing heading'|t) }}</span>
{{ 'Close'|t }}
</button>
Expand Down