Skip to content

Commit

Permalink
Don’t reverse slide order until width is known
Browse files Browse the repository at this point in the history
  • Loading branch information
weotch committed Jan 20, 2024
1 parent 60579b9 commit 27652fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/concerns/rtl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ export default

# As an easy way to support rtl, update the index to the final value
# when RTL is enabled. This is change is combined with reversing the order
# of the slides in `ssr-carousel-track`. The downside of this appraoch is
# that it's not SSR friendly; the x position of the track can't be calcualted
# until the component mounts and it's internal width can be measured.
# of the slides in `ssr-carousel-track`
created: -> @index = @pages - @value - 1 if @rtl
9 changes: 8 additions & 1 deletion src/ssr-carousel-track.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default
leftPeekingSlideIndex: Number
rightPeekingSlideIndex: Number
rtl: Boolean
slideWidth: Number

data: ->

Expand Down Expand Up @@ -112,7 +113,13 @@ export default
getSlideComponents: ->
slides = [...(@$slots.default || []), ...(@$slots.clones || [])]
.filter (vnode) -> !vnode.text
if @rtl then slides = slides.reverse()

# Reverses the slide if rtl and if the slide slide width is known. This
# second condition exists to prevent the reversal from happening on SSR.
# Which is important because this logic is paired with setting the
# intial index to the last page which can't be known until the slide
# width is known.
if @rtl and @slideWidth then slides = slides.reverse()
return slides

# Makes a clone of the vnode properties we'll be updating so the changes
Expand Down
1 change: 1 addition & 0 deletions src/ssr-carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
leftPeekingSlideIndex,
rightPeekingSlideIndex,
rtl,
slideWidth,
}`)

//- Render the slotted slides
Expand Down

0 comments on commit 27652fe

Please sign in to comment.