aschemschat / range-slider

A range-slider-component for Vaadin 8
Apache License 2.0
0 stars 1 forks source link

Add a no-argument constructor for the RangeSlider #3

Closed veronicarose closed 5 years ago

veronicarose commented 5 years ago

A no-argument constructor is needed for Vaadin to auto-bind an html element with a Java component. The default RangeSlider is created with a (0, 0) Range.

aschemschat commented 5 years ago

Hi, thanks for the PR :) i have some changes i haven't pushed (and maybe will reset), but i will have a look at this and release a new version in any case :)

aschemschat commented 5 years ago

I've added your changes and two other minor points and released it as 1.1.1. The changes are now in the vaadin-addons-repo. Let me know if there are some issues :)

veronicarose commented 5 years ago

Great, thanks! Does a slider resize when you set the Range with setBoundaries()? It seems like once one is created with Boundaries of (0, 0), it never resizes to anything longer, so it just looks like a slider with the two numbers on top of each other. The setting code looks like: theStrikeRangeSlider.setBoundaries(100, 4000); theStrikeRangeSlider.setStep(50); theStrikeRangeSlider.setTooltips(RangeSliderState.Tooltips.ON_FOCUS); screen shot 2019-02-27 at 1 11 19 pm

aschemschat commented 5 years ago

Hm, i will have a look at that tomorrow. Maybe the underlying js-plugin calculates the width based on the distance of the boundaries and a difference of 0 messes the calculation up. If thats the case an initial boundary of 0,1 might help.

veronicarose commented 5 years ago

My thoughts exactly. Thanks and let me know if you need me to make the change and submit another PR.

aschemschat commented 5 years ago

As suspected. If i enter a boundary with a difference of 0, the width is set to 0. But if i change the boundaries at any step (directly afterwards or with the controls in the demo) the slider is resized to its available width again. As i discovered, the component must have a width defined however. If i don't set any width to the slider (percent or pixel), the slider is always displayed like your screenshot above. I will add that to the readme :). Did you define a width for your strikeRangeSlider?

So, now i'm wondering how to fix this. Restricting the boundaries to lower < greater is not an option, because in the case i'm using it for the lower and upper boundary is calculated based on a prefiltered dataset and they might be the same. Disabling the input and faking a difference of 1 might be an option, but that might yield a whole set of other problems. Currently im leaning towards adding a warning in the readme and leaving it at that, if you can solve your width-problem by adding a width to the component.

veronicarose commented 5 years ago

Hm I do have the width set before I reset the boundaries. I have tried both setting the width as a percentage in the html and calling: theStrikeRangeSlider.setWidth("30%"); or theStrikeRangeSlider.setWidth("30em"); before doing setBoundaries() and neither allows the slider to resize. It always stays as a 0 width.

I also tried setting the value with setValue() after changing the boundaries and that doesn't resize it either.

aschemschat commented 5 years ago

Could you reproduce the error in a small sample-project? And which Vaadin-Version are you using? To test if its really the boundary you could subclass the RangeSlider and add another default-constructor with a larger boundary.

veronicarose commented 5 years ago

Hi, sorry it took me so long to get back. I confirmed that by subclassing the RangeSlider and setting the Range to (0, 1) in the overridden constructor, I know longer see the resizing failure. But, I continued to do some experimenting and found that you are correct: the (0,0) range is not the problem. I was setting the width of the RangeSlider in the html width field, and for some reason, the width only resizes correctly when I set it using "em" and not when I set it using "%". I can't explain why this is, but for me it works to just set the width explicitly with "em," so I don't need any follow-up from you! Thank you (and great tool by the way :))

aschemschat commented 5 years ago

Maybe the outer element doesn't have a fixed width so its something like " X percent of -1 -> 0" (had that problem a few times myself :D). But i have no idea, if that would work, if the difference is one at the beginning. Anyways, thanks and glad it works now :) Let me know, if you have any other suggestions.