Git Product home page Git Product logo

react-bootstrap-slider's Introduction

DEPRECATED ⛔️

I no longer have the time to maintain this project. If anybody else wants to take on ownership and maintenance then I'd be happy to hand it over, although I've no idea how one actually does that!

React Bootstrap Slider

This project was bootstrapped with Create React App. It was then ejected due to jQuery issue (see below).

Overview

A ReactJS wrapper for seiyria's Bootstrap Slider component using Bootstrap. From version 3.0.0, we are supporting Bootstrap 4 only. Please use version 2.2.3 if you are still using Bootstrap 3.

How to install

Install from npm with:

npm install --save react-bootstrap-slider

or

yarn add react-bootstrap-slider

Import like so for ES6:

import ReactBootstrapSlider from 'react-bootstrap-slider';

The control is implemented in UMD format, so should also work for AMD/RequireJS, but I've not tested that.

Peer Dependencies

React, React Dom and Bootstrap are listed as peer dependencies (peerDependencies section in package.json) for react-bootstrap-slider. They will not be installed automatically when you install this component into your own project. You will need to install them yourself, as part of that project, if you have not done so already. This command will install them for you if you don't yet have them:

npm install react react-dom prop-types bootstrap@^4 --save

or

yarn add react react-dom prop-types bootstrap@^4

jQuery

The bootstrap-slider component - and, therefore, react-bootstrap-slider - will work with jQuery if it detects it in your project setup, but it is not a requirement. It works fine without jQuery. However, if you are using Webpack or Browserify to build your project, you may get a "missing dependency" build error if jQuery is not present. This is a known, upstream issue in bootstrap-slider. Please see How do I exclude the optional JQuery dependency from my build? on the Bootstrap Slider's Readme for how you can workaround this issue. You can also see how I did it by inspecting the /examples/config/webpack.config.js file and searching for "jQuery".

You must also ensure that you have included bootstrap-slider's CSS file in your build, otherwise the control will be blank! You'll also need Bootstrap's own CSS file too, of course. If you're using Webpack, which you will be if you have a Create React App based project, then you can import the CSS file directly into your build, like so:

import "bootstrap/dist/css/bootstrap.css";
import "bootstrap-slider/dist/css/bootstrap-slider.css"

Those two imports need to be in your top-level JavaScript file, e.g. App.js.

Or you can simply add the files as links in your HTML file as a link e.g.:

<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" />
    <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/11.0.2/bootstrap-slider.min.js"></script>

checking that the versions match those of Bootstrap and Bootsrap Slider themselves.

How to use react-bootstrap-slider

Here's an example of how you might call it in your ReactJS's render method:

<ReactBootstrapSlider
    value={this.state.currentValue}
    change={this.changeValue}
    slideStop={this.changeValue}
    step={this.state.step}
    max={this.state.max}
    min={this.state.min}
    orientation="vertical"
    reversed={true}
    disabled="disabled" />

The value, step, max and min parameters should be self-explanatory. The change event is the callback method that will be called when the slider actually changes. (NB: this is the change event for the Bootstrap slider.) As of version 1.1.2, there is a new slideStop event, which only triggers when you've finished moving the slider (i.e. you release it). This makes slideStop a deal less "chatty" than the change event. Decide which one you need; you'll only ever need one or the other (unlike my example code above!).

If the optional parameter disabled is included, and is set to "disabled", then the slider will display in a disabled state. If the parameter is not included, or is set to anything else except "disabled", then the slider control will be enabled.

The default orientation value is 'horizontal', so you only need to include that prop if you want to set it to 'vertical'.

If value is a two member array, then the slider will have two handles: minimum and maximum. You should also pass win a range parameter set to true in this case.

As of version 1.0.5, other values passed into the component will also passed into the underlying bootstrap-slider component via the Object Spread Operator that's been proposed for ES2017 (yes, that's how cutting edge I am!!). See seyria's documentation for a full list of these. Those parameters have not all been tested yet but the reversed parameter definitely works, and I have included this in the demo of the vertical slider.

Version 1.0.6 fixed an issue that prevented ticks props from being rendered. Pass in ticks props like so:

ticks = {[0, 100, 200, 300, 400]}
ticks_labels = {["$0", "$100", "$200", "$300", "$400"]}
ticks_snap_bounds = { 30 }

react-bootstrap-slider's People

Contributors

brownieboy avatar davemo avatar dbendit avatar evelan avatar fabioespinosa avatar jewelsjacobs avatar joncppl avatar kevbelisle avatar saevarom avatar saxicek avatar talater avatar yefim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-bootstrap-slider's Issues

slider does not appear

Hi, I have followed the guide to install the slider, but when I write

<ReactBootstrapSlider value={this.state.currentValue} handleChange={this.changeValue} step={this.state.step} max={this.state.max} min={this.state.min} orientation="vertical" reverse={true} disabled="disabled" />

in my render function, simply it does not appear?
Why?
Thanks

max doesn't get updated if first set to 0

That is, if the first time the component has been mounted with max={0}, later changes doesn't take effect. This can be inferred from this block of code:

        if (
            this.props.max &&
            (this.mySlider.max || this.mySlider.options.max)
        ) {
            this.mySlider.setAttribute("max", this.props.max);
        }

From what I can gather, this.mySlider.max is never set to anything. The only place for max to be set to 0 is componentDidMount. And if that happens, max can't be changed anymore.

But if the first value is null, it works out.

Judging from commit names it has something to do with ticks, but I don't see the connection.

disabled state

i don't know it this is desired but its weird

the disabled state works correctly (becomes gray) but instead of a circle the drag icon is a square
i think it should be a gray circle

Min and max in same slider: value="[250,450]"

Hi, in the docs of seiyria I can read that there is an option to place two dots in the slider, by setting the value by an array..

Unfortunately, I am unable to get this to work.. Is this supported?

I get the following error: Uncaught TypeError: num.toFixed is not a function

tooltip prop doesn't take effect

Passing in the tooltip prop doesn't change the value shown in the tooltip.

Expected: tooltip should show 'foobar'
Actual: tooltip shows the numerical value of the slider's position

This important for adding a label to the numeric value (10+ or $10).

        <ReactBootstrapSlider
          value={this.state.currentVal}
          slideStop={this.handleChange}
          step={this.state.step}
          min={this.state.min}
          max={this.state.max}
          tooltip={'foobar'} />

Thanks for making this!

API weirdness

Hi,

first of all, thanks for your project, it's cool 😄

But I find that the API is a bit different from what is currently seen:

  • disabled taking a string is quite unconventional, and leads to unnecessary ternary operations
  • change and slideStop: events callback names usually start with on to tell they expect callbacks, like onChange, onClick etc

Just my 2cts,
have a great day

Width of slider

Is there any way to pass in props to ReactBootstrapSlider so that width is no longer fixed to 210px? Thanks!

Errors: Uncaught Invariant Violation

Hi,

when I try to use the component in my render method i get multiple errors:

  • Warning: React.createElement: type should not be null...
  • Uncaught Invariant Violation: Element type is invalid...
  • Uncaught TypeError: Cannot read property '__reactInternalInstance$ctfhri5urwdsvbrkifzeka9k9' of null

I have no clue what I am doing wrong or what might be causing the failure.

Version 1.0.1 and up fails if babel-cli is not installed globally

> [email protected] postinstall /home/jan/src/snap/frontend/app/node_modules/react-bootstrap-native-slider/node_modules/react-bootstrap-slider
> npm run buildDemo

-
> [email protected] buildDemo /home/jan/src/snap/frontend/app/node_modules/react-bootstrap-native-slider/node_modules/react-bootstrap-slider
> npm run build && webpack

/
> [email protected] build /home/jan/src/snap/frontend/app/node_modules/react-bootstrap-native-slider/node_modules/react-bootstrap-slider
> babel ./src/js/react-bootstrap-slider.jsx -o ./dist/react-bootstrap-slider.js

sh: 1: babel: not found

The commands in postinstall should be ./node_modules/.bin/babel or similar.

As an addendum, is there are reason to re-build on postInstall? The published package is already built

Does react-bootstrap-slider support slider ticks?

Hi,
Bootstrap slider supports slider ticks and label as shown in examples #13
Example usage is like:
<input id="ex13" type="text" data-slider-ticks="[0, 100, 200, 300, 400]" data-slider-ticks-snap-bounds="30" data-slider-ticks-labels='["$0", "$100", "$200", "$300", "$400"]'/>

Does react-bootstrap-slider support it? If not, is there any plan to add it?

Thanks

CSS not built in dist js file.

The slider isn't display for me using 1.0.6. No styles appear to be getting loaded? @brownieboy

    <ReactBootstrapSlider
                value={100}
                handleChange={() => {}}
                step={[]}
                max={100}
                min={0}
                orientation="horizontal"
                reverse={false}
                disabled={false} />

Request that "range" attribute be updated in updateSliderValues()

In some cases, my slider is targeted by another type of selector. Based on the targeting selector, the slider can switch between having one handle and two handles. The value is correctly updated in updateSliderValues(), but the range attribute is not. This causes a Uncaught TypeError: num.toFixed is not a function when num is an array. Adding something like this to updateSliderValues() seems to fix the problem:

if (this.props.range !== this.mySlider.options.range) {
   this.mySlider.setAttribute("range", this.props.range);
}

Is this something you would be willing to change? Thanks!

react-bootstrap-slider requires react^16.0.0

Ever since react-bootstrap-slider v2.1.1, the package requires react^16.0.0 to be installed as a peer dependency. Is this actually the case? It seems to work fine even though I'm using react 15.6.1.

Remove slider attributes logging

It would be nice if the sliderAttributes logging that's done on creation could be removed. It causes some spam when testing and debugging.

It's in dist\react-bootstrap-slider.js on line 122.

console.log("sliderAttributes = " + JSON.stringify(sliderAttributes, null, 4));

It produces output like...

sliderAttributes = {
          "id": "size-slider",
          "value": 1,
          "step": 1,
          "max": 5,
          "min": 1,
          "tooltip": "show"
      }

Uncaught Error: Invalid input value '2000' passed in

Hi,

For testpurposes I use the following react:

<ReactBootstrapSlider value='2000' step='1000' max='20000' min='1000' handleChange='' />

But I constantly get the following console error, where my slider is not displaying:

Uncaught Error: Invalid input value '2000' passed in 

Can anyone help?

Failed to recognize change in props.

My application requires that the range for the slider change based on the state of the application.

Specifically I'm changing the integer value of the prop 'max' between 10 and 25 depending on my application's state.

                <Slider
                  value={scale}
                  max={cut ? 10 : 25}
                  min={2}
                  step={1}
                  slideStop={e => updateScale(e.target.value)}
                />

However, the slider doesn't update for this change.

I quickly fiddled with the code in the library and found that removing the if statement around

                if (this.mySlider.max) {
                    this.mySlider.setAttribute("max", this.props.max);
                }

fixes the issue and it updates as I would expect. (It seems that this.mySlider doesn't have the property max)

Am I doing something wrong, or does this library need to updated?

TypeError: Cannot read property 'slider' of undefined

Hi,

I need help here. I got the following error when using this plugin.

TypeError: Cannot read property 'slider' of undefined
   at /Applications/XAMPP/xamppfiles/htdocs/kumparan-cms-jared/node_modules/bootstrap-slider/dist/bootstrap-slider.js:1676:14
   at /Applications/XAMPP/xamppfiles/htdocs/kumparan-cms-jared/node_modules/bootstrap-slider/dist/bootstrap-slider.js:1691:6
   at /Applications/XAMPP/xamppfiles/htdocs/kumparan-cms-jared/node_modules/bootstrap-slider/dist/bootstrap-slider.js:1693:4
   at NAMESPACE_MAIN (/Applications/XAMPP/xamppfiles/htdocs/kumparan-cms-jared/node_modules/bootstrap-slider/dist/bootstrap-slider.js:51:20)
   at Object.<anonymous> (/Applications/XAMPP/xamppfiles/htdocs/kumparan-cms-jared/node_modules/bootstrap-slider/dist/bootstrap-slider.js:55:3)
   at Module._compile (module.js:541:32)
   at Module._extensions..js (module.js:550:10)
   at Object.require.extensions.(anonymous function) [as .js] (/Applications/XAMPP/xamppfiles/htdocs/kumparan-cms-jared/node_modules/babel-register/lib/node.js:154:7)
   at Module.load (module.js:458:32)
   at tryModuleLoad (module.js:417:12)

Can you help me to solve this? Thanks

Tooltips no longer function with Bootstrap 4

I am in the process of upgrading Bootstrap from 3.3.7 to 4.0.

Apparently the new version uses Tether for tooltips, which I believe I have added to my version of Bootstrap.

For whatever reason the system used in react-bootstrap-slider no longer displays after the upgrade.

Just a heads up.

I've tried with both ver 1.1.7 and 2.0.0 of react-bootstrap-slider.

Slider appears in conditional code

I have a render call which only generates the slider element in an else clause.
However as soon as I render my component a slider appears on my screen, and every time the render is retriggered (due to state updates etc) an extra slider appears.

Not working in a reactstrap popover

Scenario:
Create any type of slider in a reactstrap popover (https://reactstrap.github.io/components/popovers/)

<Button id="Popover1" onClick={this.togglePopover}>
    Launch Popover
</Button>
<Popover placement="bottom" isOpen={this.state.popoverOpen} target="DateSliderPopoverTrigger">
    <PopoverTitle>Some title</PopoverTitle>
    <PopoverContent>
        <ReactBootstrapSlider
            step={step}
            max={max}
            min={min}
            orientation={orientation}
            {...rest}
        />
    </PopoverContent>
</Popover>

Expected: Slider works normally in a popover
Actual: Slider cannot be moved.

Have not investigated why this is happening, it is my conjecture that it's unwanted interference from the combination of components/events. Either an event stopped earlier or a z-index issue?

Slider orientation

Hi, i'd like to use the slider in vertical mode.
I tried to insert a data attribute "data-slider-orientation", since it is not provided in the component orientation property, but without success.

There is another way?
Thanks

Add option to handle change on mouse up

Right now, if you hold your mouse and drag, handleChange gets called on every single mouse movement. This causes some performance issues, as well as janky behaviour if you don't debounce the handleChange callback, especially with multiple values.

Proposal: Call handle change on mouse up as opposed to on every single movement

CSS missing from dist/

Hi,

not sure how it's suppose to work, but the docs mention bootstrap-slider/dist/css/bootstrap-slider.min.css which doesn't exist if I install it from npm.

Set attributes dynamically

Is there a way to set or add attributes dynamically? For example, like after the slideStop event? Thanks!

reports directory is included in the Node package

A redundant 628K worth of files are packed into the react-bootstrap-slider package.
Total package size is then 668K instead of merely 12K.

The 'reports' directory should be added to .npmignore file.

$ tree /home/user/my_project/node_modules/react-bootstrap-slider
/home/user/my_project/node_modules/react-bootstrap-slider
├── dist
│   └── react-bootstrap-slider.js
├── package.json
├── README.md
└── reports
    ├── 12de2320923d89385cd9c19ef5364683.png
    ├── 15e45c5845494a1b3ef2d42bb180aba0.png
    ├── 188933ca5b8a2e29a5ceb3ef0c3b8c52.png
    ├── 2c61e214712abaa8ca0ea69241ea6499.png
    ├── 405ff6658abbfab36ca8d058d39f3f1a.png
    ├── 45c30c6c731e4071271e4cf525397693.png
    ├── 674c4aa3ffb3ee8cf85e19fd2967a5a8.png
    ├── 7035d2cb768e8e81e6da350e0d44c1e3.png
    ├── 7e2aa5da2c9f15a29b6618ed28a82011.png
    ├── 8c664432d76ac66e83d7e89335a36a49.png
    ├── b2c2f9e31436003c983795ce330ab0f5.png
    ├── bf6e35089833c197518c5098adac6319.png
    ├── c890ffc5b59d797375f27ed841fbf26d.png
    ├── eeac8a48b0927c84a7b2f5768234a793.png
    └── index.html

2 directories, 18 files
tomer@Kubuntu:~$ du -h /home/user/my_project/node_modules/react-bootstrap-slider
12K     /home/user/my_project/node_modules/react-bootstrap-slider/dist
628K    /home/user/my_project/node_modules/react-bootstrap-slider/reports
668K    /home/user/my_project/node_modules/react-bootstrap-slider

Tooltip positioning error

screen shot 2016-05-18 at 14 21 39

On first render i'm seeing the tooltip floating too far to the right. If I use the https://github.com/seiyria/bootstrap-slider directly in a setTimeout() during the onComponentDidMount method it renders in the right place. I'm willing to bet calling relayout would fix the tooltip.

As soon as I click/drag the slider the tooltip re-renders the tooltip in the right position

jQuery dependency

There appears to be some problem with 1.1.6 dependency on jquery. I got the following error when installing.

Failed to compile.

Error in ./~/bootstrap-slider/dist/bootstrap-slider.js
Module not found: 'jquery' in /Users/me/myproj/node_modules/bootstrap-slider/dist

 @ ./~/bootstrap-slider/dist/bootstrap-slider.js 56:2-29

Manually adding jQuery to the project fixed the issue. Although, doing that installed [email protected] on my system.

Not sure if this is a Yarn/NPM problem or a ReactBootstrapSlider problem.

Using slider as form input

In seiyria's Bootstrap Slider other attributes can be supplied using the API format, for example name:

<input
type="text"
id="id-01"
name="somename"
data-provide="slider"
data-slider-ticks="[1, 2, 3]"
data-slider-min="1"
data-slider-max="3"
data-slider-step="1"
data-slider-value="3"
>

If using the component as a form input field, is there a way to send an id and/or name attribute so that it is attached to the input rather than the div?

The above example is then displayed in the code as:
<input type="text" id="id-01" name="somename" data-provide="slider" data-slider-ticks="[1, 2, 3]" data-slider-min="1" data-slider-max="3" data-slider-step="1" data-slider-value="3" data-value="1" value="1" style="display: none;">

Readme lacks information to use bootstrap-slider.min.css

I spent quite some time trying to understand why the component is not visible in my project.
Eventually I figured I should use the following code in app.js:

import BootstrapSlider from 'bootstrap-slider/dist/css/bootstrap-slider.min.css';

Or in index.html:

<link rel="stylesheet" href="bootstrap-slider/dist/css/bootstrap-slider.min.css" />

Could you please add this information to Readme?

Plan for supporting Bootstrap 4

Hi man. I found your work is extremely useful ;-) However it has some display problem in Bootstrap 4. Also there is some problem in detecting the dragging event. Will you have any plan to upgrade it? Thanks.

Labels are not placed correctly on fisrt load

Hi,
The labels are not correctly placed on load, but if I click somewhere in the component it fixes. I don't know if I'm missing something..

So, the code is:
<ReactBootstrapSlider ticks={[0, 1, 2, 3, 4, 5]} value={[4, 5]} handle="square" ticks_labels={["Set/2018", "Out/2018", "Nov/2018", "Dez/2018", "Jan/2019", "Fev/2019"]} range={true} />

This is when it first loads:
screenshot_4

And the when I click somewhere in the component:
screenshot_5

Slider should be attached to `input` tag

Thanks for creating this.

Currently, ReactBootstrapSlider creates a div tag and attaches the slider to this node.

I would like to propose to change this to an input tag as that's what the Bootstrap Slider does and since this is built upon that library, I think it should keep those assumptions in place.

I will be happy to create a PR for the same.

Slider is affecting other sliders

I try to use multiple sliders with the following setup:

render() {
    return (
        <div>
            <ReactBootstrapSlider
                value={ this.state.value1 }
                change={ (event) => this.changeValue(event, 1) }
                step={ 1 }
                max={ 100 }
                min={ 0 }
                tooltip="always"
                tooltip_position="bottom"
            />
            ...
            <ReactBootstrapSlider
                value={ this.state.value2 }
                change={ (event) => this.changeValue(event, 2) }
                step={ 1 }
                max={ 100 }
                min={ 0 }
                tooltip="always"
                tooltip_position="bottom"
            />
        </div>
    );
}

changeValue(event, type) {
    let value = event.target.value;
    if(type === 1) {
        this.setState({ value1: value });
    }
    else {
        this.setState({ value2: value });
    }
}

Sometimes (not always) if I change slider 1 it changes the value of slider 2 too. The space between the two sliders is big enough so it can't be a miss-click. Is it a Bug or is my setup wrong?

import slider but hidden

Hi, I have imported the slider like in the example:

import ReactBootstrapSlider from 'react-bootstrap-slider';

and I have render it in this way:

<ReactBootstrapSlider value={this.state.currentValue} change={this.changeValue} slideStop={this.changeValue} step={this.state.step} max={this.state.max} min={this.state.min} orientation="vertical" reverse={true} />

but I don't see nothing in my page (I set also the state variables). The html code shows that there is this element, but it is not visibile...why?

Thanks

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.