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 options to change prev & next button aria labels #985

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ var flky = new Flickity( '.gallery', {
// set img data-flickity-lazyload="src.jpg"
// set to number to load images adjacent cells

nextButtonAriaLabel: 'Next',
// sets next button aria-label

percentPosition: true,
// sets positioning in percent values, rather than pixels
// Enable if items have percent widths
Expand All @@ -122,6 +125,9 @@ var flky = new Flickity( '.gallery', {
prevNextButtons: true,
// creates and enables buttons to click to previous & next cells

prevButtonAriaLabel: 'Previous',
// sets previous button aria-label

pageDots: true,
// create and enable page dots

Expand Down
4 changes: 3 additions & 1 deletion js/flickity.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ Flickity.defaults = {
percentPosition: true,
resize: true,
selectedAttraction: 0.025,
setGallerySize: true
setGallerySize: true,
// watchCSS: false,
// wrapAround: false
prevButtonAriaLabel: 'Previous',
nextButtonAriaLabel: 'Next'
};

// hash of methods triggered on _create()
Expand Down
5 changes: 4 additions & 1 deletion js/prev-next-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ PrevNextButton.prototype._create = function() {
// init as disabled
this.disable();

element.setAttribute( 'aria-label', this.isPrevious ? 'Previous' : 'Next' );
var prevButtonAriaLabel = this.parent.options.prevButtonAriaLabel;
var nextButtonAriaLabel = this.parent.options.nextButtonAriaLabel;

element.setAttribute( 'aria-label', this.isPrevious ? prevButtonAriaLabel : nextButtonAriaLabel );

// create arrow
var svg = this.createSVG();
Expand Down
6 changes: 6 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<script>
Flickity.defaults.accessibility = false;
</script>

<!-- Customize previouse & next buttons to test the options. -->
<script>
Flickity.defaults.prevButtonAriaLabel = "Previous Custom Label";
Flickity.defaults.nextButtonAriaLabel = "Next Custom Label";
</script>
<!-- unit tests -->
<script src="unit/init.js"></script>
<script src="unit/cell-selector.js"></script>
Expand Down