-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow keyboard navigation to dialog's scroll region (#4000)
* move ScrollableRegion to its own internal component * use scrollable region in dialog body * changeset * Update src/internal/components/ScrollableRegion.tsx Co-authored-by: Josh Black <joshblack@github.com> * Revert "Update src/internal/components/ScrollableRegion.tsx" This reverts commit 37d3231. --------- Co-authored-by: Josh Black <joshblack@github.com>
- Loading branch information
1 parent
cf22577
commit a416298
Showing
4 changed files
with
36 additions
and
25 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': patch | ||
--- | ||
|
||
Fix an issue where the scrollable Dialog body could not be focused with the keyboard |
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,26 @@ | ||
import React from 'react' | ||
import Box from '../../Box' | ||
import {useOverflow} from '../hooks/useOverflow' | ||
|
||
type ScrollableRegionProps = React.PropsWithChildren<{ | ||
'aria-labelledby'?: string | ||
className?: string | ||
}> | ||
|
||
export function ScrollableRegion({'aria-labelledby': labelledby, children, ...rest}: ScrollableRegionProps) { | ||
const ref = React.useRef(null) | ||
const hasOverflow = useOverflow(ref) | ||
const regionProps = hasOverflow | ||
? { | ||
'aria-labelledby': labelledby, | ||
role: 'region', | ||
tabIndex: 0, | ||
} | ||
: {} | ||
|
||
return ( | ||
<Box {...rest} {...regionProps} ref={ref} sx={{overflow: 'auto'}}> | ||
{children} | ||
</Box> | ||
) | ||
} |