enes

Exported components

  • Drawer
  • DrawerHeader
  • DrawerBody
  • DrawerFooter

Drawer AI

A Drawer is a panel that slides in from an edge of the viewport, with navigation, settings or a form that adds to the page. It overlays the page or sits inline next to the content.

Default drawer

A modal drawer slides in from the start edge. Press Escape or click outside to close it.

Usage

<script>
  import { Button, Drawer, DrawerHeader, DrawerBody, DrawerFooter } from 'fluentui-svelte';
  let open = $state(false);
</script>

<Button onclick={() => (open = true)}>Open drawer</Button>
<Drawer bind:open>
  <DrawerHeader title="Default drawer" />
  <DrawerBody>
    <p>Drawer content</p>
  </DrawerBody>
  <DrawerFooter>
    <Button appearance="accent" onclick={() => (open = false)}>Done</Button>
  </DrawerFooter>
</Drawer>

Position

position picks the edge the drawer opens from: start (default), end, top or bottom. Start and end follow the text direction.

Position: start

The drawer slides in from the start edge.

Size

size sets the width, or the height at the top and the bottom: small (320px, default), medium (592px), large (940px), full or any CSS length, such as 30rem or 50%.

Size: small

The presets are 320px, 592px, 940px and the whole viewport. Any CSS length works too.

Floating

floating detaches the drawer from the edge of the viewport, with rounded corners and a shadow, like a dialog. The footer can submit a form in the body through the form attribute.

New contact

Resizable

resizable adds a handle on the inner edge: drag it, or focus it and use the arrow keys. bind:size reads the new size in pixels, to keep it between visits.

Resizable

Drag the inner edge, or focus it and use the arrow keys.

Size: small

Nested drawers

A drawer inside another drawer opens one level above it. Escape and the backdrop close the top level only, and closing a drawer closes the levels inside it. hideBackdrop keeps a second level from dimming the page twice.

Settings

The settings. Escape closes this level only; closing Settings closes it too.

Types and backdrop

type="non-modal" leaves the page behind interactive. type="alert" ignores Escape and clicks outside: one of its actions has to close it. hideBackdrop removes the dimmed backdrop of a modal drawer. action adds buttons before the close button of the header.

Filters

Type: non-modal

Prevent closing

onBeforeClose runs before the drawer closes from within, with the reason: escape, backdrop, close-button or parent. Return false to keep it open, here while the note is not saved.

New note

Inline

type="inline" renders the drawer in the layout, where it pushes the content aside instead of covering it. Put it in a flex container next to the content.

Navigation

Home

Keyboard and accessibility

The overlay drawer is a native dialog: a modal one traps the focus and gives it back to the opener on close. Escape closes it, except an alert. The title of DrawerHeader names the drawer; without a header, name it with aria-label. The inline drawer is a region.

Component Props

Drawer

NameTypeDefaultDescription
ref bindableHTMLDialogElement | HTMLDivElementThe DOM reference of the drawer element.
idstringThe id of the drawer element. Falls back to a generated one.
open bindablebooleanfalseControls the open state of the drawer.
onOpenChange(open: boolean) => voidCalled whenever the drawer opens or closes from within.
type'modal' | 'non-modal' | 'alert' | 'inline''modal'How the drawer behaves once open.
position'start' | 'end' | 'top' | 'bottom''start'The edge the drawer opens from. Start and end follow the text direction.
size bindableDrawerSize | string'small'The width of the drawer, or its height at the top or the bottom: a preset (320px, 592px, 940px, the whole viewport) or any CSS length.
floatingbooleanDetaches the drawer from the edge of the viewport, with rounded corners and a shadow.
hideBackdropbooleanRemoves the dimmed backdrop behind a modal drawer. A click outside still closes it.
resizablebooleanAdds a handle on the inner edge that resizes the drawer with the pointer or the arrow keys.
resizeLabelstring'Resize'The accessible name of the resize handle.
onBeforeClose(reason: DrawerCloseReason) => boolean | voidCalled before the drawer closes from within. Return false to keep it open.
childrenSnippetThe parts of the drawer: a header, a body and a footer.
HTMLAttributes<HTMLElement> without children

DrawerHeader

NameTypeDefaultDescription
ref bindableHTMLElement | nullThe DOM reference of the header element.
titleSnippet | Component | stringThe title of the drawer. A snippet or a component receives the id the drawer is labelled by.
headingLevel1 | 2 | 3 | 4 | 5 | 62The level of the heading that holds a string title, to fit the headings of the page around it.
actionSnippet | ComponentExtra actions rendered before the close button.
hideCloseButtonbooleanRemoves the button that closes the drawer.
closeLabelstring'Close'The accessible name of the close button.
HTMLAttributes<HTMLElement> without children, title

DrawerBody

NameTypeDefaultDescription
ref bindableHTMLDivElement | nullThe DOM reference of the body element.
Element Attributes (div)

DrawerFooter

NameTypeDefaultDescription
ref bindableHTMLElement | nullThe DOM reference of the footer element.
Element Attributes

Support Fluent UI Svelte

The library is built by one person in their free time. If it helps your work, consider sponsoring it.