Skip to content

Commit

Permalink
fix(PageLayout): update Pane to warn instead of error (#3160)
Browse files Browse the repository at this point in the history
* fix(PageLayout): update Pane to warn instead of error

* chore: add changeset

* chore: remove invariant

* chore: address eslint violations

---------

Co-authored-by: Josh Black <[email protected]>
  • Loading branch information
2 people authored and radglob committed Apr 20, 2023
1 parent dbb3950 commit b65da55
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-yaks-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Update PageLayout.Pane to provide a warning instead of an error when overflow is detected and no label has been provided
18 changes: 12 additions & 6 deletions src/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {useSlots} from '../hooks/useSlots'
import {BetterSystemStyleObject, merge, SxProp} from '../sx'
import {Theme} from '../ThemeProvider'
import {canUseDOM} from '../utils/environment'
import {invariant} from '../utils/invariant'
import {useOverflow} from '../utils/useOverflow'
import {warning} from '../utils/warning'
import VisuallyHidden from '../_VisuallyHidden'
import {useStickyPaneHeight} from './useStickyPaneHeight'

Expand Down Expand Up @@ -652,13 +652,19 @@ const Pane = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageLayout

const paneId = useId(id)

let labelProp = undefined
const labelProp: {'aria-labelledby'?: string; 'aria-label'?: string} = {}
if (hasOverflow) {
invariant(label !== undefined || labelledBy !== undefined)
warning(
label === undefined && labelledBy === undefined,
'The <PageLayout.Pane> has overflow and `aria-label` or `aria-labelledby` has not been set. ' +
'Please provide `aria-label` or `aria-labelledby` to <PageLayout.Pane> in order to label this ' +
'region.',
)

if (labelledBy) {
labelProp = {'aria-labelledby': labelledBy}
} else {
labelProp = {'aria-label': label}
labelProp['aria-labelledby'] = labelledBy
} else if (label) {
labelProp['aria-label'] = label
}
}

Expand Down

0 comments on commit b65da55

Please sign in to comment.