-
Notifications
You must be signed in to change notification settings - Fork 947
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
Fix selection container default index #1823
Fix selection container default index #1823
Conversation
I think it makes sense for Tab to default to the first item selected. Notice the logic in the selection widgets about choosing a default selection:
We could do something like that. I agree that a default of None for the accordion makes sense. |
4519ca8
to
7a499a6
Compare
OK, I changed the logic to the following:
|
@jasongrout are you ok with this new logic? If yes, I will merge the companion PR in xwidgets. |
@observe('children') | ||
def _observe_children(self, change): | ||
if len(change.new) > 0: | ||
self.selected_index = 0 |
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.
This means that if I keep adding a tab to the end (I think @rmenegaux did this, for example), the selected index keeps being reset to 0.
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.
That is right. Although, we don't have operational transforms on sequences, we change all at once.
Since setting the selected index to None
is not something we want for tabs, this is one way to go.
@@ -29,6 +30,11 @@ def _validated_index(self, proposal): | |||
else: | |||
raise TraitError('Invalid selection: index out of bounds') | |||
|
|||
@observe('children') | |||
def _observe_children(self, change): | |||
if self.selected_index is not None and len(change.new) < self.selected_index: |
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.
This doesn't necessarily select the same child (if we delete a child from the front, now the selected container is not the same), which may be confusing.
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.
same as above
I'm thinking through various scenarios with the current behavior and your new behavior. Two scenarios are:
|
Part of the problem here is that we don't have the notion of inserting or removing a single container - we only have the notion of refreshing the entire children list. When you have more semantic information about what was done (e.g., deleting a tab), you can do something more intelligent like selecting the tab next to it. See, for example, the phosphor insert and remove behavior options at http://phosphorjs.github.io/phosphor/api/widgets/classes/tabbar.html#insertbehavior. |
This new behavior is still better than the current one, which does not handle the case of an empty list (and causes failures in the C++ backend). We could try to check if |
Is there a way to preserve the current behavior for cases where the children list is nonempty, and only insert a workaround for when the children list is empty? If we are changing the current behavior for non-empty children lists, we're breaking user's code, so we really should wait until 8.0. I can imagine the frustration of updating to a patch or even a minor release and having your code managing the children of a selection container break. |
We should make a decision on this one for 8.0 IMO. I am not so opinionated about the solution but I think that selection containers should be default-constructible. |
7a499a6
to
4483e55
Compare
Rebased on master |
…et selected index to 0. It will be the user’s responsibility to set the selected index to something that makes sense when they change the children.
I thought more about it, and I think it should be the user's responsibility to set the selected index to something that makes sense when they change the children list, especially for the tab widget:
|
Thanks @SylvainCorlay! |
cf discussions on #1822