Comments (7)
Sorry. Missed this one. Hmmmm...not sure I want to do this. Can you tell me a little more about the use case? I'm just thinking I would set it to some placeholder value with it disabled until I had the actual value(s). Or possibly not show the slider and put some placeholder component until the values are known.
from react-compound-slider.
The use case is to differentiate the slider having a value of zero versus the slider having no value.
For example: If I had a questionnaire that could be partially completed and resumed, I would like the slider to look different if it has never been used to set a value from when it has been used to set the value of 0.
from react-compound-slider.
Oh, I see. Just pass an empty array for the values prop, right? You don't have to pass a value. You can change the way it looks however you want when the array has length zero.
from react-compound-slider.
Ha, I didn't think of trying <Slider values={[]}/>
(i only tried [undefined]
and [null]
).
Ok, so an empty array avoids a warning and defaulting to the max, but it means that the handles array passed from <Handles>
is empty... which makes sense, since by passing an empty array, i'm stating that I don't have any handles... So i need to create a default Handle manually... I can get a static one that never changes - but this is starting to feel quite messy.
<Handles>
{({ handles, getHandleProps }) => (
<div className="slider-handles">
{handles.length === 0 && <Handle handle={{id: 'DEFAULT', value: 0, percent: 0} getHandleProps={()=>{}}}/>}
{handles.map(handle => (
(<Handle
key={handle.id}
handle={handle}
getHandleProps={getHandleProps}
isVertical={isVertical}
disabled={disabled}
/>)
))}
</div>
)}
</Handles>
It would be better if values={[undefined]}
would return a handle of {id, value: NaN, percent: NaN}
(or undefined
instead of NaN
) as then that would be easier to detect and render.
(I'm not supporting multiple sliders, but allowing undefined values would mean that you could have one or more sliders undefined. e.g. values=[50, undefined, 75]
)
tldr; []
has a different meaning than [undefined]
from react-compound-slider.
How about just default the props in the Handle component? Then...
<Handles>
{({ handles, getHandleProps }) => (
<div className="slider-handles">
{handles.length === 0 ? (
<Handle />
) : (
{handles.map(handle => (
(<Handle
key={handle.id}
handle={handle}
getHandleProps={getHandleProps}
isVertical={isVertical}
disabled={disabled}
/>)
))}
)}
</div>
)}
</Handles>
from react-compound-slider.
<Handle />
gives me an error 'cannot call id', so I need to add in the handle object. and then there is an error that getHandleProps is not a function. Once i add that back in, i've got the same as before <Handle handle={{id: 'x'}} getHandleProps={()=>{}}}/>
and then i cannot drag the handle. It looks like I would need a way to set the initial value from dragging the empty <Handle />
and i'm not sure how to do that...
from react-compound-slider.
Just default the props in the Handle component. This is really more of a react question than a question about this library. Hopefully this has got you steered in the right direction.
from react-compound-slider.
Related Issues (20)
- SVG Handle Example? HOT 1
- airbnb slider in pure js or in jquery
- Tutorial step generates TypeError: children is not a function
- Showing rail in varying color based on tick position HOT 2
- Rounding error with domain that contain decimals HOT 1
- Handle id being sorted
- Handling values and step HOT 2
- Cannot read property 'type' of null error in 3.1.0 HOT 2
- the name of Ticks is undefined HOT 2
- Change in step behavior HOT 4
- Step of 0.01 results in too many decimal places in some generated values HOT 2
- Removing the `d3-array` dependency? HOT 2
- Handle tooltips need number formatting HOT 1
- Make Range slider draggable HOT 7
- Custom mode = same min/max value? HOT 1
- Allow slider to work in popup window by registering event listener with Slider's ownerDocument
- Show track with linear gradient?
- Dragging works incorrectly on wide slider with scrolls HOT 1
- How to avoid "jumping" handles?
- GetEventData function return undefined
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-compound-slider.