Skip to content
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

[SelectPanel] Fix experimental SelectPanel anchoring behavior #5593

Merged
merged 13 commits into from
Jan 30, 2025
Merged
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/gentle-planets-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Fix experimental SelectPanel anchoring behavior
12 changes: 10 additions & 2 deletions packages/react/src/experimental/SelectPanel2/SelectPanel.tsx
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ import {clsx} from 'clsx'
import {useFeatureFlag} from '../../FeatureFlags'

import classes from './SelectPanel.module.css'
import type {PositionSettings} from '@primer/behaviors'

const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_ga'

@@ -66,6 +67,7 @@ export type SelectPanelProps = {
defaultOpen?: boolean
open?: boolean
anchorRef?: React.RefObject<HTMLButtonElement>
anchoredPositionSettings?: Partial<PositionSettings>

onCancel?: () => void
onClearSelection?: undefined | (() => void)
@@ -89,6 +91,7 @@ const Panel: React.FC<SelectPanelProps> = ({
defaultOpen = false,
open: propsOpen,
anchorRef: providedAnchorRef,
anchoredPositionSettings,

onCancel: propsOnCancel,
onClearSelection: propsOnClearSelection,
@@ -228,6 +231,7 @@ const Panel: React.FC<SelectPanelProps> = ({
floatingElementRef: dialogRef,
side: 'outside-bottom',
align: 'start',
...anchoredPositionSettings,
},
[internalOpen, anchorRef.current, dialogRef.current],
)
@@ -267,7 +271,6 @@ const Panel: React.FC<SelectPanelProps> = ({
border: 'none',
padding: 0,
color: 'fg.default',
'&[open]': {display: 'flex'}, // to fit children

'&[data-variant="anchored"], &[data-variant="full-screen"]': {
margin: 0,
@@ -309,8 +312,13 @@ const Panel: React.FC<SelectPanelProps> = ({
'--max-height': maxHeightValue,
'--position-top': `${position?.top ?? 0}px`,
'--position-left': `${position?.left ?? 0}px`,
visibility: internalOpen ? 'visible' : 'hidden',
display: 'flex',
} as React.CSSProperties)
: undefined
: {
visibility: internalOpen ? 'visible' : 'hidden',
display: 'flex',
}
}
className={enabled ? classes.Overlay : undefined}
{...props}