Skip to content

Commit

Permalink
base directly on top of 28.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
VanAnderson committed May 18, 2021
1 parent 2c3fc9e commit 2ec6c7b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,14 @@ const Buttons: React.FC<{buttons: DialogButtonProps[]}> = ({buttons}) => {
const autoFocusRef = useRef<HTMLButtonElement>(null)
let autoFocusCount = 0
useEffect(() => {
if (autoFocusRef.current) {
autoFocusRef.current.focus()
}
// hack to work around dialogs originating from other focus traps.
setTimeout(() => {
if (autoFocusRef.current) {
autoFocusRef.current.focus()
}
})
}, [])

return (
<>
{buttons.map((dialogButtonProps, index) => {
Expand Down
25 changes: 25 additions & 0 deletions src/stories/ConfirmationDialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Meta} from '@storybook/react'

import {BaseStyles, Button, Flex, ThemeProvider, useTheme} from '..'
import {ConfirmationDialog, useConfirm} from '../Dialog/ConfirmationDialog'
import {ActionMenu} from '../ActionMenu'

export default {
title: 'Internal components/ConfirmationDialog',
Expand Down Expand Up @@ -78,3 +79,27 @@ export const ShorthandHook = () => {
</Flex>
)
}

export const ShorthandHookFromActionMenu = () => {
const confirm = useConfirm()
const [text, setText] = useState('open me')
const onButtonClick = useCallback(async () => {
if (await confirm({title: 'Are you sure?', content: 'Do you really want to do a trick?'})) {
setText('tada!')
}
}, [confirm])

return (
<Flex flexDirection="column" alignItems="flex-start">
<ActionMenu
renderAnchor={props => <Button {...props}>{text}</Button>}
items={[
{
text: 'Do a trick!',
onAction: onButtonClick
}
]}
/>
</Flex>
)
}

0 comments on commit 2ec6c7b

Please sign in to comment.