Skip to content

Commit 28ed646

Browse files
authored
Fix (carousel block): display correct layout and remove frontend console errors (#3619)
* fix console errors when not using infinite scrolling * fix carousel layout
1 parent 612e761 commit 28ed646

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/block/carousel/frontend-carousel.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,9 @@ class _StackableCarousel {
491491
onWheel = e => {
492492
const sliderElScrollLeft = this.sliderEl.scrollLeft
493493
const lastSlideOffset = this.slideEls[ this.slideEls.length - 1 ].offsetLeft
494-
const firstCloneOffset = this.clones[ 0 ].offsetLeft
495494
const slidesOffset = this.slideEls.map( slide => slide.offsetLeft )
496-
const clonesOffset = this.clones.map( slide => slide.offsetLeft )
495+
const firstCloneOffset = this.infiniteScroll && this.clones.length ? this.clones[ 0 ].offsetLeft : 0
496+
const clonesOffset = this.infiniteScroll && this.clones.length ? this.clones.map( slide => slide.offsetLeft ) : []
497497
if ( this.type === 'fade' ) {
498498
if ( this.wheelTimeout ) {
499499
return
@@ -549,7 +549,7 @@ class _StackableCarousel {
549549
let dx = e.clientX - this.initialClientX
550550
const sliderElScrollLeft = this.sliderEl.scrollLeft
551551
const lastSlideOffsetLeft = this.slideEls[ this.slideEls.length - 1 ].offsetLeft
552-
const firstCloneOffsetLeft = this.clones[ 0 ].offsetLeft
552+
const firstCloneOffsetLeft = this.infiniteScroll && this.clones.length ? this.clones[ 0 ].offsetLeft : 0
553553

554554
if ( this.type === 'slide' ) {
555555
if ( this.infiniteScroll && sliderElScrollLeft === 0 && dx > 0 ) {

src/styles/block.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454

5555
@include desktop-tablet {
5656
.stk-block:is(.aligncenter, .alignwide, .alignfull) > .stk-content-align:not(.alignwide):not(.alignfull),
57+
// Dev note: add selector for carousel because it has an extra wrapper before the inner blocks.
58+
.stk-block-carousel:is(.aligncenter, .alignwide, .alignfull) > :where(.stk-block-carousel__content-wrapper) > .stk-content-align:not(.alignwide):not(.alignfull),
5759
.stk-block .stk-block.aligncenter {
5860
// --stk-block-default-width is a Stackable setting
5961
// --stk-block-width-default-detected is from the fallback autodetected value.

src/styles/editor-block.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@
104104

105105
// For wide/full width blocks, but with their contents center aligned.
106106
:where(:is(.stk-preview-device-desktop, .stk-preview-device-tablet) [data-type^="stackable/"]:is([data-align="wide"], [data-align="full"]) > .stk-block > .stk-inner-blocks:not(.alignwide):not(.alignfull)),
107-
:where(:is(.stk-preview-device-desktop, .stk-preview-device-tablet) [data-type^="stackable/"]:is([data-align="wide"], [data-align="full"]) [data-type^="stackable/"][data-align="center"]) {
107+
:where(:is(.stk-preview-device-desktop, .stk-preview-device-tablet) [data-type^="stackable/"]:is([data-align="wide"], [data-align="full"]) [data-type^="stackable/"][data-align="center"]),
108+
// Dev note: add selector for carousel because it has an extra wrapper before the inner blocks.
109+
:where(:is(.stk-preview-device-desktop, .stk-preview-device-tablet) [data-type^="stackable/"]:is([data-align="wide"], [data-align="full"]) > .stk-block-carousel > :where(.stk-block-carousel__content-wrapper) > .stk-inner-blocks:not(.alignwide):not(.alignfull)) {
108110
// --stk-block-default-width is a Stackable setting
109111
// --stk-block-width-default-detected is from the fallback autodetected value.
110112
max-width: var(--stk-block-default-width, var(--stk-block-width-default-detected, 900px)) !important;

0 commit comments

Comments
 (0)