swiper -- slidesPerView={'auto'} wont work for me
Asked Answered
C

3

11

im working on a swiper. my intention is to collect some in slider but i dont want to use breakPonit attribute for responsively work. i want to slidesPerView, automatically fill the swiper wrapper. i read the document and use Demo... the resault is like that just one apear on the view, while width and spaceBetween is minimun and in wide screen wont change.

this is my code but its not my desired:

import React from 'react';
import { Swiper, SwiperSlide } from "swiper/react";
import "swiper/css";
import "swiper/css/navigation";
import "swiper/css/scrollbar";
import "swiper/css/free-mode";
import SwiperCore, { Autoplay, FreeMode, Navigation, Scrollbar } from "swiper";
import { styled } from "@mui/material";

SwiperCore.use([Scrollbar,FreeMode, Autoplay, Navigation]);

//-----------style to swiper by: styled()
let Swip = styled(Swiper)(({ theme }) => ({
    padding: 17,
    paddingBottom: 35,
    width: "90%",
    "& .swiper-wrapper": { padding: 0 },
    
}));
export default function Brands() {
  return( 
  <Swip
                // autoplay={{
                //     delay: 6000,
                //     disableOnInteraction: false,
                // }}
                navigation={true}
                spaceBetween={10}
                loop={true}
                freeMode={true}
                scrollbar={{
                  "hide":false
                }}
            >
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                <SwiperSlide>
                    <div style={{width:100,height:50 , backgroundColor:'black'}}/>
                </SwiperSlide>
              
                
              
            </Swip>
  )}

Commandeer answered 23/1, 2022 at 12:5 Comment(1)
I'm having the same problem. Did you manage to solve it?Relevance
L
15

I researched a lot and finally found out that you have to override slides css to force them to be specific width. For example according to it's content:.swiper-slide { width: auto; }

Loner answered 14/1, 2023 at 11:24 Comment(0)
D
0

In my case I was rendering a list of components using map without key. Adding key helped me with the issue.

Darden answered 25/11, 2023 at 4:12 Comment(0)
B
-3

Did you try slidesPerView="auto" and not {'auto'}?

Bellicose answered 27/12, 2023 at 12:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.