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

[TreeView] Remove un-needed aria-activedescendant attribute #12867

Merged
merged 2 commits into from
Apr 23, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,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 @@ -429,6 +431,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
Loading