Skip to content

Commit 4d92deb

Browse files
fix(AnchoredOverlay): Remove use of useResponsiveValue (#7098)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 17c6318 commit 4d92deb

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

packages/react/src/AnchoredOverlay/AnchoredOverlay.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {useFocusZone} from '../hooks/useFocusZone'
99
import {useAnchoredPosition, useProvidedRefOrCreate, useRenderForcingRef} from '../hooks'
1010
import {useId} from '../hooks/useId'
1111
import type {AnchorPosition, PositionSettings} from '@primer/behaviors'
12-
import {useResponsiveValue, type ResponsiveValue} from '../hooks/useResponsiveValue'
12+
import {type ResponsiveValue} from '../hooks/useResponsiveValue'
1313
import {IconButton, type IconButtonProps} from '../Button'
1414
import {XIcon} from '@primer/octicons-react'
1515
import classes from './AnchoredOverlay.module.css'
@@ -225,8 +225,6 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
225225
})
226226
useFocusTrap({containerRef: overlayRef, disabled: !open || !position, ...focusTrapSettings})
227227

228-
const currentResponsiveVariant = useResponsiveValue(variant, 'anchored')
229-
230228
const showXIcon = onClose && variant.narrow === 'fullscreen' && displayCloseButton
231229
const XButtonAriaLabelledBy = closeButtonProps['aria-labelledby']
232230
const XButtonAriaLabel = closeButtonProps['aria-label']
@@ -253,13 +251,13 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
253251
visibility={position ? 'visible' : 'hidden'}
254252
height={height}
255253
width={width}
256-
top={currentResponsiveVariant === 'anchored' ? position?.top || 0 : undefined}
257-
left={currentResponsiveVariant === 'anchored' ? position?.left || 0 : undefined}
254+
top={position?.top || 0}
255+
left={position?.left || 0}
258256
responsiveVariant={variant.narrow === 'fullscreen' ? 'fullscreen' : undefined}
259-
data-variant={currentResponsiveVariant}
260257
anchorSide={position?.anchorSide}
261258
className={className}
262259
preventOverflow={preventOverflow}
260+
data-component="AnchoredOverlay"
263261
{...overlayProps}
264262
ref={node => {
265263
if (overlayProps?.ref) {

packages/react/src/AnchoredOverlay/__snapshots__/AnchoredOverlay.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ exports[`AnchoredOverlay > should render consistently when open 1`] = `
4141
>
4242
<div
4343
class="prc-Overlay-Overlay-ViJgm"
44+
data-component="AnchoredOverlay"
4445
data-focus-trap="active"
4546
data-height-auto=""
46-
data-variant="anchored"
4747
data-visibility-visible=""
4848
data-width-auto=""
4949
role="none"
50-
style="left: 0px; top: 36px;"
50+
style="--top: 36px; --left: 0px;"
5151
>
5252
<span
5353
aria-hidden="true"

packages/react/src/Overlay/Overlay.module.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
background-color: var(--overlay-bgColor);
2020
border-radius: var(--borderRadius-large);
2121
box-shadow: var(--shadow-floating-small);
22+
/* stylelint-disable-next-line primer/spacing */
23+
top: var(--top, auto);
24+
/* stylelint-disable-next-line primer/spacing */
25+
left: var(--left, auto);
26+
/* stylelint-disable-next-line primer/spacing */
27+
right: var(--right, auto);
28+
/* stylelint-disable-next-line primer/spacing */
29+
bottom: var(--bottom, auto);
2230

2331
&:focus {
2432
outline: none;

packages/react/src/Overlay/Overlay.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ export const BaseOverlay = React.forwardRef(
113113
ref={forwardedRef}
114114
style={
115115
{
116-
left,
117-
right,
118-
top,
119-
bottom,
116+
'--top': typeof top === 'number' ? `${top}px` : top,
117+
'--left': typeof left === 'number' ? `${left}px` : left,
118+
'--right': typeof right === 'number' ? `${right}px` : right,
119+
'--bottom': typeof bottom === 'number' ? `${bottom}px` : bottom,
120120
position,
121121
...styleFromProps,
122122
} as React.CSSProperties

packages/react/src/experimental/SelectPanel2/SelectPanel.module.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
}
2626
}
2727

28+
&:where([data-variant='modal']) {
29+
top: 0;
30+
left: 0;
31+
right: 0;
32+
bottom: 0;
33+
}
34+
2835
&:where([data-variant='modal'])::backdrop {
2936
background-color: var(--overlay-backdrop-bgColor);
3037
}

0 commit comments

Comments
 (0)