Skip to content

experimental/SelectPanel: Recalculate position when panel opens #4321

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

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
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/curvy-fireants-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

experimental/SelectPanel: Fix anchored position inside a Dialog
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react'
import {SelectPanel} from './SelectPanel'
import {ActionList, ActionMenu, Avatar, Box, Button, Text} from '../../index'
import {ArrowRightIcon, EyeIcon, GitBranchIcon, TriangleDownIcon, GearIcon} from '@primer/octicons-react'
import {Dialog} from '../../drafts'
import {ArrowRightIcon, EyeIcon, GitBranchIcon, TriangleDownIcon, GearIcon, TagIcon} from '@primer/octicons-react'
import data from './mock-story-data'

export default {
Expand Down Expand Up @@ -665,6 +666,47 @@ export const ShortSelectPanel = () => {
)
}

export const InsideSidebar = () => {
const [selectedTag, setSelectedTag] = React.useState<string>()
const [sidebarOpen, setSidebarOpen] = React.useState(false)

return (
<>
<h1>Opening SelectPanel inside a sidebar</h1>

<Button onClick={() => setSidebarOpen(true)}>Open sidebar</Button>
{sidebarOpen && (
<Dialog position="right" title="Sidebar" onClose={() => setSidebarOpen(false)}>
<Box p={3}>
<SelectPanel
title="Choose a tag"
selectionVariant="instant"
onSubmit={() => {
if (!selectedTag) return
data.ref = selectedTag // pretending to persist changes
}}
>
<SelectPanel.Button leadingVisual={TagIcon}>{selectedTag || 'Choose a tag'}</SelectPanel.Button>

<ActionList>
{data.tags.map(tag => (
<ActionList.Item
key={tag.id}
onSelect={() => setSelectedTag(tag.id)}
selected={selectedTag === tag.id}
>
{tag.name}
</ActionList.Item>
))}
</ActionList>
</SelectPanel>
</Box>
</Dialog>
)}
</>
)
}

// ----- Suspense implementation details ----

const cache = new Map()
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/drafts/SelectPanel2/SelectPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const Panel: React.FC<SelectPanelProps> = ({
side: 'outside-bottom',
align: 'start',
},
[anchorRef.current, dialogRef.current],
[internalOpen, anchorRef.current, dialogRef.current],
)

/*
Expand Down