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

TreeGrid: Update README with data-expanded attribute usage #50026

Merged
merged 4 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- `NavigableContainer`: Convert to TypeScript ([#49377](https://github.com/WordPress/gutenberg/pull/49377)).

### Documentation

- `TreeGrid`: Update docs with `data-expanded` attribute usage ([#50026](https://github.com/WordPress/gutenberg/pull/50026)).

## 23.9.0 (2023-04-26)

### Internal
Expand Down
18 changes: 18 additions & 0 deletions packages/components/src/tree-grid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,26 @@ An integer value that represents the total number of items in the set, at this s

An optional value that designates whether a row is expanded or collapsed. Currently this value only sets the correct aria-expanded property on a row, it has no other built-in behavior.

If there is a need to implement `aria-expanded` elsewhere in the row, cell, or element within a cell, you may pass `isExpanded={ undefined }`. In order for keyboard navigation to continue working, add the `data-expanded` attribute with either `true`/`false`. This allows the `TreeGrid` component to still manage keyboard interactions while allowing the `aria-expanded` attribute to be placed elsewhere. See the example below.

- Required: No

```jsx
function TreeMenu() {
return (
<TreeGrid>
<TreeGridRow level={ 1 } positionInSet={ 1 } setSize={ 2 } isExpanded={ undefined } data-expanded={ false }>
<TreeGridCell>
{ ( props ) => (
<Button aria-expanded="false" onClick={ onSelect } { ...props }>Select</Button>
) }
</TreeGridCell>
</TreeGridRow>
</TreeGrid>
);
}
```

### TreeGridCell

#### Props
Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/tree-grid/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export type TreeGridRowProps = {
* An optional value that designates whether a row is expanded or collapsed.
* Currently this value only sets the correct aria-expanded property on a row,
* it has no other built-in behavior.
*
* If there is a need to implement `aria-expanded` elsewhere in the row, cell,
* or element within a cell, you may pass `isExpanded={ undefined }`.
* In order for keyboard navigation to continue working, add the
* `data-expanded` attribute with either `true`/`false`. This allows the
* `TreeGrid` component to still manage keyboard interactions while allowing
* the `aria-expanded` attribute to be placed elsewhere.
*/
isExpanded?: boolean;
};
Expand Down