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

[MWPW-151474] Ensure carousel navigation is displayed after everything has been loaded #2427

Merged
merged 2 commits into from
Jun 10, 2024
Merged
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
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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of repetition for is-delayed, would it be worth to turn it into a constant?

'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);
}
Loading