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

fix(chrome): prevent focus on closed Sheet #1920

Merged
merged 2 commits into from
Sep 11, 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
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 : ''}
Copy link
Contributor

@ze-flo ze-flo Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a mental note that this might break with React@19.x:

facebook/react#17157 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using an empty string feels wrong anyway lol glad they're fixing it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the unit tests should tell us if the fix breaks Garden's code

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