Skip to content

Commit

Permalink
Carousel: Fix bug when carousel slides contain list elements (#534)
Browse files Browse the repository at this point in the history
* Use the `nav` element to query for child list items.

* Store the pagination class name in a constant and use to select the pagination component.

* Version bump to v14.3.16
  • Loading branch information
edwardcasbon authored Jul 18, 2024
1 parent 8e80b51 commit 2ec5c9e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "honeycomb-web-toolkit",
"version": "14.3.15",
"version": "14.3.16",
"repository": {
"type": "git",
"url": "https://github.com/red-gate/honeycomb-web-toolkit"
Expand Down
8 changes: 5 additions & 3 deletions src/carousel/js/honeycomb.carousel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import loadScript from '../../document/js/honeycomb.document.load-script';

const paginationClassName = 'carousel__pagination';

const rearrangeNav = (carousel) => {
// selectors
let nav = carousel.querySelector('ul');
let nav = carousel.querySelector(`ul.${paginationClassName}`);
let leftButton = carousel.querySelector('.slick-prev');
let rightButton = carousel.querySelector('.slick-next');

Expand All @@ -21,7 +23,7 @@ const rearrangeNav = (carousel) => {

// the left button can't be the first element in the <ul>, otherwise it messes up the navigation, which counts <ul> child elements to map the slides to the links - adding a new first-child pushes the links off by one
// so we need to add it to the end of the list, and translate its position by working out the width of the nav, plus the width of the arrow
let navWidth = ( carousel.querySelectorAll('ul li').length - 1 ) * 30 + 130;
let navWidth = ( nav.querySelectorAll('li').length - 1 ) * 30 + 130;
leftButton.style.transform = `translate(-${navWidth}px, 0px)`;

} else if(!nav && leftButton && rightButton) {
Expand Down Expand Up @@ -67,7 +69,7 @@ const init = ( config = {} ) => {
let carousel = carousels[ i ];
let options = {
autoplaySpeed: 4000,
dotsClass: 'slick-dots carousel__pagination',
dotsClass: `slick-dots ${paginationClassName}`,
adaptiveHeight: false,
dots: true
};
Expand Down

0 comments on commit 2ec5c9e

Please sign in to comment.