akiran / react-slick

React carousel component
http://react-slick.neostack.com/
MIT License
11.77k stars 2.11k forks source link

Styles overwritten on application-owned div elements #1180

Closed nihlton closed 5 years ago

nihlton commented 6 years ago

demo: https://codesandbox.io/s/7yvq357xz6

for the given markup:

<Slider {...settings}>
  <div style={slideStyle}>
    <img style={imageStyle} src="http://placekitten.com/g/400/200" />
  </div>
  ...
</Slider>

{slideStyle} will be ignored / overwritten.

lironzluf commented 6 years ago

Got the same issue, they're overwritten by

style: {
 width: 100 / settings.slidesPerRow + "%",
 display: "inline-block"
}
mihauko commented 6 years ago

Are those inline styles connected to additional div wrapper like on screenshot? What is the purpose of this div?

selection_0961

It can be also visible on @nihlton demo.

I have this structure on 0.23.1 version

ViacheslavBurlaka commented 6 years ago

@mihauko i have the same problem

nihlton commented 6 years ago

@mihauko - was wondering that as well.

I suspect that they intended to apply those styles to the additional div wrapper, and are applying them to the application div instead.

nihlton commented 6 years ago

any update on this issue?

dhruvramdev commented 6 years ago

Facing Same Issue.

nihlton commented 6 years ago

any update on this issue?

mopilo commented 6 years ago

same here

charliedavison commented 6 years ago

+1

tetogomez commented 6 years ago

useful component but it's so hard to use with custom styles. :(

charliedavison commented 6 years ago

Ended up wrapping an extra div around everything so we could prevent our styles from being overwritten. Would be nice if this was fixed properly though.

remingtonchan commented 6 years ago

@charliedavison Hi, how was your approach in "wrapping everything"? I still can't get around this. 😅

pinglinh commented 5 years ago

Any updates on this issue? 😭

goriverna commented 5 years ago

As a workaround, you can use className on your div and define css class, in this way you can override css rules.

<Slider {...settings}>
  <div className='slick-custom'>
    <img  src="http://placekitten.com/g/400/200" />
  </div>
  ...
</Slider>

and then create css rule on you css style:

.slick-custom{
    display: flex !important;
    justify-content: center;
}
akiran commented 5 years ago

Fixed in react-slick@0.25.2

chrisneal commented 4 years ago

@akiran We're still experiencing this issue in 0.25.2.

manugo-dev commented 4 years ago

same here

noobG commented 4 years ago

yep still broken

rphly commented 4 years ago

Hi guys, I found a workaround for this although it's less than ideal.

You can wrap your application div with <ul> and the styles won't be overwritten.

Example:

return (
    <ul key={i}>
        {...your component here}    
    </ul> 
)

to clarify, your component can use inline JS styles as usual without the need for css classname

abhishekashyap commented 4 years ago

Any follow-ups? Still experiencing on 0.27.0

tazcarper commented 4 years ago

Still occurring in 0.27.0. Any ETA on fix?

tazcarper commented 4 years ago

Could this issue be because React used to require you wrapping lists with a <div> or something similar? We can use <React.Fragment> instead now and it wont add the unnecessary empty <div> within the slides. Seems like the root is around the logic creating rows per slide. Even if you have one row, it still executes this.

slider.js Replace this: newSlide.push(<div key={10 * i + j}>{row}</div>);

With this: newSlide.push(<React.Fragment key={10 * i + j}>{row}</React.Fragment>);

tazcarper commented 4 years ago

Sounds like the author wants to wait until a future major change to implement this.

templateio commented 4 years ago

Create a component for slide and use Hooks to pass style: Slide.js or \ :

function Slide() { 
const [style, setStyle] = useState({  
  backgroundImage: 'url(' + process.env.PUBLIC_URL +'/img/url.jpg)',  
  backgroundRepeat: 'no-repeat'  
});  

return (  
  <div  
    className="..."  
    style={style}  
  >  
  ...content...  
  </div>  
)  

Hook logic will ensure that your component always stays up to date with state! https://reactjs.org/docs/hooks-state.html if using redux global state you can use useSelector PS inside <Slider {...settings}> you can map 's with Slide list component for extra fancy points

c-jain commented 3 years ago

I am still facing this issue with version 0.28.0. I want my div to have display: flex; but it is not working. Did anyone get the solution? currently, I am adding !important to fix the situation but a cleaner solution would be great. Please someone help!

performautodev commented 3 years ago

I am still facing this issue with version 0.28.0. I want my div to have display: flex; but it is not working. Did anyone get the solution? currently, I am adding !important to fix the situation but a cleaner solution would be great. Please someone help!

You can change on node_modules\react-slick\lib\slider.js L 251

newSlide.push( /#PURE/_react["default"].createElement("div", { key: 10 * i + j }, row));

By : newSlide.push( /#PURE/_react["default"].createElement(_react["default"].Fragment, { key: 10 * i + j }, row));

AgainPsychoX commented 3 years ago

Still experiencing the same issue, sadly, we need to wait for major update I guess, since bReAkInG cHaNgEs :C

easyrun32 commented 2 years ago

A work around this without messing with inline-block is to just wrap it again

<Slider {...settings}>

        <div className='dont_touch_wrapper'> // some css injected by slider * no touch*

          <div className='container_flex'> 
            <div className='a'>A</div>
            <div className='b'>B</div>
          </div>

       </div>

</Slider/>
mz3r0 commented 1 year ago

Somehow used to work, moved files to another location and suddenly got this issue. Easiest temporary fix for me was to use !important on my css.