Skip to content

Commit 403b70d

Browse files
authored
fix(chrome): prevent focus on closed Sheet (#1920)
1 parent e270a63 commit 403b70d

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

packages/chrome/src/elements/sheet/Sheet.spec.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,19 @@ describe('Sheet', () => {
5252
expect(getByRole('complementary')).toBe(ref.current);
5353
});
5454

55+
it('is inert when closed', () => {
56+
const { getByRole } = render(<Example />);
57+
const sheet = getByRole('complementary');
58+
59+
expect(sheet).toHaveAttribute('inert');
60+
});
61+
5562
it('contains a11y bindings to label and describe the sheet', () => {
5663
const { getByRole } = render(<Example isOpen />);
5764
const sheet = getByRole('complementary');
5865

5966
expect(screen.getByLabelText('title')).toBe(sheet);
6067
expect(sheet).toHaveAccessibleDescription('description');
68+
expect(sheet).not.toHaveAttribute('inert');
6169
});
6270
});

packages/chrome/src/elements/sheet/Sheet.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const SheetComponent = React.forwardRef<HTMLElement, ISheetProps>(
5151
return (
5252
<SheetContext.Provider value={sheetContext}>
5353
<StyledSheet
54+
inert={isOpen ? undefined : ''}
5455
isOpen={isOpen}
5556
isAnimated={isAnimated}
5657
placement={placement}

packages/chrome/src/styled/sheet/StyledSheet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ISheetProps } from '../../types';
1212
const COMPONENT_ID = 'chrome.sheet';
1313

1414
interface IStyledSheetProps {
15+
inert?: string;
1516
placement?: ISheetProps['placement'];
1617
isOpen?: boolean;
1718
isAnimated?: boolean;

0 commit comments

Comments
 (0)