Skip to content

Commit

Permalink
[TreeView] Remove un-needed aria-activedescendant attribute (mui#12867
Browse files Browse the repository at this point in the history
)
  • Loading branch information
flaviendelangle authored and DungTiger committed Jul 23, 2024
1 parent 80dc45a commit 872b71a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,12 @@ For example, if you were writing a test with `react-testing-library`, here is wh
it('test example on first item', () => {
const { getByRole } = render(
<SimpleTreeView>
<TreeItem itemId="one">One</TreeItem>
<TreeItem itemId="two">Two</TreeItem>
<TreeItem itemId="one" id="one">One</TreeItem>
<TreeItem itemId="two" id="two">Two</TreeItem>
</SimpleTreeView>
);

// Set the focus to the item "One"
- const tree = getByRole('tree');
+ const treeItem = getByRole('treeitem', { name: 'One' });
act(() => {
Expand All @@ -459,6 +461,10 @@ For example, if you were writing a test with `react-testing-library`, here is wh
});
- fireEvent.keyDown(tree, { key: 'ArrowDown' });
+ fireEvent.keyDown(treeItem, { key: 'ArrowDown' });

// Check if the new focused item is "Two"
- expect(tree)to.have.attribute('aria-activedescendant', 'two');
+ expect(document.activeElement).to.have.attribute('id', 'two');
})
```

Expand Down
8 changes: 2 additions & 6 deletions packages/x-tree-view/src/TreeItem/TreeItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,13 @@ describe('<TreeItem />', () => {
});

it('should be able to use a custom id', () => {
const { getByRole, getByTestId } = render(
const { getByRole } = render(
<SimpleTreeView>
<TreeItem id="customId" itemId="one" data-testid="one" />
</SimpleTreeView>,
);

act(() => {
getByTestId('one').focus();
});

expect(getByRole('tree')).to.have.attribute('aria-activedescendant', 'customId');
expect(getByRole('treeitem')).to.have.attribute('id', 'customId');
});

describe('Accessibility', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,9 @@ export const useTreeViewFocus: TreeViewPlugin<UseTreeViewFocusSignature> = ({
}
};

const focusedItem = instance.getItemMeta(state.focusedItemId!);
const activeDescendant = focusedItem
? instance.getTreeItemIdAttribute(focusedItem.id, focusedItem.idAttribute)
: null;

return {
getRootProps: (otherHandlers) => ({
onFocus: createRootHandleFocus(otherHandlers),
'aria-activedescendant': activeDescendant ?? undefined,
}),
publicAPI: {
focusItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@ export type UseTreeViewDefaultizedParameters<
export interface UseTreeViewRootSlotProps
extends Pick<
React.HTMLAttributes<HTMLUListElement>,
| 'onFocus'
| 'onBlur'
| 'onKeyDown'
| 'id'
| 'aria-activedescendant'
| 'aria-multiselectable'
| 'role'
| 'tabIndex'
'onFocus' | 'onBlur' | 'onKeyDown' | 'id' | 'aria-multiselectable' | 'role' | 'tabIndex'
> {
ref: React.Ref<HTMLUListElement>;
}
Expand Down

0 comments on commit 872b71a

Please sign in to comment.