diff --git a/.changeset/mighty-ghosts-swim.md b/.changeset/mighty-ghosts-swim.md new file mode 100644 index 00000000000..64c492888c7 --- /dev/null +++ b/.changeset/mighty-ghosts-swim.md @@ -0,0 +1,5 @@ +--- +'@primer/react': patch +--- + +Fix an issue where the scrollable Dialog body could not be focused with the keyboard diff --git a/src/DataTable/Table.tsx b/src/DataTable/Table.tsx index af65ba9aedb..1c3429981fb 100644 --- a/src/DataTable/Table.tsx +++ b/src/DataTable/Table.tsx @@ -11,7 +11,7 @@ import {Column, CellAlignment} from './column' import {UniqueRow} from './row' import {SortDirection} from './sorting' import {useTableLayout} from './useTable' -import {useOverflow} from '../internal/hooks/useOverflow' +import {ScrollableRegion} from '../internal/components/ScrollableRegion' // ---------------------------------------------------------------------------- // Table @@ -662,29 +662,6 @@ const Button = styled.button` } ` -type ScrollableRegionProps = React.PropsWithChildren<{ - 'aria-labelledby'?: string - className?: string -}> - -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 ( - - {children} - - ) -} - export { TableContainer, TableTitle, diff --git a/src/Dialog/Dialog.tsx b/src/Dialog/Dialog.tsx index f5511aea6bd..dbd1190e2e8 100644 --- a/src/Dialog/Dialog.tsx +++ b/src/Dialog/Dialog.tsx @@ -13,6 +13,7 @@ import {FocusKeys} from '@primer/behaviors' import Portal from '../Portal' import {useRefObjectAsForwardedRef} from '../hooks/useRefObjectAsForwardedRef' import {useId} from '../hooks/useId' +import {ScrollableRegion} from '../internal/components/ScrollableRegion' /* Dialog Version 2 */ @@ -324,7 +325,9 @@ const _Dialog = React.forwardRef {header} - {body} + + {body} + {footer} diff --git a/src/internal/components/ScrollableRegion.tsx b/src/internal/components/ScrollableRegion.tsx new file mode 100644 index 00000000000..0600f5cba92 --- /dev/null +++ b/src/internal/components/ScrollableRegion.tsx @@ -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 ( + + {children} + + ) +}