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

Tree component: multiple items at the root level #24

Open
Gee-Bee opened this issue Jul 5, 2022 · 1 comment
Open

Tree component: multiple items at the root level #24

Gee-Bee opened this issue Jul 5, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@Gee-Bee
Copy link

Gee-Bee commented Jul 5, 2022

It looks like the tree component could only build trees with one root node.

image
"School Activities" in examples.

In my use case I need to build a tree with multiple items at the root level.
Deque University has such an example: https://dequeuniversity.com/library/aria/tree-view
image

I tried to workaround the issue, placing multiple components one under another:

<Tree>...</Tree>
<Tree>...</Tree>

but this does not produce a valid tree structure and I lost the ability to move around the root nodes.

@Gee-Bee Gee-Bee added the enhancement New feature or request label Jul 5, 2022
@Gee-Bee
Copy link
Author

Gee-Bee commented Jul 20, 2022

I worked around this issue by importing TreeContext and rendering it conditionally within <ul role="tree"> element.

import React from 'react'
import TreeContext from '@devtools-ds/tree/dist/esm/TreeContext'

const Level = ({ parentId }) => {

  const items = ...

  if (!parentId) {
    return (
      <ul
        role="tree"
        tabIndex={0}
      >
        <TreeContext.Provider value={{ isChild: true, depth: 0, hasHover: true }} >
          {items}
        </TreeContext.Provider>
      </ul>
    )
  } else {
    return items
  }
}

It's not an ideal solution, because I lost some attributes on the root <ul>, but the tree structure is at least valid now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant