Giter Site home page Giter Site logo

Comments (7)

sghall avatar sghall commented on June 15, 2024

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.

xinsight avatar xinsight commented on June 15, 2024

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.

sghall avatar sghall commented on June 15, 2024

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.

xinsight avatar xinsight commented on June 15, 2024

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.

sghall avatar sghall commented on June 15, 2024

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.

xinsight avatar xinsight commented on June 15, 2024

<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.

sghall avatar sghall commented on June 15, 2024

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)

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.