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

Expand sl-tree-item on first selection. #1517

Closed

Conversation

grncdr
Copy link
Contributor

@grncdr grncdr commented Aug 15, 2023

Previously, an sl-tree with the 'single' selection mode would always toggle the expanded state of an item when selecting it, which leads to an unusual behaviour: selecting an expanded (but not previously selected) item collapses it.

This changes the behaviour of 'single' mode so that an item is always expanded when it is first selected. Clicking an item that was already selected then toggles it's expanded state.


See related discussion in #1159

Previously, an sl-tree with the 'single' selection mode would always toggle the expanded state of an item when selecting it, which lead to an unexpected behaviour that selecting an expanded (but not previously selected) item would collapse it.

This changes that behaviour so that an item is always (in 'single' mode) expanded if it was not previously selected. Clicking an item that was already selected continues to toggle it's expanded state.
@vercel
Copy link

vercel bot commented Aug 15, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
shoelace ✅ Ready (Inspect) Visit Preview Aug 15, 2023 11:20am

@grncdr
Copy link
Contributor Author

grncdr commented Aug 15, 2023

I've intentionally scoped this change very narrowly, for reasons described in the linked discussion (comment).

@claviska
Copy link
Member

I can see why this is useful. My only question is, should we identify clicks on the chevron and always toggle for those clicks and use the new behavior for clicks elsewhere on the tree item?

@grncdr
Copy link
Contributor Author

grncdr commented Aug 16, 2023

I can see why this is useful. My only question is, should we identify clicks on the chevron and always toggle for those clicks and use the new behavior for clicks elsewhere on the tree item?

It sounds reasonable, and there's already code that detects if a click was on the chevron, so to implement I only needed to forward that boolean to selectItem. However, it reintroduces the problematic behaviour I'm trying to fix: clicking the chevron for a deselected + expanded tree item will set selected = true and expanded = false.

After clicking around a bunch on
https://shoelace-b9zozc8hn-font-awesome.vercel.app/components/tree/ I think a better option might be to combine it with #1521.

@claviska
Copy link
Member

Thanks again for the PRs! I believe this was resolved as part of #1521, but if I'm mistaken let me know.

@claviska claviska closed this Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants