Skip to content

Commit d1c018e

Browse files
committed
Fix a regression in #1513 with creating selection range sliders.
The following was broken: from ipywidgets import SelectionRangeSlider s=SelectionRangeSlider(options=[1])
1 parent 587b1b6 commit d1c018e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

ipywidgets/widgets/widget_selection.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _validate_options(self, proposal):
117117

118118
@observe('options')
119119
def _propagate_options(self, change):
120-
"Set the values and labels, and unselect any option if we aren't initializing"
120+
"Set the values and labels, and select the first option if we aren't initializing"
121121
options = self._options_full
122122
self.set_trait('_options_labels', tuple(i[0] for i in options))
123123
self._options_values = tuple(i[1] for i in options)
@@ -391,6 +391,15 @@ def _validate_options(self, proposal):
391391
raise TraitError("Option list must be nonempty")
392392
return proposal.value
393393

394+
@observe('options')
395+
def _propagate_options(self, change):
396+
"Select the first option"
397+
options = self._options_full
398+
self.set_trait('_options_labels', tuple(i[0] for i in options))
399+
self._options_values = tuple(i[1] for i in options)
400+
if self._initializing_traits_ is not True:
401+
self.index = (0, 0)
402+
394403
@register
395404
class SelectionSlider(_SelectionNonempty):
396405
"""Slider to select a single item from a list or dictionary."""
@@ -415,13 +424,6 @@ class SelectionRangeSlider(_MultipleSelectionNonempty):
415424
label = Tuple(help="Min and max selected labels")
416425
index = Tuple((0,0), help="Min and max selected indices").tag(sync=True)
417426

418-
@observe('options')
419-
def _propagate_options(self, change):
420-
"Unselect any option"
421-
if self._initializing_traits_ is not True:
422-
self.index = (0, 0)
423-
self.set_trait('_options_labels', tuple(i[0] for i in change.new))
424-
self._options_values = tuple(i[1] for i in change.new)
425427

426428
@validate('index')
427429
def _validate_index(self, proposal):

0 commit comments

Comments
 (0)