Skip to content

Commit

Permalink
Handle no selection cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongrout committed Apr 6, 2017
1 parent 0a90140 commit bd50091
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions jupyter-js-widgets/src/widget_selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class DropdownView extends LabeledDOMWidgetView {
this.listbox.disabled = this.model.get('disabled');

// Select the correct element
this.listbox.selectedIndex = this.model.get('index');
let index = this.model.get('index');
this.listbox.selectedIndex = index === null ? -1 : index;
return super.update();
}

Expand All @@ -114,7 +115,7 @@ class DropdownView extends LabeledDOMWidgetView {
* Handle when a new value is selected.
*/
_handle_change() {
this.model.set('index', this.listbox.selectedIndex);
this.model.set('index', this.listbox.selectedIndex === -1 ? null : this.listbox.selectedIndex);
this.touch();
}

Expand Down Expand Up @@ -172,7 +173,8 @@ class SelectView extends LabeledDOMWidgetView {
}

updateSelection() {
this.listbox.selectedIndex = this.model.get('index');
let index = this.model.get('index');
this.listbox.selectedIndex = index === null ? -1 : index;
}

_updateOptions() {
Expand Down

0 comments on commit bd50091

Please sign in to comment.