Skip to content

Commit

Permalink
recalculate position on open
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthkp committed Feb 28, 2024
1 parent ea44386 commit 05c2d4e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
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

0 comments on commit 05c2d4e

Please sign in to comment.