Skip to content

Commit

Permalink
[MWPW-151474] Ensure carousel navigation is displayed after everythin…
Browse files Browse the repository at this point in the history
…g has been loaded (adobecom#2427)

[MWPW-151474] Ensure navigation is displayed after everything has been loaded
  • Loading branch information
narcis-radu authored and mokimo committed Jun 11, 2024
1 parent 4faf094 commit 7266eb1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions libs/blocks/carousel/carousel.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
margin-bottom: 1.8rem;
}

/* Late loading controls */
.carousel .is-delayed {
visibility: hidden;
}

.carousel .carousel-wrapper {
position: relative;
overflow: hidden;
Expand Down
17 changes: 12 additions & 5 deletions libs/blocks/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function decorateNextPreviousBtns() {
const previousBtn = createTag(
'button',
{
class: 'carousel-button carousel-previous',
class: 'carousel-button carousel-previous is-delayed',
'aria-label': 'Previous',
'data-toggle': 'previous',
},
Expand All @@ -30,7 +30,7 @@ function decorateNextPreviousBtns() {
const nextBtn = createTag(
'button',
{
class: 'carousel-button carousel-next',
class: 'carousel-button carousel-next is-delayed',
'aria-label': 'Next',
'data-toggle': 'next',
},
Expand All @@ -43,15 +43,15 @@ function decorateLightboxButtons() {
const expandBtn = createTag(
'button',
{
class: 'lightbox-button carousel-expand',
class: 'lightbox-button carousel-expand is-delayed',
'aria-label': 'Open in full screen',
},
LIGHTBOX_ICON,
);
const closeBtn = createTag(
'button',
{
class: 'lightbox-button carousel-close',
class: 'lightbox-button carousel-close is-delayed',
'aria-label': 'Close full screen carousel',
},
CLOSE_ICON,
Expand Down Expand Up @@ -342,7 +342,7 @@ export default function init(el) {
const fragment = new DocumentFragment();
const nextPreviousBtns = decorateNextPreviousBtns();
const slideIndicators = decorateSlideIndicators(slides);
const controlsContainer = createTag('div', { class: 'carousel-controls' });
const controlsContainer = createTag('div', { class: 'carousel-controls is-delayed' });

fragment.append(...slides);
const slideWrapper = createTag('div', { class: 'carousel-wrapper' });
Expand Down Expand Up @@ -395,4 +395,11 @@ export default function init(el) {
}
slides.slice(NoOfVisibleSlides).forEach((slide) => slide.querySelectorAll('a').forEach((focusableElement) => { focusableElement.setAttribute('tabindex', -1); }));
handleChangingSlides(carouselElements);

function handleLateLoadingNavigation() {
[...el.querySelectorAll('.is-delayed')].forEach((item) => item.classList.remove('is-delayed'));
parentArea.removeEventListener(MILO_EVENTS.DEFERRED, handleLateLoadingNavigation, true);
}

parentArea.addEventListener(MILO_EVENTS.DEFERRED, handleLateLoadingNavigation, true);
}

0 comments on commit 7266eb1

Please sign in to comment.