Skip to content
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

docs(AnchoredOverlay): add role, aria-label and aria-modal to stories #5184

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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {useEffect, useRef, useState} from 'react'
import type {Args, Meta} from '@storybook/react'
import {FocusKeys} from '@primer/behaviors'

import {Avatar, Box, Text} from '..'
import {Avatar, Box, Link, Text} from '..'
import {AnchoredOverlay} from '../AnchoredOverlay'
import Heading from '../Heading'
import Octicon from '../Octicon'
Expand All @@ -26,7 +26,9 @@ const hoverCard = (
<Stack direction="horizontal" gap="none">
<Text weight="medium">monalisa</Text>
<Text color={'var(--fgColor-muted)'} ml={1}>
Monalisa Octocat
<Link inline underline muted href="#">
Monalisa Octocat
</Link>
</Text>
</Stack>
<Text size="medium">Former beach cat and champion swimmer. Now your friendly octapus with a normal face.</Text>
Expand Down Expand Up @@ -101,6 +103,8 @@ export const CustomAnchorId = () => {
onClose={() => setOpen(false)}
renderAnchor={props => <Button {...props}>Button</Button>}
anchorId="my-custom-anchor-id"
overlayProps={{role: 'dialog', 'aria-modal': true, 'aria-label': 'User Card Overlay'}}
focusZoneSettings={{disabled: true}}
>
<Box sx={{width: '100%', height: '100%', display: 'flex', flexDirection: 'column'}}>{hoverCard}</Box>
</AnchoredOverlay>
Expand All @@ -117,6 +121,8 @@ export const Height = () => {
onClose={() => setOpen(false)}
renderAnchor={props => <Button {...props}>Button</Button>}
height="large"
overlayProps={{role: 'dialog', 'aria-modal': true, 'aria-label': 'User Card Overlay'}}
focusZoneSettings={{disabled: true}}
>
<Box sx={{width: '100%', height: '100%', display: 'flex', flexDirection: 'column'}}>{hoverCard}</Box>
</AnchoredOverlay>
Expand All @@ -133,8 +139,19 @@ export const Width = () => {
onClose={() => setOpen(false)}
renderAnchor={props => <Button {...props}>Button</Button>}
width="large"
overlayProps={{role: 'dialog', 'aria-modal': true, 'aria-label': 'User Card Overlay'}}
focusZoneSettings={{disabled: true}}
>
<Box sx={{width: '100%', height: '100%', display: 'flex', flexDirection: 'column'}}>{hoverCard}</Box>
<Box
sx={{
width: '100%',
height: '100%',
display: 'flex',
flexDirection: 'column',
}}
>
{hoverCard}
</Box>
</AnchoredOverlay>
)
}
Expand All @@ -153,6 +170,8 @@ export const AnchorAlignment = () => {
</Button>
)}
align="center"
overlayProps={{role: 'dialog', 'aria-modal': true, 'aria-label': 'User Card Overlay'}}
focusZoneSettings={{disabled: true}}
>
<Box sx={{width: '100%', height: '100%', display: 'flex', flexDirection: 'column'}}>{hoverCard}</Box>
</AnchoredOverlay>
Expand All @@ -169,6 +188,8 @@ export const AnchorSide = () => {
onClose={() => setOpen(false)}
renderAnchor={props => <Button {...props}>Button</Button>}
side="outside-right"
overlayProps={{role: 'dialog', 'aria-modal': true, 'aria-label': 'User Card Overlay'}}
focusZoneSettings={{disabled: true}}
>
<Box sx={{width: '100%', height: '100%', display: 'flex', flexDirection: 'column'}}>{hoverCard}</Box>
</AnchoredOverlay>
Expand All @@ -185,6 +206,8 @@ export const OffsetPositionFromAnchor = () => {
onClose={() => setOpen(false)}
renderAnchor={props => <Button {...props}>Button</Button>}
anchorOffset={100}
overlayProps={{role: 'dialog', 'aria-modal': true, 'aria-label': 'User Card Overlay'}}
focusZoneSettings={{disabled: true}}
>
<Box sx={{width: '100%', height: '100%', display: 'flex', flexDirection: 'column'}}>{hoverCard}</Box>
</AnchoredOverlay>
Expand All @@ -201,6 +224,8 @@ export const OffsetAlignmentFromAnchor = () => {
onClose={() => setOpen(false)}
renderAnchor={props => <Button {...props}>Button</Button>}
alignmentOffset={100}
overlayProps={{role: 'dialog', 'aria-modal': true, 'aria-label': 'User Card Overlay'}}
focusZoneSettings={{disabled: true}}
>
<Box sx={{width: '100%', height: '100%', display: 'flex', flexDirection: 'column'}}>{hoverCard}</Box>
</AnchoredOverlay>
Expand All @@ -218,6 +243,8 @@ export const FocusTrapOverrides = () => {
onClose={() => setOpen(false)}
renderAnchor={props => <Button {...props}>Button</Button>}
focusTrapSettings={{initialFocusRef}}
overlayProps={{role: 'dialog', 'aria-modal': true, 'aria-label': 'Focus Trap Demo Overlay'}}
focusZoneSettings={{disabled: true}}
>
<Button>First button</Button>
<Button ref={initialFocusRef}>Initial focus</Button>
Expand All @@ -235,6 +262,7 @@ export const FocusZoneOverrides = () => {
onClose={() => setOpen(false)}
renderAnchor={props => <Button {...props}>Button</Button>}
focusZoneSettings={{bindKeys: FocusKeys.JK}}
overlayProps={{role: 'dialog', 'aria-modal': true, 'aria-label': 'Focus Zone Demo Overlay'}}
>
<p>
Use <kbd>J</kbd> and <kbd>K</kbd> keys to move focus.
Expand All @@ -258,7 +286,11 @@ export const OverlayPropsOverrides = () => {
overlayProps={{
overflow: 'auto',
maxHeight: 'xsmall',
role: 'dialog',
'aria-modal': true,
'aria-label': 'User Card Overlay',
}}
focusZoneSettings={{disabled: true}}
>
<div>Overlay props have been overridden to set: </div>
<pre>
Expand Down
16 changes: 13 additions & 3 deletions packages/react/src/AnchoredOverlay/AnchoredOverlay.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {useState} from 'react'
import type {Args, Meta} from '@storybook/react'
import {LocationIcon, RepoIcon} from '@primer/octicons-react'

import {Avatar, Text} from '..'
import {Avatar, Link, Text} from '..'
import {AnchoredOverlay} from '../AnchoredOverlay'
import {Button} from '../Button'
import Octicon from '../Octicon'
Expand All @@ -23,7 +23,9 @@ const hoverCard = (
<Stack direction="horizontal" gap="none">
<Text weight="medium">monalisa</Text>
<Text color={'var(--fgColor-muted)'} ml={1}>
Monalisa Octocat
<Link inline underline muted href="#">
Monalisa Octocat
</Link>
</Text>
</Stack>
<Text size="medium">Former beach cat and champion swimmer. Now your friendly octapus with a normal face.</Text>
Expand Down Expand Up @@ -51,6 +53,8 @@ export const Default = () => {
onOpen={() => setOpen(true)}
onClose={() => setOpen(false)}
renderAnchor={props => <Button {...props}>Button</Button>}
overlayProps={{role: 'dialog', 'aria-modal': true, 'aria-label': 'User Card Overlay'}}
focusZoneSettings={{disabled: true}}
>
{hoverCard}
</AnchoredOverlay>
Expand All @@ -74,8 +78,14 @@ export const Playground = (args: Args) => {
width={args.width}
height={args.height}
renderAnchor={props => <Button {...props}>Button</Button>}
overlayProps={args.portalContainerName}
overlayProps={{
...args.portalContainerName,
role: 'dialog',
'aria-modal': true,
'aria-label': 'User Card Overlay',
}}
side={args.side}
focusZoneSettings={{disabled: true}}
>
{hoverCard}
</AnchoredOverlay>
Expand Down
Loading