);
// Removes itself from the DOM when clicked, while it has the focus.
const SelfRemovingButton = () => {
const [isShown, setIsShown] = useState(true);
return isShown ? (
) : null;
};
export const backdrop = () => (
);
export const backdropNoInteractOutside = () => (
);
export const backdropWithSelect = () => (
{ /* Portaled on purpose, unlike the documented `createPortal={ false }` (see the docs
OverlayElements story), to test that interacting with a nested layer is not an outside
interaction: the z-index lifts its list (dropdown layer) above the drawer. */ }
);
export const noBackdrop = () => (
);
export const noBackdropCustomContentId = () => (
);
// Open by default: the opener is body, so the trigger must be found by its owner, whatever its id.
export const noBackdropCustomTriggerId = () => (
);
// Open on mount: zag's machine has started before DrawerContent can give it its id.
export const noBackdropOpenCustomContentId = () => (
);
// The content id changes while the drawer is open, e.g. derived from the item a details drawer shows.
export const noBackdropChangingContentId = () => {
const [item, setItem] = useState(1);
return (
);
};
// A trigger without value next to valued ones, as a header button above one trigger per row.
export const noBackdropValuedTriggers = () => (
Header trigger
{ ['1', '2', '3'].map((row) => (
Row { row }
)) }
);
// A form drawer whose Close button asks for a confirmation in a Modal: Discard closes both.
export const noBackdropNestedModal = () => {
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
const [isModalOpen, setIsModalOpen] = useState(false);
return (
setIsDrawerOpen(open) } open={ isDrawerOpen }>
setIsModalOpen(open) } open={ isModalOpen }>
);
};
// Rendered in a shadow root, next to an input of the page; the drawer is closed by code. The root
// is exposed for the tests, as a closed one cannot be reached from the page.
const ShadowRootDrawer = ({ mode }: { mode: ShadowRootMode }) => {
const hostRef = useRef(null);
const [shadowRoot, setShadowRoot] = useState();
const [isOpen, setIsOpen] = useState(false);
useEffect(() => {
const host = hostRef.current as (HTMLDivElement & { drawerShadowRoot?: ShadowRoot }) | null;
if (host) {
host.drawerShadowRoot ??= host.attachShadow({ mode });
setShadowRoot(host.drawerShadowRoot);
}
}, [mode]);
return (
<>
{
shadowRoot && createPortal(
shadowRoot }>
setIsOpen(false) }>
Close by code
setIsOpen(open) } open={ isOpen }>
,
shadowRoot,
)
}
>
);
};
export const noBackdropInShadowRoot = () => (
);
export const noBackdropInClosedShadowRoot = () => (
);
// An iframe of the page, outside the drawer: a focus inside it fires no event in the page.
export const noBackdropOutsideIframe = () => {
const [isOpen, setIsOpen] = useState(false);
return (
setIsOpen(false) }>
Close by code
setIsOpen(open) } open={ isOpen } />
);
};
// A drawer without trigger, opened without moving the focus (the opener is body), whose Close
// button asks for a confirmation in a Modal: Discard closes both, and nothing can take the focus.
export const noBackdropNestedModalWithoutTrigger = () => {
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
const [isModalOpen, setIsModalOpen] = useState(false);
return (
setIsDrawerOpen(true) }>
Open without focus
setIsDrawerOpen(open) } open={ isDrawerOpen }>
setIsModalOpen(open) } open={ isModalOpen }>
);
};
// A drawer opened from a trigger inside another drawer. A button of the inner drawer closes the
// outer one only, then Escape closes the inner one.
export const noBackdropNestedDrawers = () => {
const [isOuterOpen, setIsOuterOpen] = useState(false);
return (
setIsOuterOpen(open) } open={ isOuterOpen }>
Outer trigger
Inner trigger
);
};
export const noBackdropInteractOutside = () => (
);
export const noBackdropRemovedFocus = () => {
const [isOpen, setIsOpen] = useState(false);
return (
{ /* Clicked by script in the tests, to close the drawer by code without moving the focus. */ }
setIsOpen(false) }>
Close by code
setIsOpen(open) } open={ isOpen }>
);
};
export const noBackdropControlled = () => {
const [isOpen, setIsOpen] = useState(false);
return (
{ /* Opens without moving the focus (as WebKit does when clicking a button): the opener is body. */ }
setIsOpen(true) }>
Open without focus
setIsOpen(open) } open={ isOpen }>
);
};
export const noBackdropClosedByCode = () => {
const [isOpen, setIsOpen] = useState(false);
return (
{ /* Not focusable: closes the drawer by code without moving the focus anywhere but body. */ }
setIsOpen(false) }>
Close by code
setIsOpen(open) } open={ isOpen } />
);
};
// Loads the closed-by-code story in a same-origin iframe, next to an input of the parent page.
export const noBackdropInIframe = () => (
<>
>
);
// Loads the iframe story in an iframe: the drawer is two frames below the page.
export const noBackdropInNestedIframe = () => (
<>
>
);
const NamedDrawer = ({ name }: { name: string }) => (
Trigger { name }
);
export const twoDrawers = () => (
);
export const noEscape = () => (
);