Skip to content
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

Allow selected_index=none in selection container widgets #1495

Merged

Conversation

pbugnion
Copy link
Member

@pbugnion pbugnion commented Jul 11, 2017

Prior to this commit, the way to unset the selection for a tab or accordion widget was to set selected_index = -1. Having to set it to None would be better (see issue #1493 ).

This PR allows setting the index to None. The bulk of the changes are in the Selection class, which now allows setting the index to null.

This is what's left to do:

  • explicitly disable setting selected_index to an out of range value
  • unit tests for Selection class
  • amend docs

This is now ready for review.

@pbugnion
Copy link
Member Author

screen shot 2017-07-11 at 07 30 17

@pbugnion pbugnion force-pushed the selection-container-allow-none branch from f3806bc to b6ec556 Compare July 11, 2017 07:04
@jasongrout jasongrout added this to the 7.0 milestone Jul 11, 2017
@pbugnion pbugnion changed the title [WIP] Allow selected_index=none in selection container widgets Allow selected_index=none in selection container widgets Jul 13, 2017
@pbugnion pbugnion force-pushed the selection-container-allow-none branch from 7494306 to 88ba725 Compare July 13, 2017 07:02
@@ -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`.
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.

@@ -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;
Copy link
Member

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.

@jasongrout jasongrout merged commit 05dd4e4 into jupyter-widgets:master Jul 15, 2017
@jasongrout
Copy link
Member

Thanks!

@github-actions github-actions bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Feb 12, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants