-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pagelayout stories axe violations (#3012)
* Adding tabIndex to pane and content in CustomStickyHeader story to fix scrollable region issue. * Add role=region, tabIndex and required aria-label when pane overflows. * Fix theme-preval snapshot. * Create wild-snakes-fetch.md * Add additional aria-labels to fix errors in other PageLayout stories. * Update docs. * Update generated/components.json * Add useOverflow hook, fix broken story missing aria-label. --------- Co-authored-by: radglob <radglob@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@primer/react": minor | ||
--- | ||
|
||
Adds `tabIndex` and `role="region"` to `PageLayout.Pane` when overflow is detected (scrollHeight > clientHeight). Also requires either `aria-labelledby` or `aria-label` when overflow is detected, and throws an error if neither is defined. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {useEffect, useState} from 'react' | ||
|
||
export function useOverflow<T extends HTMLElement>(ref: React.RefObject<T>) { | ||
const [hasOverflow, setHasOverflow] = useState(false) | ||
|
||
useEffect(() => { | ||
if (ref.current === null) return | ||
|
||
const observer = new ResizeObserver(entries => { | ||
for (const entry of entries) { | ||
setHasOverflow( | ||
entry.target.scrollHeight > entry.target.clientHeight || entry.target.scrollWidth > entry.target.clientWidth, | ||
) | ||
} | ||
}) | ||
|
||
observer.observe(ref.current) | ||
return () => { | ||
observer.disconnect() | ||
} | ||
}, [ref]) | ||
|
||
return hasOverflow | ||
} |