diff --git a/panel/tests/ui/widgets/test_sliders.py b/panel/tests/ui/widgets/test_sliders.py index a7a14982bf..5845d2ede2 100644 --- a/panel/tests/ui/widgets/test_sliders.py +++ b/panel/tests/ui/widgets/test_sliders.py @@ -5,6 +5,7 @@ from panel.tests.util import serve_component, wait_until from panel.widgets import ( EditableFloatSlider, EditableIntSlider, EditableRangeSlider, + IntRangeSlider, ) @@ -297,3 +298,18 @@ def test_editablerangeslider_no_overlap(page): down_end.click(click_count=3) wait_until(lambda: widget.value == (1, 1), page) + + +def test_intrangeslider(page): + # Test for https://github.com/holoviz/panel/issues/6483 + # Which has floating point error, e.g., 4 will return + # 3.9999999999999996, so we can't use int() in our code + # but needs to use round() instead. + widget = IntRangeSlider(start=1, end=10, step=1) + serve_component(page, widget) + + page.locator(".noUi-touch-area").nth(0).click() + for _ in range(3): + page.keyboard.press("ArrowRight") + + wait_until(lambda: widget.value == (4, 10), page) diff --git a/panel/widgets/slider.py b/panel/widgets/slider.py index f0679f1cb1..159b4c8ecf 100644 --- a/panel/widgets/slider.py +++ b/panel/widgets/slider.py @@ -646,10 +646,10 @@ class IntRangeSlider(RangeSlider): def _process_property_change(self, msg): msg = super()._process_property_change(msg) if 'value' in msg: - msg['value'] = tuple([v if v is None else int(v) + msg['value'] = tuple([v if v is None else round(v) for v in msg['value']]) if 'value_throttled' in msg: - msg['value_throttled'] = tuple([v if v is None else int(v) + msg['value_throttled'] = tuple([v if v is None else round(v) for v in msg['value_throttled']]) return msg