Skip to content

Commit

Permalink
[tree view] Cleanup onKeyDown handler (mui#11481)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle authored Jan 10, 2024
1 parent 4edbf52 commit 0946a1b
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 146 deletions.
30 changes: 30 additions & 0 deletions packages/x-tree-view/src/TreeItem/TreeItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,36 @@ describe('<TreeItem />', () => {

expect(getByTestId('one')).not.to.have.attribute('aria-selected');
});

it('should select a node when Enter is pressed and the node is not selected', () => {
const { getByRole, getByTestId } = render(
<SimpleTreeView>
<TreeItem nodeId="one" label="one" data-testid="one" />
</SimpleTreeView>,
);

act(() => {
getByRole('tree').focus();
});
fireEvent.keyDown(getByRole('tree'), { key: 'Enter' });

expect(getByTestId('one')).to.have.attribute('aria-selected');
});

it('should not un-select a node when Enter is pressed and the node is selected', () => {
const { getByRole, getByTestId } = render(
<SimpleTreeView defaultSelectedNodes="one">
<TreeItem nodeId="one" label="one" data-testid="one" />
</SimpleTreeView>,
);

act(() => {
getByRole('tree').focus();
});
fireEvent.keyDown(getByRole('tree'), { key: 'Enter' });

expect(getByTestId('one')).to.have.attribute('aria-selected');
});
});

describe('mouse', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type MuiCancellableEvent = {
defaultMuiPrevented?: boolean;
};

export type MuiCancellableEventHandler<Event> = (event: Event & MuiCancellableEvent) => void;
Loading

0 comments on commit 0946a1b

Please sign in to comment.