-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b97cee6
commit b51b782
Showing
34 changed files
with
4,383 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const CLASS_PREFIX = 'md-tree'; | ||
|
||
const DEFAULTS = { | ||
IS_RENDERED_FLAT: true, | ||
EXCLUDE_TREE_ROOT: true, | ||
}; | ||
|
||
const STYLE = { | ||
wrapper: `${CLASS_PREFIX}-wrapper`, | ||
}; | ||
|
||
export { CLASS_PREFIX, DEFAULTS, STYLE }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { commonStyles } from '../../storybook/helper.stories.argtypes'; | ||
|
||
export default { | ||
...commonStyles, | ||
shouldNodeFocusBeInset: { | ||
description: | ||
'Determines whether the focus around list-items should be inset or outset. This is needed for virtualized lists', | ||
control: { type: 'boolean' }, | ||
table: { | ||
type: { | ||
summary: 'boolean', | ||
}, | ||
defaultValue: { | ||
summary: 'false', | ||
}, | ||
}, | ||
}, | ||
excludeTreeRoot: { | ||
description: 'Determines if the tree root should be excluded from the tree navigation.', | ||
control: { type: 'boolean' }, | ||
table: { | ||
type: { | ||
summary: 'boolean', | ||
}, | ||
defaultValue: { | ||
summary: 'true', | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
The `<Tree />` component implements the basic tree navigation based on the WAI-ARIA specification, | ||
see [WCAG Tree Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/treeview/) for more details. | ||
|
||
`<Tree />` does not render the tree nodes automatically. It makes it more flexible to customize the tree nodes and | ||
make it possible to use it with Virtualized trees. | ||
|
||
Tree nodes must be wrapped in a `<TreeNodeBase />` component to ensure proper keyboard navigation and focus management. | ||
|
||
Any node inside the `<Tree />` can access to the tree context using the `useTreeContext` hook. | ||
|
||
## Nested VS Flat tree | ||
|
||
There is 2 ways to represent the tree structure in the DOM: | ||
|
||
### 1) Nested elements | ||
|
||
Simple static trees usually represented as nested elements. It's easy to understand and implement and | ||
most of the semantics are implicitly set. But hard to render it automatically especially in virtualized trees. | ||
|
||
```html | ||
<ul role="tree" aria-labelledby="tree_label"> | ||
<li role="treeitem" aria-expanded="false" aria-selected="false"> | ||
<span> Level 1 </span> | ||
<ul role="group"> | ||
<li role="treeitem" aria-selected="false">Level 2.1</li> | ||
<li role="treeitem" aria-selected="false">Level 2.2</li> | ||
<li role="treeitem" aria-selected="false">Level 2.3</li> | ||
<li role="treeitem" aria-expanded="false" aria-selected="false"> | ||
<span> Level 2.4 </span> | ||
<ul role="group"> | ||
<li role="treeitem" aria-selected="false">Level 3.1</li> | ||
<li role="treeitem" aria-selected="false">Level 3.2</li> | ||
</ul> | ||
</li> | ||
<li role="treeitem" aria-selected="false">Level 2.5</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
|
||
``` | ||
|
||
### 2) Flat elements | ||
|
||
Flat tree structure is more flexible and can be used with virtualized trees. It requires more explicit semantics. | ||
|
||
```html | ||
<h3 id="tree_label_2">Tree with flat DOM</h3> | ||
<ul role="tree" aria-labelledby="tree_label_2"> | ||
<li | ||
role="treeitem" | ||
aria-level="1" | ||
aria-expanded="true" | ||
aria-selected="false" | ||
class="level-1" | ||
> | ||
<span> Level 1 </span> | ||
<div role="group" aria-owns="level-2.1 level-2.2 level-2.3 level-2.4 level-2.5"></div> | ||
</li> | ||
<li | ||
id="level-2.1" | ||
aria-setsize="5" | ||
aria-posinset="1" | ||
role="treeitem" | ||
aria-level="2" | ||
class="level-2" | ||
> | ||
<span> Level 2.1</span> | ||
</li> | ||
<li | ||
id="level-2.2" | ||
aria-setsize="5" | ||
aria-posinset="2" | ||
role="treeitem" | ||
aria-level="2" | ||
class="level-2" | ||
> | ||
<span> Level 2.2</span> | ||
</li> | ||
<li | ||
id="level-2.3" | ||
aria-setsize="5" | ||
aria-posinset="3" | ||
role="treeitem" | ||
aria-level="2" | ||
class="level-2" | ||
> | ||
<span> Level 2.3</span> | ||
</li> | ||
<li | ||
id="level-2.4" | ||
aria-setsize="5" | ||
aria-posinset="4" | ||
role="treeitem" | ||
aria-level="2" | ||
class="level-2" | ||
aria-expanded="true" | ||
|
||
> | ||
Level 2.4 | ||
<div role="group" aria-owns="level-3.1 level-3.2"></div> | ||
</li> | ||
<li | ||
id="level-3.1" | ||
aria-setsize="2" | ||
aria-posinset="1" | ||
role="treeitem" | ||
aria-level="3" | ||
class="level-3" | ||
> | ||
<span> Level 3.1</span> | ||
</li> | ||
<li | ||
id="level-3.2" | ||
aria-setsize="2" | ||
aria-posinset="2" | ||
role="treeitem" | ||
aria-level="3" | ||
class="level-3" | ||
> | ||
<span> Level 3.2</span> | ||
</li> | ||
<li | ||
id="level-2.5" | ||
aria-setsize="5" | ||
aria-posinset="5" | ||
role="treeitem" | ||
aria-level="2" | ||
class="level-2" | ||
> | ||
<span> Level 2.5</span> | ||
</li> | ||
</ul> | ||
``` |
Oops, something went wrong.