Giter VIP home page Giter VIP logo

Comments (14)

veewee avatar veewee commented on June 12, 2024 1

We are also facing this problem when the slider is placed in a react-bootstrap TabPane.
Currently, I am solving the issue by triggering a resize event during change of tabs:

window.dispatchEvent(new Event('resize'));

However, there must be a way to handle this in the slider component.

from react-slider.

qwtel avatar qwtel commented on June 12, 2024

Hi,

I've run into this problem myself, unfortunately I haven't really come up with a good solution.

I thought about calculating the slider/handle sizes on each render, but since it triggers a browser reflow this is prohibitive from a performance standpoint.

Maybe calculating the sizes only on touch/mouse start would be a compromise.

Your thoughts?

from react-slider.

DustinHigginbotham avatar DustinHigginbotham commented on June 12, 2024

That may be a pretty good idea. If it happens fast enough, the user wouldn't notice.

Worst comes to worst, should there be a more public way of saying "hey, I'm visible now" kind of like what I am doing in my work-around.

from react-slider.

qwtel avatar qwtel commented on June 12, 2024

I've experimentally implemented the idea, but of course it doesn't solve the problem as touch/mouse start don't get called when the element becomes visible.

From a quick google search it seems like there is no clean way to detect visibility changes, so it seems manually calling _handleResize is the "most correct" solution anyway (judging form this answer to a similar stackoverflow question)

from react-slider.

DustinHigginbotham avatar DustinHigginbotham commented on June 12, 2024

But the touch/mouse events won't trigger unless the element is visible anyway. In theory, when mousedown happens, it could essentially run _handleResize assuming that it has visibility. If nothing less, it could check to see if getBoundingClientRect has returned all zeros and have it check again.

Do you fear that by the time mousedown happens, it would be too late to do all of these things?

from react-slider.

qwtel avatar qwtel commented on June 12, 2024

The problem is that the sizes are also used for positioning the handles. This means that when you make the slider visible, all the handles are still positioned at 0. Once you start dragging one of them they all "jump" to their correct position.

Performance isn't the problem.

from react-slider.

qwtel avatar qwtel commented on June 12, 2024

You could also call _handleResize on the component, but it feels a bit "hacky" as well.

It all has to do with the fact that we use absolute pixel values for the handle positions, which can not be calculated before the size of the slider is known.

For the next version of the slider I have planned to position the handles on a percentage basis, which would also allow the slider to pre-render on the server. However, it will require the users to "center" the handles themselves (i.e. when your handle is 50px in width, give it a margin-left: -25px), because we also can't know the size of the handle before it is rendered.

from react-slider.

veewee avatar veewee commented on June 12, 2024

Great! I am looking forward to the next version :)

from react-slider.

ccitro avatar ccitro commented on June 12, 2024

I ran into this issue myself, and I submitted a pull request for how I've solved it for my use cases.

For me, checking if upperBound is 0 in componentWillReceiveProps works because my props will always change after the slider becomes visible. It won't fix all cases, but it doesn't add any overhead and fixes it as long as your props change.

Merge if you think it'd be helpful, and thanks for the slider.

from react-slider.

whroman avatar whroman commented on June 12, 2024

The above-mentioned merge was not helping me in the same situation of having a slider be hidden when the app first loads. I managed to fix this in a fork of react-slider where I wrapped the logic within _handleResize with a setTimeout of 0. I have submitted a PR for this change at #38.

from react-slider.

AndrewRayCode avatar AndrewRayCode commented on June 12, 2024

Why not make the css left a % based, so you never have to worry about size? this is biting me because the slider appears on a page with one layout, then a reflow happens and the slider changes size, but it still thinks its the original size

from react-slider.

qwtel avatar qwtel commented on June 12, 2024

Yes I was thinking about making left %-based (see my earlier post), but I haven't come around to implementing it yet.

Also, it's not as simple as I've originally thought. Setting the left property on every touchmove (as it is now) is not such a good idea, because it's causing layout, paint and composite for every new value. Using the pixel-based transform would only cause composite.
I'm not sure how much will-change: left is helping with that, but certainly not much for browsers that don't support it.

So ideally I would have left be %-based during normal rendering, but trasform and pixel-based while sliding, which is more complicated than just switching to %-based values.

from react-slider.

7rulnik avatar 7rulnik commented on June 12, 2024

I also have a component that is hidden on initial load. I replaced display: none by visibilty: hidden. It works.

from react-slider.

stale avatar stale commented on June 12, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from react-slider.

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.