Skip to content

Commit a416298

Browse files
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 <[email protected]> * Revert "Update src/internal/components/ScrollableRegion.tsx" This reverts commit 37d3231. --------- Co-authored-by: Josh Black <[email protected]>
1 parent cf22577 commit a416298

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

.changeset/mighty-ghosts-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
Fix an issue where the scrollable Dialog body could not be focused with the keyboard

src/DataTable/Table.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {Column, CellAlignment} from './column'
1111
import {UniqueRow} from './row'
1212
import {SortDirection} from './sorting'
1313
import {useTableLayout} from './useTable'
14-
import {useOverflow} from '../internal/hooks/useOverflow'
14+
import {ScrollableRegion} from '../internal/components/ScrollableRegion'
1515

1616
// ----------------------------------------------------------------------------
1717
// Table
@@ -662,29 +662,6 @@ const Button = styled.button`
662662
}
663663
`
664664

665-
type ScrollableRegionProps = React.PropsWithChildren<{
666-
'aria-labelledby'?: string
667-
className?: string
668-
}>
669-
670-
function ScrollableRegion({'aria-labelledby': labelledby, children, ...rest}: ScrollableRegionProps) {
671-
const ref = React.useRef(null)
672-
const hasOverflow = useOverflow(ref)
673-
const regionProps = hasOverflow
674-
? {
675-
'aria-labelledby': labelledby,
676-
role: 'region',
677-
tabIndex: 0,
678-
}
679-
: {}
680-
681-
return (
682-
<Box {...rest} {...regionProps} ref={ref} sx={{overflow: 'auto'}}>
683-
{children}
684-
</Box>
685-
)
686-
}
687-
688665
export {
689666
TableContainer,
690667
TableTitle,

src/Dialog/Dialog.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {FocusKeys} from '@primer/behaviors'
1313
import Portal from '../Portal'
1414
import {useRefObjectAsForwardedRef} from '../hooks/useRefObjectAsForwardedRef'
1515
import {useId} from '../hooks/useId'
16+
import {ScrollableRegion} from '../internal/components/ScrollableRegion'
1617

1718
/* Dialog Version 2 */
1819

@@ -324,7 +325,9 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP
324325
sx={sx}
325326
>
326327
{header}
327-
{body}
328+
<ScrollableRegion aria-labelledby={dialogLabelId} className="DialogOverflowWrapper">
329+
{body}
330+
</ScrollableRegion>
328331
{footer}
329332
</StyledDialog>
330333
</Backdrop>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react'
2+
import Box from '../../Box'
3+
import {useOverflow} from '../hooks/useOverflow'
4+
5+
type ScrollableRegionProps = React.PropsWithChildren<{
6+
'aria-labelledby'?: string
7+
className?: string
8+
}>
9+
10+
export function ScrollableRegion({'aria-labelledby': labelledby, children, ...rest}: ScrollableRegionProps) {
11+
const ref = React.useRef(null)
12+
const hasOverflow = useOverflow(ref)
13+
const regionProps = hasOverflow
14+
? {
15+
'aria-labelledby': labelledby,
16+
role: 'region',
17+
tabIndex: 0,
18+
}
19+
: {}
20+
21+
return (
22+
<Box {...rest} {...regionProps} ref={ref} sx={{overflow: 'auto'}}>
23+
{children}
24+
</Box>
25+
)
26+
}

0 commit comments

Comments
 (0)