Comments (14)
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.
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.
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.
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.
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.
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.
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.
Great! I am looking forward to the next version :)
from react-slider.
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.
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.
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.
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.
I also have a component that is hidden on initial load. I replaced display: none
by visibilty: hidden
. It works.
from react-slider.
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)
- React 18.3: A props object containing a "key" prop is being spread into JSX HOT 4
- First click on track doesn't work when slider value is array and array values is equal
- Typescript issue HOT 1
- Possible to use a gradient as background for the slider? HOT 1
- Feature request: provide a way of detecting when react-slider has/loses focus HOT 2
- The specified value "1,669" cannot be parsed, or is out of range. HOT 1
- disabled does not apply to child elements?
- [TypeScript] `renderThumb`
- Module not found: Error: Can't resolve '@babel/runtime/helpers/inheritsLoose' HOT 4
- How to handle key events when I have global listeners? HOT 2
- Thumb Incorrect positioning HOT 1
- Slider not changing value when running Cypress tests HOT 3
- Wrong index in change event when changing thumb value through click
- No option to remove the slider thumb from the 'tab flow' HOT 1
- README.md file should be updated for how to use the packege HOT 2
- Missing dependency: @babel/runtime HOT 1
- Styling instructions are out of date
- Not working on Scaled Div
- Possible Incorrect State Management
- Incompatibility with React Testing Library
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-slider.