Skip to content

Commit

Permalink
[SelectPanel] Fix experimental SelectPanel anchoring behavior (#5593)
Browse files Browse the repository at this point in the history
* Fix experimental SelectPanel anchoring behavior

* Simplify

* Add changeset

* Revert "[Accessibility][Storybook] Add aria-labels to the multiple item progr…"

This reverts commit 65f89fe.

---------

Co-authored-by: Marie Lucca <40550942+francinelucca@users.noreply.github.com>
  • Loading branch information
camertron and francinelucca authored Jan 30, 2025
1 parent 124f88a commit 2b05aad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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
Expand Up @@ -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'

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

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

onCancel: propsOnCancel,
onClearSelection: propsOnClearSelection,
Expand Down Expand Up @@ -228,6 +231,7 @@ const Panel: React.FC<SelectPanelProps> = ({
floatingElementRef: dialogRef,
side: 'outside-bottom',
align: 'start',
...anchoredPositionSettings,
},
[internalOpen, anchorRef.current, dialogRef.current],
)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 2b05aad

Please sign in to comment.