Skip to content
Snippets Groups Projects
Unverified Commit 9343436f authored by Alexis BENOIT's avatar Alexis BENOIT Committed by GitHub
Browse files

[a11y] Slider pagination : ajout de `aria-describedby` (#779)

parent ef3f3409
No related branches found
No related tags found
No related merge requests found
......@@ -15,11 +15,12 @@ osuny.SlidersFactory = function () {
};
osuny.SlidersFactory.prototype.create = function (element, index) {
var title = this.getTitle(element, index);
var titleId;
// Check if carousel as more than one slide
if (element.children.length > 1) {
this.sliders.push(new osuny.Slider(element, title));
titleId = this.getTitleId(element, index);
this.sliders.push(new osuny.Slider(element, titleId));
}
};
......@@ -41,8 +42,8 @@ osuny.SlidersFactory.prototype.checkDisableCondition = function (slider, index)
}
};
osuny.SlidersFactory.prototype.getTitle = function (element, index) {
var title = osuny.i18n.slider.default_title + ' ' + index,
osuny.SlidersFactory.prototype.getTitleId = function (element, index) {
var titleElement,
block = element.closest('.block-titled'),
blockTitle;
......@@ -51,10 +52,23 @@ osuny.SlidersFactory.prototype.getTitle = function (element, index) {
}
if (blockTitle) {
title = blockTitle.innerText;
titleElement = blockTitle;
} else {
titleElement = this.createDefaultTitle(element, index);
element.parentElement.prepend(titleElement);
}
return title;
titleElement.id = 'slider-title-' + index;
return titleElement.id;
};
osuny.SlidersFactory.prototype.createDefaultTitle = function (element, index) {
var titleElement = document.createElement('p');
titleElement.innerText = osuny.i18n.slider.default_title + ' ' + index;
titleElement.classList.add('sr-only');
return titleElement;
};
osuny.SlidersFactory.prototype.listen = function () {
......
......@@ -7,7 +7,7 @@ osuny.SliderPagination = function (slider) {
this.container = document.createElement('ul');
this.container.classList.add('slider-pagination');
this.container.setAttribute('aria-label', osuny.i18n.slider.pagination_list);
this.container.setAttribute('aria-description', this.slider.title);
this.container.setAttribute('aria-describedby', this.slider.titleId);
this.slider.controls.appendChild(this.container);
this.create();
};
......@@ -25,6 +25,7 @@ osuny.SliderPagination.prototype.createButton = function (index) {
a11yText = osuny.i18n.slider.goto + ' ' + (index + 1);
osuny.utils.insertSROnly(button, a11yText);
button.setAttribute('aria-describedby', this.slider.titleId);
item.appendChild(button);
this.container.appendChild(item);
......
......@@ -10,9 +10,9 @@ osuny.sliderComponents = {
pagination: osuny.SliderPagination
};
osuny.Slider = function (list, title) {
osuny.Slider = function (list, titleId) {
this.list = list;
this.title = title;
this.titleId = titleId;
this.setState();
this.setOptions();
};
......
......@@ -9,7 +9,7 @@
margin-bottom: calc(#{$spacing-3} + #{$spacing-2})
.block-title + .description
margin-top: $spacing-3
.block-title.hidden + .description
.block-title.sr-only + .description
margin-top: 0
@include in-page-without-sidebar
--block-space-y: #{$block-space-y-desktop}
......
......@@ -10,7 +10,7 @@
@include grid(4, desktop)
&.odd-items
@include grid(3, desktop)
.top:not(.hidden) + ul
.top + ul
margin-top: $spacing-4
align-items: baseline
li > span
......
......@@ -5,6 +5,7 @@
height: 1px !important
overflow: hidden !important
padding: 0 !important
margin: 0 !important
position: absolute !important
width: 1px !important
white-space: nowrap !important
......
......@@ -116,7 +116,7 @@
display: flex
.block-title
width: columns(4)
&:not(.hidden) + .description
+ .description
margin-left: var(--grid-gutter)
.description
margin-top: 0
......
......@@ -8,7 +8,7 @@
{{ partial "blocks/top.html" (dict
"title" $block.title
"heading_level" $block.ranks.self
"hidden" true
"sr_only" true
)}}
<div class="testimonials" data-slider="{{ site.Params.blocks.testimonials.slider | encoding.Jsonify }}">
{{ range .testimonials }}
......
......@@ -11,7 +11,7 @@
)}}
{{ if or .title .description }}
<div class="top {{ if .hidden }}hidden{{ end }}">
<div class="top {{ if .sr_only }}sr-only{{ end }}">
{{ if .title }}
{{ $heading_tag.open }}
{{- if .link -}}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment