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 View] Polish the default design & revise the simple version pages #11529

Merged
merged 28 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
415bbd6
polish the built-in styles
danilo-leal Dec 28, 2023
3758623
revise the Overview page
danilo-leal Dec 28, 2023
98c9165
docs:typescript:formatted
danilo-leal Dec 28, 2023
2cc7afd
fix hierarchy
danilo-leal Dec 28, 2023
ad42d5b
fix correct demo order
danilo-leal Dec 28, 2023
5965688
Merge branch 'next' into polish-tree-view
danilo-leal Jan 2, 2024
4d8d6dc
Merge branch 'next' into polish-tree-view
danilo-leal Jan 2, 2024
3bf5f96
overview page quick revision
danilo-leal Jan 2, 2024
02e094f
standardize page order
danilo-leal Jan 2, 2024
83a584d
simple tree view items revision
danilo-leal Jan 2, 2024
ea29621
items page revision
danilo-leal Jan 2, 2024
d5aaf90
expansion page revision
danilo-leal Jan 2, 2024
9af35c7
customization page revision
danilo-leal Jan 2, 2024
3e8686a
fix page order again (did it wrong the last time)
danilo-leal Jan 2, 2024
1fa9993
run yarn eslint and docs:typescript:formatted
danilo-leal Jan 2, 2024
264aaa2
Merge branch 'next' into polish-tree-view
danilo-leal Jan 3, 2024
5407480
Merge branch 'next' into polish-tree-view
danilo-leal Jan 16, 2024
27c2e2a
adjust padding
danilo-leal Jan 16, 2024
2af6572
more small adjustments
danilo-leal Jan 16, 2024
d726693
docs:typescript:formatted
danilo-leal Jan 16, 2024
01020c4
Merge branch 'next' into polish-tree-view
danilo-leal Jan 17, 2024
2d5aa28
Merge branch 'next' into polish-tree-view
danilo-leal Jan 24, 2024
420fa32
Merge branch 'next' into polish-tree-view
danilo-leal Jan 26, 2024
7547021
Sam's copywriting review
danilo-leal Jan 29, 2024
448dc1d
add installation blocks
danilo-leal Jan 29, 2024
400df30
update prop names
danilo-leal Feb 1, 2024
16f2e9a
add info callout about advanced features and future growth
danilo-leal Feb 1, 2024
72b1879
quick rich tree view disabled prop consistency
danilo-leal Feb 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions docs/data/tree-view/overview/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,36 @@ packageName: '@mui/x-tree-view'

# MUI X Tree View

<p class="description">A Tree View widget presents a hierarchical list.</p>

Tree views can be used to represent a file system navigator displaying folders and files, an item representing a folder can be expanded to reveal the contents of the folder, which may be files, folders, or both.
<p class="description">The Tree View component lets users navigate hierarchical lists of data with nested levels that can be expanded and collapsed.</p>

{{"component": "modules/components/ComponentLinkHeader.js"}}

## Available components

There are two versions of the Tree View available.
The MUI X Tree View package exposes two different versions of the component:

### Simple Tree View

### SimpleTreeView
```jsx
import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView';
```

The `SimpleTreeView` component receives its items as JSX children.
It is designed for simple use-cases where the items are hardcoded.
The simple version of the Tree View component receives its items as JSX children.
This is the recommended version for hardcoded items.

{{"demo": "BasicSimpleTreeView.js"}}

:::warning
danilo-leal marked this conversation as resolved.
Show resolved Hide resolved
Most new advanced features won't be available on this component.
If you are waiting for features like editing or virtualization, you should use `RichTreeView` instead.
:::
### Rich Tree View

### RichTreeView
```jsx
import { RichTreeView } from '@mui/x-tree-view/RichTreeView';
```

The `RichTreeView` component receives its items through the `items` prop.
It is designed for more advanced use-cases where the items are dynamically loaded from a data source.
The rich version of the Tree View component receives its items dynamically from an external data source.
This is the recommended version for larger trees, as well as those that require more advanced features like editing and virtualization.

{{"demo": "BasicRichTreeView.js"}}

:::info
At the moment, the Simple and Rich Tree Views are similar in terms of feature support. But as the component grows, you can expect to see the more advanced ones appear primarily on the Rich Tree View.
:::
26 changes: 12 additions & 14 deletions docs/data/tree-view/rich-tree-view/items/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Unlike the `SimpleTreeView` component, the `RichTreeView` component only support

## Disabled items

You can disable some of the items using the `isItemDisabled` prop on the `RichTreeView` component:
Use the `isItemDisabled` prop on the Rich Tree View to disable interaction and focus on a Tree Item:

```tsx
function isItemDisabled(item) {
Expand All @@ -116,29 +116,27 @@ function isItemDisabled(item) {
Just like the `items` prop, the `isItemDisabled` function should keep the same JavaScript reference between two renders.
Otherwise, the Tree View will re-generate its entire structure.

It could be achieved by either defining the prop outside the component scope or by memoizing using the `React.useCallback` hook if the function reuses something from the component scope.
This can be achieved by either defining the prop outside the component scope or by memoizing using the `React.useCallback` hook if the function reuses something from the component scope.
:::

### Interact with disabled items
### The disabledItemsFocusable prop

The behavior of disabled tree items depends on the `disabledItemsFocusable` prop.
Use the `disabledItemsFocusable` prop to control whether or not a disabled Tree Item can be focused.

If it is false:
When this prop is set to false:

- Arrow keys will not focus disabled items, and the next non-disabled item will be focused.
- Typing the first character of a disabled item's label will not focus the item.
- Navigating with keyboard arrow keys will not focus the disabled items, and the next non-disabled item will be focused instead.
- Typing the first character of a disabled item's label will not move the focus to it.
- Mouse or keyboard interaction will not expand/collapse disabled items.
- Mouse or keyboard interaction will not select disabled items.
- Shift + arrow keys will skip disabled items, and the next non-disabled item will be selected.
- <kbd class="key">Shift</kbd> + arrow keys will skip disabled items, and the next non-disabled item will be selected instead.
- Programmatic focus will not focus disabled items.

If it is true:
When it's set to true:

- Arrow keys will focus disabled items.
- Typing the first character of a disabled item's label will focus the item.
- Navigating with keyboard arrow keys will focus disabled items.
- Typing the first character of a disabled item's label will move focus to it.
- Mouse or keyboard interaction will not expand/collapse disabled items.
- Mouse or keyboard interaction will not select disabled items.
- Shift + arrow keys will not skip disabled items but, the disabled item will not be selected.
- <kbd class="key">Shift</kbd> + arrow keys will not skip disabled items, but the disabled item will not be selected.
- Programmatic focus will focus disabled items.

{{"demo": "DisabledItemsFocusable.js", "defaultCodeOpen": false}}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const CustomContent = React.forwardRef(function CustomContent(props, ref) {
ref={ref}
>
<div className={classes.iconContainer}>{icon}</div>
<Box sx={{ flexGrow: 1, display: 'flex', gap: 2 }}>
<Box sx={{ flexGrow: 1, display: 'flex', gap: 1 }}>
<Avatar
sx={(theme) => ({
background: theme.palette.primary.main,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const CustomContent = React.forwardRef(function CustomContent(
ref={ref as React.Ref<HTMLDivElement>}
>
<div className={classes.iconContainer}>{icon}</div>
<Box sx={{ flexGrow: 1, display: 'flex', gap: 2 }}>
<Box sx={{ flexGrow: 1, display: 'flex', gap: 1 }}>
<Avatar
sx={(theme) => ({
background: theme.palette.primary.main,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ The demo below shows many of the previous customization examples brought togethe
Google's Gmail side nav is potentially one of the web's most famous tree view components.
The demo below shows how to replicate it.

The Gmail sidebar is one of the most well known examples of a tree view.
The demo below shows how to recreate it with the Tree View component:

{{"demo": "GmailTreeView.js"}}
7 changes: 3 additions & 4 deletions docs/data/tree-view/simple-tree-view/expansion/expansion.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/

# Simple Tree View - Expansion

<p class="description">Handle how users can expand items.</p>
<p class="description">Learn how to handle expanding and collapsing Tree View items.</p>

## Controlled expansion

Use the `expandedNodes` prop to control the expanded items.

You can use the `onExpandedNodesChange` prop to listen to changes in the expanded items and update the prop accordingly.
You can also use the `onExpandedNodesChange` prop to listen to changes in the expanded items and update the prop accordingly.

{{"demo": "ControlledExpansion.js"}}

Expand All @@ -29,6 +28,6 @@ Learn more about the _Controlled and uncontrolled_ pattern in the [React documen

## Track node expansion change

Use the `onNodeExpansionToggle` prop if you want to react to a node expansion change:
Use the `onNodeExpansionToggle` prop to trigger an action upon a node being expanded.

{{"demo": "TrackNodeExpansionToggle.js"}}
61 changes: 29 additions & 32 deletions docs/data/tree-view/simple-tree-view/items/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,65 @@ waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/

# Simple Tree View - Items

<p class="description">Pass data to your Tree View.</p>
<p class="description">Learn how to add simple data to the Tree View component.</p>

## Basic usage
## Basics

The items can be defined as JSX children of the `SimpleTreeView` component:
```jsx
import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView';
import { TreeItem } from '@mui/x-tree-view/TreeItem';
```

{{"demo": "BasicSimpleTreeView.js"}}
The Simple Tree View component receives its items directly as JSX children.

## Item identifier
{{"demo": "BasicSimpleTreeView.js"}}

Each `TreeItem` must have a unique `nodeId`.
### Item identifier

This identifier is used internally to identify the item in the various models and to track the item across updates.
Each Tree Item must have a unique `nodeId`.
This is used internally to identify the item in the various models, and to track it across updates.

```tsx
<SimpleTreeView>
<TreeItem nodeId="tree-view-community" {...otherItemProps} />
<TreeItem nodeId="item-unique-id" {...otherItemProps} />
</SimpleTreeView>
```

## Item label
### Item label

You must pass a `label` prop to each `TreeItem` component:
You must pass a `label` prop to each Tree Item component, as shown below:

```tsx
<SimpleTreeView>
<TreeItem label="@mui/x-tree-view" {...otherItemProps} />
<TreeItem label="Item label" {...otherItemProps} />
</SimpleTreeView>
```

## Disabled items
### Disabled items

You can disable some of the items using the `disabled` prop on the `TreeItem` component:
Use the `disabled` prop on the Tree Item component to disable interaction and focus:

```tsx
<SimpleTreeView>
<TreeItem disabled {...otherItemProps} />
</SimpleTreeView>
```

{{"demo": "DisabledJSXItem.js", "defaultCodeOpen": false}}
{{"demo": "DisabledItemsFocusable.js", "defaultCodeOpen": false}}

### Interact with disabled items
#### The disabledItemsFocusable prop

The behavior of disabled tree items depends on the `disabledItemsFocusable` prop.
Note that the demo above also includes a switch.
This toggles the `disabledItemsFocusable` prop, which controls whether or not a disabled Tree Item can be focused.

If it is false:
When this prop is set to false:

- Arrow keys will not focus disabled items, and the next non-disabled item will be focused.
- Typing the first character of a disabled item's label will not focus the item.
- Navigating with keyboard arrow keys will not focus the disabled items, and the next non-disabled item will be focused instead.
- Typing the first character of a disabled item's label will not move the focus to it.
- Mouse or keyboard interaction will not expand/collapse disabled items.
- Mouse or keyboard interaction will not select disabled items.
- Shift + arrow keys will skip disabled items, and the next non-disabled item will be selected.
- <kbd class="key">Shift</kbd> + arrow keys will skip disabled items, and the next non-disabled item will be selected instead.
- Programmatic focus will not focus disabled items.

If it is true:
When it's set to true:

- Arrow keys will focus disabled items.
- Typing the first character of a disabled item's label will focus the item.
- Navigating with keyboard arrow keys will focus disabled items.
- Typing the first character of a disabled item's label will move focus to it.
- Mouse or keyboard interaction will not expand/collapse disabled items.
- Mouse or keyboard interaction will not select disabled items.
- Shift + arrow keys will not skip disabled items but, the disabled item will not be selected.
- <kbd class="key">Shift</kbd> + arrow keys will not skip disabled items, but the disabled item will not be selected.
- Programmatic focus will focus disabled items.

{{"demo": "DisabledItemsFocusable.js", "defaultCodeOpen": false}}
9 changes: 4 additions & 5 deletions docs/data/tree-view/simple-tree-view/selection/selection.md
danilo-leal marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/

# Simple Tree View - Selection

<p class="description">Handle how users can select items.</p>
<p class="description">Learn how to enable item selection for the Tree View component.</p>

## Multi selection

The Tree View also supports multi-selection:
Apply the `multiSelect` prop on the Tree View to let users select multiple items.

{{"demo": "MultiSelectTreeView.js"}}

Expand All @@ -25,9 +25,8 @@ Use the `disableSelection` prop if you don't want your items to be selectable:

## Controlled selection

Use the `selectedNodes` prop to control the selected items.

You can use the `onSelectedNodesChange` prop to listen to changes in the selected items and update the prop accordingly.
Use the `selectedNodes` prop to control selected Tree View items.
You can also use the `onSelectedNodesChange` prop to listen to changes in the selected items and update the prop accordingly.

{{"demo": "ControlledSelection.js"}}

Expand Down
10 changes: 5 additions & 5 deletions packages/x-tree-view/src/TreeItem/TreeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ const StyledTreeItemContent = styled(TreeItemContent, {
];
},
})<{ ownerState: TreeItemOwnerState }>(({ theme }) => ({
padding: '0 8px',
padding: theme.spacing(0.5, 1),
borderRadius: theme.shape.borderRadius,
width: '100%',
boxSizing: 'border-box', // prevent width + padding to overflow
display: 'flex',
alignItems: 'center',
gap: theme.spacing(1),
cursor: 'pointer',
WebkitTapHighlightColor: 'transparent',
'&:hover': {
Expand Down Expand Up @@ -107,8 +109,7 @@ const StyledTreeItemContent = styled(TreeItemContent, {
},
},
[`& .${treeItemClasses.iconContainer}`]: {
marginRight: 4,
width: 15,
width: 16,
display: 'flex',
flexShrink: 0,
justifyContent: 'center',
Expand All @@ -117,7 +118,6 @@ const StyledTreeItemContent = styled(TreeItemContent, {
},
},
[`& .${treeItemClasses.label}`]: {
paddingLeft: 4,
width: '100%',
boxSizing: 'border-box', // prevent width + padding to overflow
// fixes overflow - see https://github.com/mui/material-ui/issues/27372
Expand All @@ -134,7 +134,7 @@ const TreeItemGroup = styled(Collapse, {
})({
margin: 0,
padding: 0,
marginLeft: 17,
paddingLeft: 12,
});

/**
Expand Down
Loading