@@ -25,6 +25,7 @@ import classes from './SelectPanel.module.css'
25
25
import { clsx } from 'clsx'
26
26
import { heightMap } from '../Overlay/Overlay'
27
27
import { debounce } from '@github/mini-throttle'
28
+ import { useResponsiveValue } from '../hooks/useResponsiveValue'
28
29
29
30
// we add a delay so that it does not interrupt default screen reader announcement and queues after it
30
31
const SHORT_DELAY_MS = 500
@@ -170,6 +171,10 @@ export function SelectPanel({
170
171
const [ inputRef , setInputRef ] = React . useState < React . RefObject < HTMLInputElement > | null > ( null )
171
172
const [ listContainerElement , setListContainerElement ] = useState < HTMLElement | null > ( null )
172
173
const [ needsNoItemsAnnouncement , setNeedsNoItemsAnnouncement ] = useState < boolean > ( false )
174
+ const isNarrowScreenSize = useResponsiveValue ( { narrow : true , regular : false , wide : false } , false )
175
+
176
+ const usingModernActionList = useFeatureFlag ( 'primer_react_select_panel_modern_action_list' )
177
+ const usingFullScreenOnNarrow = useFeatureFlag ( 'primer_react_select_panel_fullscreen_on_narrow' )
173
178
174
179
const onListContainerRefChanged : FilteredActionListProps [ 'onListContainerRefChanged' ] = useCallback (
175
180
( node : HTMLElement | null ) => {
@@ -234,6 +239,25 @@ export function SelectPanel({
234
239
] ,
235
240
)
236
241
242
+ // disable body scroll when the panel is open on narrow screens
243
+ useEffect ( ( ) => {
244
+ if ( open && isNarrowScreenSize && usingFullScreenOnNarrow ) {
245
+ const bodyOverflowStyle = document . body . style . overflow || ''
246
+ // If the body is already set to overflow: hidden, it likely means
247
+ // that there is already a modal open. In that case, we should bail
248
+ // so we don't re-enable scroll after the second dialog is closed.
249
+ if ( bodyOverflowStyle === 'hidden' ) {
250
+ return
251
+ }
252
+
253
+ document . body . style . overflow = 'hidden'
254
+
255
+ return ( ) => {
256
+ document . body . style . overflow = bodyOverflowStyle
257
+ }
258
+ }
259
+ } , [ isNarrowScreenSize , open , usingFullScreenOnNarrow ] )
260
+
237
261
useEffect ( ( ) => {
238
262
if ( open ) {
239
263
if ( items . length === 0 && ! ( isLoading || loading ) ) {
@@ -385,9 +409,6 @@ export function SelectPanel({
385
409
}
386
410
}
387
411
388
- const usingModernActionList = useFeatureFlag ( 'primer_react_select_panel_modern_action_list' )
389
- const usingFullScreenOnNarrow = useFeatureFlag ( 'primer_react_select_panel_fullscreen_on_narrow' )
390
-
391
412
const iconForNoticeVariant = {
392
413
info : < InfoIcon size = { 16 } /> ,
393
414
warning : < AlertIcon size = { 16 } /> ,
0 commit comments