Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
francinelucca committed Nov 25, 2024
1 parent b7fdfec commit 4ea3678
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
3 changes: 3 additions & 0 deletions e2e/components/Overlay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ test.describe('Overlay ', () => {
globals: {
colorScheme: theme,
},
args: {
open: true,
},
})
await story.setup(page)

Expand Down
35 changes: 20 additions & 15 deletions packages/react/src/Overlay/Overlay.features.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState, useRef, useCallback} from 'react'
import type {Meta} from '@storybook/react'
import type {Args, Meta} from '@storybook/react'
import {TriangleDownIcon, PlusIcon, IssueDraftIcon, XIcon} from '@primer/octicons-react'
import {
Overlay,
Expand Down Expand Up @@ -28,6 +28,7 @@ export default {
args: {
anchorSide: 'inside-top',
role: 'dialog',
open: false,
},
argTypes: {
anchorSide: {
Expand All @@ -49,6 +50,10 @@ export default {
role: {
type: 'string',
},
open: {
control: false,
visible: false,
},
},
} as Meta

Expand All @@ -58,7 +63,7 @@ interface OverlayProps {
right?: boolean
}

export const DropdownOverlay = ({anchorSide}: OverlayProps) => {
export const DropdownOverlay = ({anchorSide, open}: Args) => {
const [isOpen, setIsOpen] = useState(false)
const buttonRef = useRef<HTMLButtonElement>(null)

Expand All @@ -67,7 +72,7 @@ export const DropdownOverlay = ({anchorSide}: OverlayProps) => {
<Button ref={buttonRef} sx={{position: 'relative'}} onClick={() => setIsOpen(!isOpen)}>
open overlay
</Button>
{isOpen ? (
{isOpen || open ? (
<Overlay
returnFocusRef={buttonRef}
height="auto"
Expand All @@ -94,7 +99,7 @@ export const DropdownOverlay = ({anchorSide}: OverlayProps) => {
)
}

export const DialogOverlay = ({anchorSide, role}: OverlayProps) => {
export const DialogOverlay = ({anchorSide, role, open}: Args) => {
const [isOpen, setIsOpen] = useState(false)
const buttonRef = useRef<HTMLButtonElement>(null)
const containerRef = useRef<HTMLDivElement>(null)
Expand All @@ -108,7 +113,7 @@ export const DialogOverlay = ({anchorSide, role}: OverlayProps) => {
<Button ref={buttonRef} onClick={() => setIsOpen(!isOpen)}>
open overlay
</Button>
{isOpen ? (
{isOpen || open ? (
<Overlay
initialFocusRef={confirmButtonRef}
returnFocusRef={buttonRef}
Expand Down Expand Up @@ -137,7 +142,7 @@ export const DialogOverlay = ({anchorSide, role}: OverlayProps) => {
)
}

export const OverlayOnTopOfOverlay = ({anchorSide, role}: OverlayProps) => {
export const OverlayOnTopOfOverlay = ({anchorSide, role, open}: Args) => {
const [isOpen, setIsOpen] = useState(false)
const [isSecondaryOpen, setIsSecondaryOpen] = useState(false)
const buttonRef = useRef<HTMLButtonElement>(null)
Expand All @@ -164,7 +169,7 @@ export const OverlayOnTopOfOverlay = ({anchorSide, role}: OverlayProps) => {
<Button ref={buttonRef} onClick={() => setIsOpen(!isOpen)}>
open overlay
</Button>
{isOpen ? (
{isOpen || open ? (
<Overlay
initialFocusRef={confirmButtonRef}
returnFocusRef={buttonRef}
Expand Down Expand Up @@ -223,7 +228,7 @@ export const OverlayOnTopOfOverlay = ({anchorSide, role}: OverlayProps) => {
)
}

export const MemexNestedOverlays = ({role}: OverlayProps) => {
export const MemexNestedOverlays = ({role, open}: Args) => {
const [overlayOpen, setOverlayOpen] = React.useState(false)
const buttonRef = useRef<HTMLButtonElement>(null)
const containerRef = useRef<HTMLDivElement>(null)
Expand All @@ -243,7 +248,7 @@ export const MemexNestedOverlays = ({role}: OverlayProps) => {
icon={TriangleDownIcon}
/>
</ButtonGroup>
{overlayOpen && (
{(overlayOpen || open) && (
<Overlay
width="auto"
onEscape={() => setOverlayOpen(false)}
Expand Down Expand Up @@ -296,7 +301,7 @@ export const MemexNestedOverlays = ({role}: OverlayProps) => {
)
}

export const NestedOverlays = ({role}: OverlayProps) => {
export const NestedOverlays = ({role, open}: Args) => {
const [listOverlayOpen, setListOverlayOpen] = React.useState(false)
const [createListOverlayOpen, setCreateListOverlayOpen] = React.useState(false)

Expand Down Expand Up @@ -332,7 +337,7 @@ export const NestedOverlays = ({role}: OverlayProps) => {
icon={TriangleDownIcon}
/>
</ButtonGroup>
{listOverlayOpen && (
{(listOverlayOpen || open) && (
<Overlay
width="medium"
onEscape={() => setListOverlayOpen(false)}
Expand Down Expand Up @@ -409,7 +414,7 @@ export const NestedOverlays = ({role}: OverlayProps) => {
)
}

export const MemexIssueOverlay = ({role}: OverlayProps) => {
export const MemexIssueOverlay = ({role, open}: Args) => {
const [overlayOpen, setOverlayOpen] = React.useState(false)
const linkRef = useRef<HTMLAnchorElement>(null)
const inputRef = useRef<HTMLInputElement>(null)
Expand Down Expand Up @@ -448,7 +453,7 @@ export const MemexIssueOverlay = ({role}: OverlayProps) => {
>
<IssueDraftIcon /> {title}
</Link>
{overlayOpen && (
{(overlayOpen || open) && (
<Overlay
height="auto"
width="auto"
Expand Down Expand Up @@ -523,7 +528,7 @@ export const MemexIssueOverlay = ({role}: OverlayProps) => {
)
}

export const PositionedOverlays = ({right, role}: OverlayProps) => {
export const PositionedOverlays = ({right, role, open}: Args) => {
const [isOpen, setIsOpen] = useState(false)
const [direction, setDirection] = useState<'left' | 'right'>(right ? 'right' : 'left')
const buttonRef = useRef<HTMLButtonElement>(null)
Expand Down Expand Up @@ -561,7 +566,7 @@ export const PositionedOverlays = ({right, role}: OverlayProps) => {
>
Open right overlay
</Button>
{isOpen ? (
{isOpen || open ? (
direction === 'left' ? (
<Overlay
initialFocusRef={confirmButtonRef}
Expand Down
17 changes: 14 additions & 3 deletions packages/react/src/Overlay/Overlay.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export default {
},
} as Meta<ComponentProps<typeof Overlay>>

export const Default = () => {
export const Default = (args: Args) => {
const [isOpen, setIsOpen] = useState(false)
const buttonRef = useRef<HTMLButtonElement>(null)
const confirmButtonRef = useRef<HTMLButtonElement>(null)
Expand All @@ -235,7 +235,7 @@ export const Default = () => {
>
Open overlay
</Button>
{isOpen ? (
{isOpen || args.open ? (
<Overlay
initialFocusRef={confirmButtonRef}
returnFocusRef={buttonRef}
Expand Down Expand Up @@ -276,6 +276,15 @@ export const Default = () => {
</Box>
)
}
Default.args = {
open: false,
}
Default.argTypes = {
open: {
control: false,
visible: false,
},
}
export const Playground = (args: Args) => {
const [isOpen, setIsOpen] = useState(false)
const buttonRef = useRef<HTMLButtonElement>(null)
Expand All @@ -297,7 +306,7 @@ export const Playground = (args: Args) => {
>
Open overlay
</Button>
{isOpen ? (
{isOpen || args.open ? (
<Overlay
initialFocusRef={confirmButtonRef}
returnFocusRef={buttonRef}
Expand Down Expand Up @@ -351,6 +360,7 @@ Playground.args = {
preventOverflow: 'false',
role: 'dialog',
visibility: 'visible',
open: false,
}
Playground.argTypes = {
width: {
Expand Down Expand Up @@ -383,6 +393,7 @@ Playground.argTypes = {
},
open: {
control: false,
visible: false,
},
portalContainerName: {
control: false,
Expand Down

0 comments on commit 4ea3678

Please sign in to comment.