Skip to content

Commit d6757d4

Browse files
authored
Add tabIndex to focusTrap target (#660)
1 parent ce91424 commit d6757d4

File tree

4 files changed

+55
-26
lines changed

4 files changed

+55
-26
lines changed

packages/components/src/Modal/ModalPortal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ export const ModalPortal = forwardRef(
5555
}, [el])
5656

5757
const content = (
58-
<InvisiBox ref={ref} zIndex={CustomizableModalAttributes.zIndex}>
58+
<InvisiBox
59+
ref={ref}
60+
tabIndex={-1}
61+
zIndex={CustomizableModalAttributes.zIndex}
62+
>
5963
{children}
6064
</InvisiBox>
6165
)

packages/components/src/Modal/ModalSurface.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export const ModalSurface: FC<ModalSurfaceProps> = ({
100100
>
101101
<Style
102102
className={`surface-overflow ${className}`}
103-
tabIndex={-1}
104103
surfaceStyles={style as CSSObject}
105104
{...props}
106105
/>

packages/playground/src/Menu/MenuDemo.tsx

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,26 @@ import {
3232
MenuDisclosure,
3333
MenuList,
3434
MenuItem,
35-
ModalContext,
35+
Dialog,
3636
MenuGroup,
3737
Paragraph,
3838
Card,
3939
Flex,
4040
IconButton,
41+
MenuContext,
4142
} from '@looker/components'
43+
import { FlexItem } from '@looker/components/src'
4244
const FancyMenuItem = ({
4345
text,
4446
current,
4547
}: {
4648
text: string
4749
current?: boolean
4850
}) => {
49-
const { closeModal } = useContext(ModalContext)
51+
const { setOpen } = useContext(MenuContext)
5052
const handleClick = () => {
5153
alert(`You picked ${text}`)
52-
closeModal && closeModal()
54+
setOpen && setOpen(false)
5355
}
5456
return (
5557
<MenuItem icon="FavoriteOutline" onClick={handleClick} current={current}>
@@ -60,30 +62,54 @@ const FancyMenuItem = ({
6062

6163
const HoverMenu = () => {
6264
const hoverRef = React.useRef<HTMLDivElement>(null)
65+
const [modalIsOpen, setOpen] = React.useState(false)
66+
function openModal() {
67+
setOpen(true)
68+
}
69+
function closeModal() {
70+
setOpen(false)
71+
}
6372
return (
6473
<Card ref={hoverRef} p="large" raised height="auto">
6574
<Flex justifyContent="space-between">
66-
<Paragraph>
75+
<FlexItem flex={1}>
6776
Hovering in this card will show the button that triggers the menu.
68-
</Paragraph>
69-
<Menu hoverDisclosureRef={hoverRef}>
70-
<MenuDisclosure>
71-
<IconButton
72-
icon="DotsVert"
73-
label="More Options"
74-
aria-haspopup="true"
75-
/>
76-
</MenuDisclosure>
77-
<MenuList compact>
78-
<FancyMenuItem text="Gouda" />
79-
<FancyMenuItem text="Swiss" current />
80-
<MenuGroup compact={false}>
81-
<FancyMenuItem text="Gouda w/ Space" />
82-
<FancyMenuItem text="Swiss w/ Space" />
83-
</MenuGroup>
84-
</MenuList>
85-
</Menu>
77+
</FlexItem>
78+
<FlexItem>
79+
<Menu hoverDisclosureRef={hoverRef}>
80+
<MenuContext.Consumer>
81+
{({ showDisclosure, isOpen }) =>
82+
(showDisclosure || isOpen) && (
83+
<IconButton
84+
icon="AddAlerts"
85+
label="Add Alert"
86+
mr="small"
87+
onClick={openModal}
88+
/>
89+
)
90+
}
91+
</MenuContext.Consumer>
92+
<MenuDisclosure>
93+
<IconButton
94+
icon="DotsVert"
95+
label="More Options"
96+
aria-haspopup="true"
97+
/>
98+
</MenuDisclosure>
99+
<MenuList compact>
100+
<FancyMenuItem text="Gouda" />
101+
<FancyMenuItem text="Swiss" current />
102+
<MenuGroup compact={false}>
103+
<FancyMenuItem text="Gouda w/ Space" />
104+
<FancyMenuItem text="Swiss w/ Space" />
105+
</MenuGroup>
106+
</MenuList>
107+
</Menu>
108+
</FlexItem>
86109
</Flex>
110+
<Dialog isOpen={modalIsOpen} onClose={closeModal}>
111+
<Box p="large">Alert icon should be hidden now.</Box>
112+
</Dialog>
87113
</Card>
88114
)
89115
}

packages/playground/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import { GlobalStyle } from '@looker/components'
2424
import { theme } from '@looker/design-tokens'
2525
import { ThemeProvider } from 'styled-components'
2626

27-
import { TooltipDemo } from './Tooltip/TooltipDemo'
27+
import { MenuDemo } from './Menu/MenuDemo'
2828

2929
const App: React.FC = () => {
3030
return (
3131
<ThemeProvider theme={theme}>
3232
<GlobalStyle />
33-
<TooltipDemo />
33+
<MenuDemo />
3434
</ThemeProvider>
3535
)
3636
}

0 commit comments

Comments
 (0)