Skip to content

Commit

Permalink
fix(chrome): prevent focus on closed Sheet (#1920)
Browse files Browse the repository at this point in the history
  • Loading branch information
jzempel authored Sep 11, 2024
1 parent e270a63 commit 403b70d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/chrome/src/elements/sheet/Sheet.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ describe('Sheet', () => {
expect(getByRole('complementary')).toBe(ref.current);
});

it('is inert when closed', () => {
const { getByRole } = render(<Example />);
const sheet = getByRole('complementary');

expect(sheet).toHaveAttribute('inert');
});

it('contains a11y bindings to label and describe the sheet', () => {
const { getByRole } = render(<Example isOpen />);
const sheet = getByRole('complementary');

expect(screen.getByLabelText('title')).toBe(sheet);
expect(sheet).toHaveAccessibleDescription('description');
expect(sheet).not.toHaveAttribute('inert');
});
});
1 change: 1 addition & 0 deletions packages/chrome/src/elements/sheet/Sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const SheetComponent = React.forwardRef<HTMLElement, ISheetProps>(
return (
<SheetContext.Provider value={sheetContext}>
<StyledSheet
inert={isOpen ? undefined : ''}
isOpen={isOpen}
isAnimated={isAnimated}
placement={placement}
Expand Down
1 change: 1 addition & 0 deletions packages/chrome/src/styled/sheet/StyledSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ISheetProps } from '../../types';
const COMPONENT_ID = 'chrome.sheet';

interface IStyledSheetProps {
inert?: string;
placement?: ISheetProps['placement'];
isOpen?: boolean;
isAnimated?: boolean;
Expand Down

0 comments on commit 403b70d

Please sign in to comment.