Dismissable
Closes on Escape or on a press outside, and stays open when the press is inside.
import { Dismissable } from '@sypnia/ui/react'
Press outside to close
Code
import { useState } from 'react';
import { Button, Dismissable } from '@sypnia/ui/react';
// Press outside the box or Escape: it closes. A press inside does not.
export default function Outside() {
const [open, setOpen] = useState(false);
return open ? (
<Dismissable onDismiss={() => setOpen(false)} label="Filters">
<div style={{ padding: 'var(--s-4)', border: '1px solid var(--line-strong)', borderRadius: 'var(--r-3)', maxWidth: '20rem' }}>Press anywhere else, or Escape.</div>
</Dismissable>
) : <Button onClick={() => setOpen(true)}>Open</Button>;
} When to use it
Use it when
- A floating thing of your own that should go away when the person moves on.
Do not use it when
- A decision the person must make: a ConfirmDialog never closes by a press outside.
For everyone
- Escape is the keyboard way out; give the box a name with
label.
Props
| Dismissable | Type | Default |
|---|---|---|
onDismissrequired | () => void | |
active | boolean | true |
className | string | |
label | string |