Skip to content

Commit 473b2ca

Browse files
committed
fix(TreeView): pass id,inert to TreeViewList
1 parent f8bcd7c commit 473b2ca

5 files changed

Lines changed: 22 additions & 3 deletions

File tree

packages/react-core/src/components/TreeView/TreeView.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export interface TreeViewProps {
8484
icon?: React.ReactNode;
8585
/** ID of the tree view. */
8686
id?: string;
87+
/** ID of the root tree view list. */
88+
rootListId?: string;
8789
/** Flag indicating whether multiple nodes can be selected in the tree view. This will also set the
8890
* aria-multiselectable attribute on the tree view list which is required to be true when multiple selection is intended.
8991
* Can only be applied to the root tree view list.
@@ -113,6 +115,8 @@ export interface TreeViewProps {
113115
* the next breaking change release in favor of defaulting to always-rendered items.
114116
*/
115117
hasAnimations?: boolean;
118+
/** @hide Flag indicating whether the tree view list should be inert. */
119+
inert?: boolean;
116120
}
117121

118122
export const TreeView: React.FunctionComponent<TreeViewProps> = ({
@@ -141,6 +145,8 @@ export const TreeView: React.FunctionComponent<TreeViewProps> = ({
141145
'aria-label': ariaLabel,
142146
'aria-labelledby': ariaLabelledby,
143147
hasAnimations: hasAnimationsProp,
148+
rootListId,
149+
inert,
144150
...props
145151
}: TreeViewProps) => {
146152
const hasAnimations = useHasAnimations(hasAnimationsProp);
@@ -151,7 +157,8 @@ export const TreeView: React.FunctionComponent<TreeViewProps> = ({
151157
isMultiSelectable={isMultiSelectable}
152158
aria-label={ariaLabel}
153159
aria-labelledby={ariaLabelledby}
154-
{...props}
160+
id={rootListId}
161+
inert={inert}
155162
>
156163
{data.map((item) => (
157164
<TreeViewListItem

packages/react-core/src/components/TreeView/TreeViewList.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export interface TreeViewListProps extends React.HTMLProps<HTMLUListElement> {
2323
* this or the aria-label property must be passed in.
2424
*/
2525
'aria-labelledby'?: string;
26+
/** @hide Flag indicating whether the tree view list should be inert. */
27+
inert?: boolean;
2628
}
2729

2830
export const TreeViewList: React.FunctionComponent<TreeViewListProps> = ({

packages/react-core/src/components/TreeView/__tests__/TreeView.test.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ jest.mock('../TreeViewList', () => ({
1010
toolbar,
1111
'aria-label': ariaLabel,
1212
'aria-labelledby': ariaLabelledBy,
13-
isMultiSelectable
13+
isMultiSelectable,
14+
id
1415
}) => (
1516
<div data-testid="TreeViewList-mock">
1617
<p>{`TreeViewList isNested: ${isNested}`}</p>
1718
<p>{`TreeViewList toolbar: ${toolbar}`}</p>
1819
<p>{`TreeViewList aria-label: ${ariaLabel}`}</p>
1920
<p>{`TreeViewList aria-labelledBy: ${ariaLabelledBy}`}</p>
2021
<p>{`TreeViewList isMultiSelectable: ${isMultiSelectable}`}</p>
22+
<p>{`TreeViewList id: ${id}`}</p>
2123
<div data-testid="TreeViewList-children">{children}</div>
2224
</div>
2325
)
@@ -164,6 +166,11 @@ test('Passes data as children TreeViewList', () => {
164166

165167
expect(screen.getByTestId('TreeViewList-children')).toContainHTML('TreeViewListItem name: Basic data name');
166168
});
169+
test('Passes rootListId to TreeViewList', () => {
170+
render(<TreeView rootListId="test-root-list-id" data={[basicData]} />);
171+
172+
expect(screen.getByText('TreeViewList id: test-root-list-id')).toBeVisible();
173+
});
167174

168175
test('Passes data action to TreeViewListItem', () => {
169176
render(<TreeView data={[{ ...basicData, action: 'Item action' }]} />);

packages/react-core/src/components/TreeView/__tests__/TreeViewList.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test(`Renders with role="group" when isNested is true`, () => {
2222
expect(screen.getByRole('group')).toHaveTextContent('Content');
2323
});
2424

25-
test(`Spreads additional props`, () => {
25+
test('Renders with id when id is passed', () => {
2626
render(<TreeViewList id="test-id">Content</TreeViewList>);
2727

2828
expect(screen.getByRole('tree')).toHaveAttribute('id', 'test-id');

packages/react-core/src/components/TreeView/__tests__/__snapshots__/TreeView.test.tsx.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ exports[`Matches snapshot 1`] = `
4141
<p>
4242
TreeViewList isMultiSelectable: false
4343
</p>
44+
<p>
45+
TreeViewList id: undefined
46+
</p>
4447
<div
4548
data-testid="TreeViewList-children"
4649
>

0 commit comments

Comments
 (0)