Skip to content

Commit

Permalink
feat: provide region role to panes
Browse files Browse the repository at this point in the history
  • Loading branch information
smeijer committed Mar 27, 2024
1 parent 84812c8 commit 83a219b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/modern-flowers-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@darkmagic/react': patch
---

provide 'region' role to panes
19 changes: 18 additions & 1 deletion packages/react/src/components/pane.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useComposedRefs } from '@radix-ui/react-compose-refs';
import * as DialogPrimitive from '@radix-ui/react-dialog';
import { EnterFullScreenIcon, ExitFullScreenIcon } from '@radix-ui/react-icons';
import { useId } from '@radix-ui/react-id';
import * as React from 'react';
import { isElement } from 'react-is';
import { createHtmlPortalNode, InPortal, OutPortal } from 'react-reverse-portal';
Expand Down Expand Up @@ -293,6 +294,7 @@ const Root = React.forwardRef<React.ElementRef<typeof StyledPane>, PaneProps>(fu
{ children, expandable = false, variant = 'nested', width = 'auto', drawer, ...props },
forwardedRef,
) {
const id = useId();
const [expanded, setExpanded] = React.useState(false);
const portalNode = React.useMemo(() => {
if (typeof document === 'undefined') return null;
Expand Down Expand Up @@ -326,6 +328,8 @@ const Root = React.forwardRef<React.ElementRef<typeof StyledPane>, PaneProps>(fu

const title = (
<Typography
// don't override the id provided by the drawer.title
{...(drawer ? {} : { id })}
as={variant === 'root' ? 'h1' : 'h2'}
variant="h2"
color="default"
Expand All @@ -336,8 +340,21 @@ const Root = React.forwardRef<React.ElementRef<typeof StyledPane>, PaneProps>(fu
</Typography>
);

const aria = {
'aria-labelledby': id,
role: 'region',
};

const pane = (
<StyledPane {...props} width={width} variant={variant} expanded={expanded} ref={composedRefs}>
<StyledPane
{...props}
// wrapping dialog provides aria props for drawers
{...(drawer ? {} : aria)}
width={width}
variant={variant}
expanded={expanded}
ref={composedRefs}
>
{hasHeader && (
<StyledHeader variant={headerVariant}>
<StyledHeaderContent variant={headerVariant}>
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export type TypographyProps = {
align?: StyledTypographyProps['align'];
children?: React.ReactNode;
as?: keyof JSX.IntrinsicElements;
id?: string;
};

export const Typography = React.forwardRef<HTMLDivElement, TypographyProps>(function Typography(
Expand Down

0 comments on commit 83a219b

Please sign in to comment.