-
Notifications
You must be signed in to change notification settings - Fork 24
WIP(5514): Short-term Slick carousel accessibility patch (theme JS) #5528
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Accessibility runtime patch for Slick carousel (short-term fix for #5514) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // - Adjust roles on dot navigation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // - Add aria-label to track | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // - Prevent focusable elements inside aria-hidden slides | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (function ($, Drupal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check warning on line 5 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'use strict'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 6 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $(document).once('slick-a11y-patch').each(function () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 7 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // When slick initializes, apply corrections | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $(document).on('init reInit', '.slick-slider', function (event, slick) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 9 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var $slider = $(this); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 10 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ensure track has accessible name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var $track = $slider.find('.slick-track'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 12 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($track.length && !$track.attr('aria-label')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $track.attr('aria-label', $slider.data('a11y-label') || 'Carousel slides'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 14 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // fix dots role | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var $dots = $slider.find('.slick-dots'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 17 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($dots.length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $dots.attr('role', 'list'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $dots.find('li').each(function (i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 20 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $(this).removeAttr('role aria-selected aria-controls'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ensure internal button has accessible label | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var $btn = $(this).find('button'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 23 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($btn.length && !$btn.attr('aria-label')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $btn.attr('aria-label', 'Go to slide ' + (i+1)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 25 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check warning on line 27 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+16
to
+27
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // hide focusable children of aria-hidden slides | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $slider.find('.slick-slide[aria-hidden="true"]').each(function () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 30 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $(this).find('a, button, input, select, textarea').attr('tabindex', '-1'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 31 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check warning on line 32 in themes/custom/az_barrio/js/slick-a11y-patch.js
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+29
to
+32
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // remove problematic role on slide wrapper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $slider.find('.slick-slide').removeAttr('role tabindex'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| })(jQuery, Drupal); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+37
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (function ($, Drupal) { | |
| 'use strict'; | |
| $(document).once('slick-a11y-patch').each(function () { | |
| // When slick initializes, apply corrections | |
| $(document).on('init reInit', '.slick-slider', function (event, slick) { | |
| var $slider = $(this); | |
| // ensure track has accessible name | |
| var $track = $slider.find('.slick-track'); | |
| if ($track.length && !$track.attr('aria-label')) { | |
| $track.attr('aria-label', $slider.data('a11y-label') || 'Carousel slides'); | |
| } | |
| // fix dots role | |
| var $dots = $slider.find('.slick-dots'); | |
| if ($dots.length) { | |
| $dots.attr('role', 'list'); | |
| $dots.find('li').each(function (i) { | |
| $(this).removeAttr('role aria-selected aria-controls'); | |
| // ensure internal button has accessible label | |
| var $btn = $(this).find('button'); | |
| if ($btn.length && !$btn.attr('aria-label')) { | |
| $btn.attr('aria-label', 'Go to slide ' + (i+1)); | |
| } | |
| }); | |
| } | |
| // hide focusable children of aria-hidden slides | |
| $slider.find('.slick-slide[aria-hidden="true"]').each(function () { | |
| $(this).find('a, button, input, select, textarea').attr('tabindex', '-1'); | |
| }); | |
| // remove problematic role on slide wrapper | |
| $slider.find('.slick-slide').removeAttr('role tabindex'); | |
| }); | |
| }); | |
| })(jQuery, Drupal); | |
| (function ($, Drupal, once) { | |
| 'use strict'; | |
| Drupal.behaviors.slickA11yPatch = { | |
| attach: function (context) { | |
| once('slick-a11y-patch', document).forEach(function () { | |
| // When slick initializes, apply corrections | |
| $(document).on('init reInit', '.slick-slider', function (event, slick) { | |
| var $slider = $(this); | |
| // ensure track has accessible name | |
| var $track = $slider.find('.slick-track'); | |
| if ($track.length && !$track.attr('aria-label')) { | |
| $track.attr('aria-label', $slider.data('a11y-label') || 'Carousel slides'); | |
| } | |
| // fix dots role | |
| var $dots = $slider.find('.slick-dots'); | |
| if ($dots.length) { | |
| $dots.attr('role', 'list'); | |
| $dots.find('li').each(function (i) { | |
| $(this).removeAttr('role aria-selected aria-controls'); | |
| // ensure internal button has accessible label | |
| var $btn = $(this).find('button'); | |
| if ($btn.length && !$btn.attr('aria-label')) { | |
| $btn.attr('aria-label', 'Go to slide ' + (i + 1)); | |
| } | |
| }); | |
| } | |
| // hide focusable children of aria-hidden slides | |
| $slider.find('.slick-slide[aria-hidden="true"]').each(function () { | |
| $(this).find('a, button, input, select, textarea').attr('tabindex', '-1'); | |
| }); | |
| // remove problematic role on slide wrapper | |
| $slider.find('.slick-slide').removeAttr('role tabindex'); | |
| }); | |
| }); | |
| } | |
| }; | |
| })(jQuery, Drupal, once); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
az-slick-a11y-patchis defined twice in this YAML. Duplicate keys are invalid YAML and can lead to parsing errors or unexpected overrides (only the last definition may win). Remove the duplicate entry, and (since the JS usesonce()semantics) add the appropriate dependency (likelycore/once) to the remaining library definition.