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

Add accessibility functionality to onscreen slides #1

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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: 2 additions & 0 deletions js/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ proto.settle = function( previousX ) {
this.positionSlider();
this.dispatchEvent( 'settle', null, [ this.selectedIndex ] );
}

this.checkVisibility();
};

proto.shiftWrapCells = function( x ) {
Expand Down
2 changes: 2 additions & 0 deletions js/drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ proto.updateDraggable = function() {
// disable dragging if less than 2 slides. #278
if ( this.options.draggable == '>1' ) {
this.isDraggable = this.slides.length > 1;
} else if (this.options.draggable === 'onOverflow') {
this.isDraggable = this.viewport.scrollWidth > this.viewport.offsetWidth;
} else {
this.isDraggable = this.options.draggable;
}
Expand Down
28 changes: 28 additions & 0 deletions js/flickity.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,34 @@ proto.queryCell = function( selector ) {
return this.getCell( selector );
};

proto.checkVisibility = function() {
var viewportX = this.viewport.getBoundingClientRect().x;
var viewportWidth = this.viewport.offsetWidth;

this.cells.forEach(function (cell) {
var cellX = cell.element.getBoundingClientRect().x - viewportX;
var isVisible = (
(cellX + cell.size.innerWidth > viewportX) && (cellX + cell.size.innerWidth < viewportWidth) ||
(cellX > viewportX) && (cellX < viewportWidth)
);

if (isVisible) {
cell.element.classList.add('is-visible');
cell.element.removeAttribute('aria-hidden');
const targetable = cell.element.querySelectorAll('button, a');

targetable.forEach(target => target.tabIndex = 0);

} else {
cell.element.classList.remove('is-visible');
cell.element.setAttribute('aria-hidden', true);
const targetable = cell.element.querySelectorAll('button, a');

targetable.forEach(target => target.tabIndex = -1);
}
});
};

// -------------------------- events -------------------------- //

proto.uiChange = function() {
Expand Down
2 changes: 2 additions & 0 deletions js/slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ proto.getLastCell = function() {
};

proto.select = function() {
this.parent.checkVisibility();

this.cells.forEach( function( cell ) {
cell.select();
} );
Expand Down
12 changes: 12 additions & 0 deletions sandbox/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ <h2>contain, few</h2>

<h2>watch, activate >900px</h2>

<h2>contain, only draggable if overflow</h2>

<div class="container variable-width js-flickity"
data-flickity-options='{ "contain": true, "cellAlign": "left", "draggable": "onOverflow" }'>
<div class="cell n1">1</div>
<div class="cell n2">2</div>
<div class="cell n3">3</div>
<div class="cell n4">4</div>
<div class="cell n5">5</div>
<div class="cell n6">6</div>
</div>

<div id="gallery5" class="container variable-width js-flickity"
data-flickity-options='{ "wrapAround": true, "watchCSS": true }'>
<div class="cell n1 w3"></div>
Expand Down