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

fix(tabs): Improve accessibility - FRONT-3661 #2576

Merged
merged 8 commits into from
Jul 18, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`Tabs Default renders correctly 1`] = `
class="ecl-tabs"
data-ecl-auto-init="Tabs"
data-ecl-tabs="true"
role="tablist"
>
<div
class="ecl-tabs__container"
Expand All @@ -17,8 +18,10 @@ exports[`Tabs Default renders correctly 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
>
Item 1 label
</a>
Expand All @@ -27,8 +30,11 @@ exports[`Tabs Default renders correctly 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 2 label
</a>
Expand All @@ -37,8 +43,11 @@ exports[`Tabs Default renders correctly 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 3 label
</a>
Expand All @@ -47,8 +56,11 @@ exports[`Tabs Default renders correctly 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="true"
class="ecl-link ecl-tabs__link ecl-tabs__link--active"
href="/example"
role="tab"
tabindex="-1"
>
Item 4 label
</a>
Expand All @@ -57,8 +69,11 @@ exports[`Tabs Default renders correctly 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 5 label
</a>
Expand All @@ -67,8 +82,11 @@ exports[`Tabs Default renders correctly 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 6 with a very long label
</a>
Expand All @@ -77,8 +95,11 @@ exports[`Tabs Default renders correctly 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 7 label
</a>
Expand All @@ -88,6 +109,7 @@ exports[`Tabs Default renders correctly 1`] = `
>
<button
class="ecl-button ecl-button--secondary ecl-tabs__toggle"
tabindex="-1"
type="button"
>
<span
Expand Down Expand Up @@ -164,6 +186,7 @@ exports[`Tabs Default renders correctly with extra attributes 1`] = `
data-ecl-tabs="true"
data-test="data-test-value"
data-test-1="data-test-value-1"
role="tablist"
>
<div
class="ecl-tabs__container"
Expand All @@ -175,8 +198,10 @@ exports[`Tabs Default renders correctly with extra attributes 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
>
Item 1 label
</a>
Expand All @@ -185,8 +210,11 @@ exports[`Tabs Default renders correctly with extra attributes 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 2 label
</a>
Expand All @@ -195,8 +223,11 @@ exports[`Tabs Default renders correctly with extra attributes 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 3 label
</a>
Expand All @@ -205,8 +236,11 @@ exports[`Tabs Default renders correctly with extra attributes 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="true"
class="ecl-link ecl-tabs__link ecl-tabs__link--active"
href="/example"
role="tab"
tabindex="-1"
>
Item 4 label
</a>
Expand All @@ -215,8 +249,11 @@ exports[`Tabs Default renders correctly with extra attributes 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 5 label
</a>
Expand All @@ -225,8 +262,11 @@ exports[`Tabs Default renders correctly with extra attributes 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 6 with a very long label
</a>
Expand All @@ -235,8 +275,11 @@ exports[`Tabs Default renders correctly with extra attributes 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 7 label
</a>
Expand All @@ -246,6 +289,7 @@ exports[`Tabs Default renders correctly with extra attributes 1`] = `
>
<button
class="ecl-button ecl-button--secondary ecl-tabs__toggle"
tabindex="-1"
type="button"
>
<span
Expand Down Expand Up @@ -320,6 +364,7 @@ exports[`Tabs Default renders correctly with extra class names 1`] = `
class="ecl-tabs custom-class custom-class--test"
data-ecl-auto-init="Tabs"
data-ecl-tabs="true"
role="tablist"
>
<div
class="ecl-tabs__container"
Expand All @@ -331,8 +376,10 @@ exports[`Tabs Default renders correctly with extra class names 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
>
Item 1 label
</a>
Expand All @@ -341,8 +388,11 @@ exports[`Tabs Default renders correctly with extra class names 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 2 label
</a>
Expand All @@ -351,8 +401,11 @@ exports[`Tabs Default renders correctly with extra class names 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 3 label
</a>
Expand All @@ -361,8 +414,11 @@ exports[`Tabs Default renders correctly with extra class names 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="true"
class="ecl-link ecl-tabs__link ecl-tabs__link--active"
href="/example"
role="tab"
tabindex="-1"
>
Item 4 label
</a>
Expand All @@ -371,8 +427,11 @@ exports[`Tabs Default renders correctly with extra class names 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 5 label
</a>
Expand All @@ -381,8 +440,11 @@ exports[`Tabs Default renders correctly with extra class names 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 6 with a very long label
</a>
Expand All @@ -391,8 +453,11 @@ exports[`Tabs Default renders correctly with extra class names 1`] = `
class="ecl-tabs__item"
>
<a
aria-selected="false"
class="ecl-link ecl-tabs__link"
href="/example"
role="tab"
tabindex="-1"
>
Item 7 label
</a>
Expand All @@ -402,6 +467,7 @@ exports[`Tabs Default renders correctly with extra class names 1`] = `
>
<button
class="ecl-button ecl-button--secondary ecl-tabs__toggle"
tabindex="-1"
type="button"
>
<span
Expand Down
49 changes: 31 additions & 18 deletions src/implementations/twig/components/tabs/tabs.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
{% set _css_class = 'ecl-tabs' %}
{% set _extra_attributes = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see that we normally define our internal variable for attributes as a string that gets populated by looping into the extra_attributes param, and it's ok since it's going to be rendered as a string. But when we have "internal" attributes to set, it would feel natural to merge these values into the extra_attributes array and get the _extra_attributes string as the result of the internal and external attributes processing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, I properly understand the issue here, we are doing same in expandable and news-ticker

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not an issue, just that we are requesting extra attributes as objects with name and value for then processing them to generate a string. if we are about to create internal attributes i would merge these with the extra_attributes array in order to process them in one place consistently. I know that we have other use cases like this, but that doesn't make it right. it was a suggestion, if you like it like this, keep it that way.

'data-ecl-tabs="true"',
'data-ecl-auto-init="Tabs"']|join(' ')
'data-ecl-auto-init="Tabs"',
'role="tablist"']|join(' ')
%}

{# Internal logic - Process properties #}
Expand Down Expand Up @@ -62,24 +63,35 @@
<nav class="{{ _css_class }}"{{ _extra_attributes|raw }}>
<div class="ecl-tabs__container">
<ul class="ecl-tabs__list">
{% for _item in _items %}
{% if _item.path is not empty %}
<li class="ecl-tabs__item">
{% set _item_extra_classes = 'ecl-tabs__link' %}
{% if _item.is_current is defined and _item.is_current is not empty %}
{% set _item_extra_classes = _item_extra_classes ~ ' ecl-tabs__link--active' %}
{% for _item in _items %}
{% if _item.path is not empty %}
<li class="ecl-tabs__item">
{% set _item_extra_classes = 'ecl-tabs__link' %}
{% set _item_extra_attributes = [{ name: 'role', value: 'tab' }] %}
{% if loop.index != 1 %}
{% set _item_extra_attributes = _item_extra_attributes|merge([{ name: 'tabindex', value: '-1' }]) %}
{% endif %}
{% if _item.is_current is defined and _item.is_current is not empty %}
{% set _item_extra_classes = _item_extra_classes ~ ' ecl-tabs__link--active' %}
{% set _item_extra_attributes = _item_extra_attributes|merge([{ name: 'aria-selected', value: 'true' }]) %}
{% else %}
{% set _item_extra_attributes = _item_extra_attributes|merge([{ name: 'aria-selected', value: 'false' }]) %}
{% endif %}
{% if _menu is not empty %}
{% set extra_attributes = extra_attributes|merge([{ name: 'data-ecl-has-menu' }]) %}
{% endif %}
{% include '@ecl/link/link.html.twig' with {
link: {
label: _item.label,
path: _item.path,
},
extra_classes: _item_extra_classes,
extra_attributes: _item_extra_attributes,
} only %}
</li>
{% endif %}
{% include '@ecl/link/link.html.twig' with {
link: {
label: _item.label,
path: _item.path,
},
extra_classes: _item_extra_classes,
} only %}
</li>
{% endif %}
{% endfor %}
<li class="ecl-tabs__item ecl-tabs__item--more">
{% endfor %}
<li class="ecl-tabs__item ecl-tabs__item--more">
{% include '@ecl/button/button.html.twig' with {
label: _more_label,
variant: 'secondary',
Expand All @@ -92,6 +104,7 @@
transform: 'rotate-180'
},
extra_classes: 'ecl-tabs__toggle',
extra_attributes: [{ name: 'tabindex', value: '-1' }],
Copy link
Contributor

@planctus planctus Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i understand that we are introducing navigation through keyboard arrows, but why disabling the standard navigation via Tab..? It feels really weird to access the first tab with a Tab and then being moved out of the tabs typing again Tab. This way the user really have to know that the only way of navigating our tabs would be using arrows.
Also because the standard navigation would be working decently in most of the viewports and only when some tabs get hidden it would be really problematic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically the request, to only be able to navigate with arrows and thus be able to go to the content more quickly without having to tab all tabs. https://www.w3.org/WAI/ARIA/apg/example-index/tabs/tabs-manual.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't understand, really..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can discuss this on the next weekly if you want ;)

} only %}
</li>
</ul>
Expand Down
Loading