Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 677
AnchoredOverlay: Add settings for CSS anchor positioning#7964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@primer/react': minor | ||
| --- | ||
| AnchoredOverlay: Add `cssAnchorPositioningSettings` prop to allow opting out of native CSS anchor positioning (via `disable`), and use it in `SelectPanel` so the `modal` variant stays manually centered instead of being repositioned by CSS anchor positioning. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -124,6 +124,13 @@ interface AnchoredOverlayBaseProps extends Pick<OverlayProps, 'height' | 'width' | ||
| * and the browser supports native CSS anchor positioning. Has no effect otherwise. Defaults to `"portal"`. | ||
| */ | ||
| renderAs?: 'portal' | 'popover' | ||
| /** | ||
| * Settings for native CSS anchor positioning. | ||
| * | ||
| * - `disable`: When `true`, opts this overlay out of native CSS anchor positioning (and the Popover API) | ||
| * even if `primer_react_css_anchor_positioning` is enabled and the browser supports it. | ||
| */ | ||
| cssAnchorPositioningSettings?: {disable?: boolean} | ||
| } | ||
| export type AnchoredOverlayProps = AnchoredOverlayBaseProps & | ||
| @@ -167,6 +174,7 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr | ||
| displayCloseButton = true, | ||
| closeButtonProps = defaultCloseButtonProps, | ||
| renderAs = 'portal', | ||
| cssAnchorPositioningSettings, | ||
| }) => { | ||
| const cssAnchorPositioningFlag = useFeatureFlag('primer_react_css_anchor_positioning') | ||
| // Lazy initial state so feature detection runs once per mount on the client. | ||
| @@ -180,7 +188,10 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr | ||
| ) | ||
| const cssAnchorPositioning = | ||
| cssAnchorPositioningFlag && supportsNativeCSSAnchorPositioning && !overlayProps?.portalContainerName | ||
| cssAnchorPositioningFlag && | ||
| supportsNativeCSSAnchorPositioning && | ||
| !overlayProps?.portalContainerName && | ||
| !cssAnchorPositioningSettings?.disable | ||
TylerJDev marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // Only use Popover API when both CSS anchor positioning is enabled AND renderAs is true | ||
TylerJDev marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const shouldRenderAsPopover = cssAnchorPositioning && renderAs === 'popover' | ||
| const anchorRef = useProvidedRefOrCreate(externalAnchorRef) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -881,6 +881,8 @@ function Panel({ | ||
| displayCloseButton={showXCloseIcon} | ||
| closeButtonProps={closeButtonProps} | ||
| displayInViewport={displayInViewport} | ||
| // Modal variant is positioned manually so native CSS anchor positioning must not be used | ||
| cssAnchorPositioningSettings={{disable: variant === 'modal'}} | ||
TylerJDev marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| > | ||
| <div className={classes.Wrapper} data-variant={variant} data-component="SelectPanel"> | ||
| <div className={classes.Header} data-variant={currentResponsiveVariant} data-component="SelectPanel.Header"> | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.