-
Notifications
You must be signed in to change notification settings - Fork 949
Allow selected_index=none
in selection container widgets
#1495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 22 commits
0376350
9b371aa
b6ec556
1f77604
f481d54
52d8e26
98e48b6
88e4182
1a4a019
465c1dd
a184d23
89238bb
8bd2304
e170bb2
04c10b0
eac8ae4
e5b298c
59fcdb4
88ba725
c31ac16
a2af8b5
cc0d435
34dd60a
95cc187
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
from unittest import TestCase | ||
|
||
from traitlets import TraitError | ||
|
||
from ipywidgets.widgets import Accordion, HTML | ||
|
||
|
||
class TestAccordion(TestCase): | ||
|
||
def setUp(self): | ||
self.children = [HTML('0'), HTML('1')] | ||
|
||
def test_selected_index_none(self): | ||
accordion = Accordion(self.children, selected_index=None) | ||
state = accordion.get_state() | ||
assert state['selected_index'] is None | ||
|
||
def test_selected_index(self): | ||
accordion = Accordion(self.children, selected_index=1) | ||
state = accordion.get_state() | ||
assert state['selected_index'] == 1 | ||
|
||
def test_selected_index_out_of_bounds(self): | ||
with self.assertRaises(TraitError): | ||
Accordion(self.children, selected_index=-1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,7 +120,7 @@ class TabPanel extends Widget { | |
* Get the index of the currently selected tab. | ||
* | ||
* #### Notes | ||
* This will be `-1` if no tab is selected. | ||
* This will be `null` if no tab is selected. | ||
*/ | ||
get currentIndex(): number { | ||
return this.tabBar.currentIndex; | ||
|
@@ -130,7 +130,7 @@ class TabPanel extends Widget { | |
* Set the index of the currently selected tab. | ||
* | ||
* #### Notes | ||
* If the index is out of range, it will be set to `-1`. | ||
* If the index is out of range, it will be set to `null`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the logic here is still missing for out of range values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, you don't need to do anything here - the tab bar handles the logic to set its current index to -1 if out of range. We'll just handle the translation to null up where we retrieve the index. |
||
*/ | ||
set currentIndex(value: number) { | ||
this.tabBar.currentIndex = value; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic needs to be added here to return null if the tab bar index is -1.