Skip to content

Commit

Permalink
🛠 add cell aria-selected & page dot aria-label
Browse files Browse the repository at this point in the history
In place of #693
  • Loading branch information
desandro committed Feb 27, 2018
1 parent 6399063 commit 26e1889
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions js/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var proto = Cell.prototype;

proto.create = function() {
this.element.style.position = 'absolute';
this.element.setAttribute( 'aria-selected', 'false' );
this.x = 0;
this.shift = 0;
};
Expand All @@ -47,6 +48,7 @@ proto.destroy = function() {
// reset style
this.element.style.position = '';
var side = this.parent.originSide;
this.element.removeAttribute('aria-selected');
this.element.style[ side ] = '';
};

Expand Down
10 changes: 8 additions & 2 deletions js/page-dots.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ PageDots.prototype.setDots = function() {
PageDots.prototype.addDots = function( count ) {
var fragment = document.createDocumentFragment();
var newDots = [];
while ( count ) {
var length = this.dots.length;
var max = length + count;

for ( var i = length; i < max; i++ ) {
var dot = document.createElement('li');
dot.className = 'dot';
dot.setAttribute( 'aria-label', 'Page dot ' + ( i + 1 ) );
fragment.appendChild( dot );
newDots.push( dot );
count--;
}

this.holder.appendChild( fragment );
this.dots = this.dots.concat( newDots );
};
Expand All @@ -103,13 +107,15 @@ PageDots.prototype.updateSelected = function() {
// remove selected class on previous
if ( this.selectedDot ) {
this.selectedDot.className = 'dot';
this.selectedDot.removeAttribute('aria-current');
}
// don't proceed if no dots
if ( !this.dots.length ) {
return;
}
this.selectedDot = this.dots[ this.parent.selectedIndex ];
this.selectedDot.className = 'dot is-selected';
this.selectedDot.setAttribute( 'aria-current', 'step' );
};

PageDots.prototype.onTap = function( event ) {
Expand Down
10 changes: 6 additions & 4 deletions js/slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,18 @@ proto.getLastCell = function() {
};

proto.select = function() {
this.changeSelectedClass('add');
this.changeSelected( true );
};

proto.unselect = function() {
this.changeSelectedClass('remove');
this.changeSelected( false );
};

proto.changeSelectedClass = function( method ) {
proto.changeSelected = function( isSelected ) {
var classMethod = isSelected ? 'add' : 'remove';
this.cells.forEach( function( cell ) {
cell.element.classList[ method ]('is-selected');
cell.element.classList[ classMethod ]('is-selected');
cell.element.setAttribute( 'aria-selected', isSelected.toString() );
});
};

Expand Down

0 comments on commit 26e1889

Please sign in to comment.