Code Monkey home page Code Monkey logo

custom-vue-range-slider's Introduction

custom-slider-vue

This template should help get you started developing with Vue 3 in Vite.

Recommended IDE Setup

VSCode + Volar (and disable Vetur) + TypeScript Vue Plugin (Volar).

Customize configuration

See Vite Configuration Reference.

Project Setup

npm install

Compile and Hot-Reload for Development

npm run dev

Compile and Minify for Production

npm run build

custom-vue-range-slider's People

Contributors

miracleonyenma avatar

Stargazers

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

Watchers

 avatar  avatar

custom-vue-range-slider's Issues

Slider min-max validations missing

Hi - I came across your component shared on a blog and I was planning to use something similar.
Currently, I do not see validations ensuring slider max is always greater than slider min - or in other words preventing to slider min to be more than slider max.
Were you planning to add it to your component by any chance ? @miracleonyenma

onInput issues

I would like to report a couple of issues in function onInput in following file:

const onInput = ({ target }) => {

  1. the first improvement I would suggest is to introduce separate functions for min and max slider. there is no point in checking the name of the slider. You only have 2 of them, so you could just split the function into 2. This is merely a performance concern and not a very substantial one.
const onInputMin = ({ target }) => { //
}

const onInputMax = ({ target }) => { //
}
  1. Secondly, why do you set the value that is equal to a value of another slider?
    target.value > sliderMaxValue.value ? target.value = sliderMaxValue.value : sliderMinValue.value = parseFloat(target.value);

per my understanding, it should not be a default behavior anyways even if it should be possible to do. The value of the opposing slider should be x +- 1. For min slider the value should be max slider -1, for max slider the minimum value should be min slier value +1.

    target.value >= sliderMaxValue.value  // see >=
      ? target.value = sliderMaxValue.value - 1 // see - 1 (for the other slider we set the +1
      : sliderMinValue.value = parseFloat(target.value);
  1. lastly I would like to address the issue that the code does not make sense. The value should be set ALWAYS, regardless of the new value. There should be no "Else" statement. You can try to move the slider extremely fast, physically. then at some point you will notice that the range will not be set correctly. that is because of the else condition that you've set.

ideally it should be:

if (target.value >= sliderMaxValue.value){
target.value = sliderMaxValue.value - 1
}
sliderMinValue.value = parseFloat(target.value); // always set the value! no ELSE!
  1. Lastly I also got rid of the parseFloat, not sure if this should be reported as a "problem", but I could not think of a use-case for this. The value is always returned as the integer. isn't it so? So at what point do we need to have a floating point conversion? This is the second performance concern. It should not influence the logic in any way.

Regardless if you agree with all suggested edits and proposals or not, here is the version of the code that I am using for my needs:

const onInputMin = ({ target }) => {
  if (target.value >= sliderMaxValue.value) {
    target.value = sliderMaxValue.value - 1
  }

  sliderMinValue.value = target.value
}

const onInputMax = ({ target }) => {
  if (target.value <= sliderMinValue.value) {
    target.value = sliderMinValue.value + 1
  }

  sliderMaxValue.value = target.value
}

Thank you very much for your solution! it works much faster than hand-made divs that act like range sliders. Soon as I added 2000 of range sliders your solution works just almost as good as 1 range slider. Whereas the custom made slider is laggy as hell and wants to obliterate my PC every second :)

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.