Skip to content

Commit

Permalink
fix(DataTable): add position: relative to scrollable region (#4440)
Browse files Browse the repository at this point in the history
* fix(DataTable): add position: relative to scrollable region

* chore: add changeset

---------

Co-authored-by: Josh Black <joshblack@users.noreply.github.com>
  • Loading branch information
joshblack and joshblack committed Mar 26, 2024
1 parent 8bbb8e5 commit 674437d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/orange-geese-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Update DataTable to avoid layout overflow when visually hidden selectors are used in Table headers
11 changes: 10 additions & 1 deletion packages/react/src/internal/components/ScrollableRegion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ type ScrollableRegionProps = React.PropsWithChildren<{
className?: string
}>

const defaultStyles = {
// When setting overflow, we also set `position: relative` to avoid
// `position: absolute` items breaking out of the container and causing
// scrollabrs on the page. This can occur with common classes like `sr-only`
// and can cause difficult to track down layout issues
position: 'relative',
overflow: 'auto',
}

export function ScrollableRegion({'aria-labelledby': labelledby, children, ...rest}: ScrollableRegionProps) {
const ref = React.useRef(null)
const hasOverflow = useOverflow(ref)
Expand All @@ -19,7 +28,7 @@ export function ScrollableRegion({'aria-labelledby': labelledby, children, ...re
: {}

return (
<Box {...rest} {...regionProps} ref={ref} sx={{overflow: 'auto'}}>
<Box {...rest} {...regionProps} ref={ref} sx={defaultStyles}>
{children}
</Box>
)
Expand Down

0 comments on commit 674437d

Please sign in to comment.