Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tasty-games-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

fix(SelectPanel): disable body scroll on full screen
27 changes: 24 additions & 3 deletions packages/react/src/SelectPanel/SelectPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import classes from './SelectPanel.module.css'
import {clsx} from 'clsx'
import {heightMap} from '../Overlay/Overlay'
import {debounce} from '@github/mini-throttle'
import {useResponsiveValue} from '../hooks/useResponsiveValue'

// we add a delay so that it does not interrupt default screen reader announcement and queues after it
const SHORT_DELAY_MS = 500
Expand Down Expand Up @@ -170,6 +171,10 @@ export function SelectPanel({
const [inputRef, setInputRef] = React.useState<React.RefObject<HTMLInputElement> | null>(null)
const [listContainerElement, setListContainerElement] = useState<HTMLElement | null>(null)
const [needsNoItemsAnnouncement, setNeedsNoItemsAnnouncement] = useState<boolean>(false)
const isNarrowScreenSize = useResponsiveValue({narrow: true, regular: false, wide: false}, false)

const usingModernActionList = useFeatureFlag('primer_react_select_panel_modern_action_list')
const usingFullScreenOnNarrow = useFeatureFlag('primer_react_select_panel_fullscreen_on_narrow')

const onListContainerRefChanged: FilteredActionListProps['onListContainerRefChanged'] = useCallback(
(node: HTMLElement | null) => {
Expand Down Expand Up @@ -234,6 +239,25 @@ export function SelectPanel({
],
)

// disable body scroll when the panel is open on narrow screens
useEffect(() => {
if (open && isNarrowScreenSize && usingFullScreenOnNarrow) {
const bodyOverflowStyle = document.body.style.overflow || ''
// If the body is already set to overflow: hidden, it likely means
// that there is already a modal open. In that case, we should bail
// so we don't re-enable scroll after the second dialog is closed.
if (bodyOverflowStyle === 'hidden') {
return
}

document.body.style.overflow = 'hidden'

return () => {
document.body.style.overflow = bodyOverflowStyle
}
}
}, [isNarrowScreenSize, open, usingFullScreenOnNarrow])

useEffect(() => {
if (open) {
if (items.length === 0 && !(isLoading || loading)) {
Expand Down Expand Up @@ -385,9 +409,6 @@ export function SelectPanel({
}
}

const usingModernActionList = useFeatureFlag('primer_react_select_panel_modern_action_list')
const usingFullScreenOnNarrow = useFeatureFlag('primer_react_select_panel_fullscreen_on_narrow')

const iconForNoticeVariant = {
info: <InfoIcon size={16} />,
warning: <AlertIcon size={16} />,
Expand Down
Loading