-
-
Notifications
You must be signed in to change notification settings - Fork 787
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
feat: add new tree-view component #823
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thanks for submitting this. I know it's a draft, but here are some initial thoughts:
I'm sure I'll have more feedback as this progresses, but you're off to a great start here! |
Thank you for taking time to review! I updated the PR following your points, here are the changes I made so far, some of them might need more discussion tho:
Regarding this topic, I think the behaviour follows what is described by the ARIA spec, especially if we think about the multiple selection. I'm not sure if there is a use case where just a subset of child items need to be selectable, so I kept the implementation into the tree component for now. |
A couple comments on styles: Can we remove the border/padding/background on the base? It appears to be in a well which is nice for some use cases, but I think the default appearance should be less opinionated, i.e. the user should be able to style the host element to add a border/background/padding should they want it. I'm also not sure about the light gray highlight + primary text color on selected tree items. Menu uses a primary background and white text, for example. I don't think anything in the library uses a light gray background for selections, so we might need to play with this a bit. Not sure if making it look like menu items would be too bold — maybe it's just the primary text throwing it off.
That's fair. Regarding lazy loading of nodes, if tree items had a I see some new commits since your last message, so let me know when you're ready for the next review/steps. |
I've updated the PR:
I think the lazy loading is quite simple to use in this way, but I'm curious to know what you think. |
AccessibilityIt seems like screen reader compat is very, very close! Here are some examples I referenced using VoiceOver:
One thing I noticed is that it keeps announcing "button, 1 of 1" and I think it's because of this It's also not currently possible to tab into the tree. It looks like a roving tab index is called for, so tabbing once lands focus in the tree and another leaves it, and subsequent tabs back into the tree should focus on the last selected tree item. From that point, arrow keys are used to navigate and expand/collapse. (FYI — neither example allows Enter to expand/collapse a node, and it seems like Left|Right are the correct keys to use here so we should probably keep those and remove Enter.) Styles
Do we even need a selected style? Mouse users don't need to see it, and keyboard users will see Note that users should be able to add a selected state through custom styles if they want it. The part could look like Lazy LoadingNice approach! Can we rename
Question: the docs only show the lazy demo loading once. I assumed it would load every time the node expands unless the user removes the
And it feels like too strong an opinion to have the component mutate the lazy attribute for them. |
I've got just a couple of questions:
The ARIA Authoring Practices Guide states that particular behaviour for the
To be honest I think it would be useful, image if you are implementing a sort of file browser, and you want to keep the selected item highlighted even if you move the focus away. |
I stand corrected. I was basing that off of the two examples, neither of which expand on Enter. Carry on! 😂
I agree, that’s a great use case. But should the visible selection be on by default for all users? It feels a lot better to me if the tree starts without a selection, and for users who want to show one, they can easily target |
I believe they should have the same behavior. If the row is selectable, both "space" and "enter" should select the row. If it is expandable, they both should toggle the row. If it is both expandable and selectable, they both should select the row and the arrow keys should be used to expand and collapse. Check out their example here.
It looks like the examples in the docs read fine for Narrator and NVDA on Windows, but VoiceOver does not correctly read the position. I tried adding the aria attributes and it didn't seem to help. 🤷♂️ |
feat: add indeterminate state fix: rename item role fix: aria attributes fix: restore hover effect fix: indeterminate state chore: fix lint issue fix: address (partially) review comment fix: minor fix feat: add keyboard navigation fix: dependency name fix: keyboard selection does not update all items chore: minor changes chore: remove leftover chore: update documentation feat: add lazy loading + several fixes fix: add aria-busy attribute fix: improve keyboard navigation and lazy loading chore: fix linting issue chore: minor fixes fix: update component styling and slot chore: remove exportparts attribute fix: remove button margin for safari fix: set correct part name feat: implement selection modes and fix accessibility issues chore: fix linting issues chore: update docs fix: minor fix fix: treeitem height style chore: update documentation chore: refactor implementation chore: implement unit tests chore: update Enter key behavior chore: update doc chore: update doc
Spent some time on this today trying to get it over the finish line. I have a branch with my updates here. It's probably easiest to merge my changes from that branch into this PR. Branch: https://github.com/shoelace-style/shoelace/tree/alenaksu-feat/tree-view The good news is that it's just about there! Here's what I updated:
Here's what's left on the wishlist:
And there's one known bug I found:
|
* fix a bug focusing collapsed nodes
Thank you for your changes, I've merged your branch into mine.
|
This PR adds a Tree and TreeItem components that allow user to display a hierarchical list of items, expanding and collapsing the nodes that have nested items.
The
sl-tree
component implements the API to interact with the whole tree, like the selection and the keyboard navigation. It has just a default slot that can containsl-tree-item
components, that represent the nodes of the tree.Each
sl-tree-item
can in turn contain othersl-tree-item
, allowing to the user to define nested trees. A tree item with nested nodes, can be expanded and collapsed.Closes #539
Code example
Appereance