Skip to content

Commit

Permalink
fix a11y issue
Browse files Browse the repository at this point in the history
  • Loading branch information
scurker committed Sep 20, 2024
1 parent 4e4d10b commit 3b5d594
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/react/src/components/Drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const Drawer = forwardRef<HTMLDivElement, DrawerProps>(
visibility: !open && !isTransitioning ? 'hidden' : undefined,
...style
}}
tabIndex={-1}
tabIndex={open ? -1 : undefined}
{...props}
>
{children}
Expand Down
33 changes: 33 additions & 0 deletions packages/react/src/utils/getElementOrRef.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createRef, type MutableRefObject } from 'react';
import getElementOrRef from './getElementOrRef';

test('should return element', () => {
expect(getElementOrRef(document.body)).toBe(document.body);
});

test('should return ref element', () => {
const ref = createRef() as MutableRefObject<HTMLElement>;
ref.current = document.body;
expect(getElementOrRef(ref)).toBe(document.body);
});

test('should return null when element is undefined', () => {
expect(getElementOrRef(undefined)).toBe(null);
});

test('should return null when ref is undefined', () => {
const ref = createRef() as MutableRefObject<HTMLElement>;
expect(getElementOrRef(ref)).toBe(null);
});

test('should return null when element is not instance of Element', () => {
// @ts-expect-error bad data
expect(getElementOrRef('thing')).toBe(null);
});

test('should return null when ref is not instance of Element', () => {
const ref = createRef() as MutableRefObject<HTMLElement>;
// @ts-expect-error bad data
ref.current = 'thing';
expect(getElementOrRef(ref)).toBe(null);
});

0 comments on commit 3b5d594

Please sign in to comment.