Skip to content
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/beige-crews-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

ActionBar: Overflow menu items should be able to trigger dialogs
46 changes: 45 additions & 1 deletion packages/react/src/drafts/ActionBar/ActionBar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import {
ListUnorderedIcon,
ListOrderedIcon,
TasklistIcon,
ReplyIcon,
} from '@primer/octicons-react'
import {MarkdownInput} from '../MarkdownEditor/_MarkdownInput'
import {ViewSwitch} from '../MarkdownEditor/_ViewSwitch'
import type {MarkdownViewMode} from '../MarkdownEditor/_ViewSwitch'
import {Box} from '../..'
import {Box, Dialog, Button} from '../..'
import {Divider} from '../../deprecated/ActionList/Divider'

export default {
title: 'Drafts/Components/ActionBar',
Expand Down Expand Up @@ -59,6 +61,8 @@ export const CommentBox = () => {
//console.log('loadPreview')
}, [])
const [value, setValue] = React.useState('')
const [isOpen, setIsOpen] = React.useState(false)
const buttonRef = React.useRef(null)
return (
<Box
sx={{
Expand Down Expand Up @@ -106,6 +110,12 @@ export const CommentBox = () => {
<ActionBar.IconButton icon={ListUnorderedIcon} aria-label="Unordered List"></ActionBar.IconButton>
<ActionBar.IconButton icon={ListOrderedIcon} aria-label="Ordered List"></ActionBar.IconButton>
<ActionBar.IconButton icon={TasklistIcon} aria-label="Task List"></ActionBar.IconButton>
<ActionBar.IconButton
ref={buttonRef}
onClick={() => setIsOpen(true)}
icon={ReplyIcon}
aria-label="Saved Replies"
></ActionBar.IconButton>
</ActionBar>
</Box>
</Box>
Expand All @@ -122,6 +132,40 @@ export const CommentBox = () => {
monospace={false}
pasteUrlsAsPlainText={false}
/>
<Dialog aria-labelledby="header" returnFocusRef={buttonRef} isOpen={isOpen} onDismiss={() => setIsOpen(false)}>
<Dialog.Header id="header">Select a reply</Dialog.Header>
<Box p={3}>Show saved replies</Box>
<Divider />
<Button variant="invisible">Create your own saved reply</Button>
</Dialog>
</Box>
)
}

export const ActionBarWithMenuTrigger = () => {
const [isOpen, setIsOpen] = React.useState(false)
const buttonRef = React.useRef(null)

return (
<Box>
<ActionBar>
<ActionBar.IconButton icon={BoldIcon} aria-label="Bold"></ActionBar.IconButton>
<ActionBar.IconButton icon={ItalicIcon} aria-label="Italic"></ActionBar.IconButton>
<ActionBar.IconButton icon={CodeIcon} aria-label="Code"></ActionBar.IconButton>
<ActionBar.IconButton
ref={buttonRef}
onClick={() => setIsOpen(true)}
icon={ReplyIcon}
aria-label="Saved Replies"
></ActionBar.IconButton>
</ActionBar>

<Dialog aria-labelledby="header" returnFocusRef={buttonRef} isOpen={isOpen} onDismiss={() => setIsOpen(false)}>
<Dialog.Header id="header">Select a reply</Dialog.Header>
<Box p={3}>Show saved replies</Box>
<Divider />
<Button variant="invisible">Create your own saved reply</Button>
</Dialog>
</Box>
)
}
4 changes: 2 additions & 2 deletions packages/react/src/drafts/ActionBar/ActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export const ActionBar: React.FC<React.PropsWithChildren<ActionBarProps>> = prop
const {
children: menuItemChildren,
//'aria-current': ariaCurrent,
onSelect,
onClick,
icon: Icon,
'aria-label': ariaLabel,
} = menuItem.props
Expand All @@ -293,7 +293,7 @@ export const ActionBar: React.FC<React.PropsWithChildren<ActionBarProps>> = prop
) => {
closeOverlay()
focusOnMoreMenuBtn()
typeof onSelect === 'function' && onSelect(event)
typeof onClick === 'function' && onClick(event)
}}
>
{Icon ? (
Expand Down