Giter VIP home page Giter VIP logo

Comments (7)

oliviertassinari avatar oliviertassinari commented on June 10, 2024 11

As a side note, at MUI, we have the plan to bring a native carousel component into MUI's product: mui/material-ui#33392, mui/mui-x#3601.

I don't know if we will start from my project (react-swipeable-views), it will be up to the engineering of the team who takes ownership of it.

from react-swipeable-views.

u12206050 avatar u12206050 commented on June 10, 2024 9

https://www.npmjs.com/package/react-swipeable-views-react-18-fix

from react-swipeable-views.

phaux avatar phaux commented on June 10, 2024 7

I replaced usage of this library with my own tiny implementation and it is working just fine for me:

import { useEffect, useRef } from "react"

export function SwipeableViews(
  { className = "", index, onChangeIndex, ...rootProps }: 
    { index: number, onChangeIndex: (index: number) => void } & React.HTMLProps<HTMLDivElement>
) {
  const containerRef = useRef<HTMLDivElement>(null)
  const scrollTimeout = useRef<number>()

  useEffect(() => {
    containerRef.current?.children[index]?.scrollIntoView({ behavior: "smooth" })
  }, [index])

  return (
    <div
      {...rootProps}
      ref={containerRef}
      className={
        "flex snap-x snap-mandatory overflow-x-scroll " +
        "*:w-full *:flex-shrink-0 *:snap-center *:snap-always " + className
      }
      onScroll={({ currentTarget }) => {
        if (scrollTimeout.current) clearTimeout(scrollTimeout.current)
        scrollTimeout.current = window.setTimeout(() => {
          const pageWidth = currentTarget.scrollWidth / currentTarget.children.length
          onChangeIndex(Math.round(currentTarget.scrollLeft / pageWidth))
        }, 100)
      }}
    />
  )
}

It doesn't add aria-hidden attribute automatically, but you can add it to the slides at usage side. (see codesandbox)

It also doesn't animate container's height. The height is just max height of children. You can give max-height to children and make them scrollable instead.

It probably doesn't work in react-native, because it uses scroll-snap.

Codesandbox (version without tailwind) (edit: updated with more features)

Edit2: I made a library

from react-swipeable-views.

twltwl avatar twltwl commented on June 10, 2024 3

If this is being deprecated, any suggestions of good alternatives?

from react-swipeable-views.

phaux avatar phaux commented on June 10, 2024 2

@phaux can you make this a library on npm?

Maybe. In the meanwhile you can just copy SwipeableViews.tsx and SwipeableViews.css from the CodeSandbox into your project.

Edit: Here's the library

from react-swipeable-views.

flying-sheep avatar flying-sheep commented on June 10, 2024

If this is being deprecated, any suggestions of good alternatives?

from react-swipeable-views.

croraf avatar croraf commented on June 10, 2024

@phaux can you make this a library on npm?

from react-swipeable-views.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.