Comments (7)
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.
https://www.npmjs.com/package/react-swipeable-views-react-18-fix
from react-swipeable-views.
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.
If this is being deprecated, any suggestions of good alternatives?
from react-swipeable-views.
@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.
If this is being deprecated, any suggestions of good alternatives?
- Swiper (mui/material-ui#33274 (comment))
- Embla Carousel (#668 (comment))
- react-slide-routes (as a replacement for react-swipeable-routes)
from react-swipeable-views.
@phaux can you make this a library on npm?
from react-swipeable-views.
Related Issues (20)
- Ignored attempt to cancel a touchmove event with cancelable=false
- Media options (download and picture and picture mode) not showing up from video controls (kebab menu) inside react swipeable views
- unpin @babel/runtime HOT 1
- Virtualized SwipeableViews: Redundant transition when reaching the overscan limit while swiping with arrow keys
- Peer dependency for React 16 HOT 1
- Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code HOT 9
- Update to be used along with react 18 HOT 27
- Can the container fit the width of the slideshow?
- add arrow in the slide
- SwipeableViews rerender too much
- Swiper virtualize slideRenderer animation is not normal
- New configurator required in react HOT 1
- Will not install with react 18.2.0 HOT 4
- 居然没有无限轮播功能? HOT 3
- 'SwipeableViews' cannot be used as a JSX component. HOT 1
- Feature request: ARIA attributes on individual slides
- Endless loading images when swiping
- Peer Dependency issues with React18 HOT 1
- The height does not get the element border when using animateHeight HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-swipeable-views.