enes

Dialog

A dialog is a window overlaid on either the primary window or another dialog window.

Dialog Title

Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, voluptates.

The Dialog is composed of several components that work together through a shared context:

  • Dialog: The root component that creates the state and provides context to its children.
  • DialogTrigger: A button that opens the dialog when clicked.
  • DialogSurface: The <dialog> element that hosts the dialog content.
  • DialogTitle: The heading of the dialog. Renders as an h3 by default.
  • DialogContent: The scrollable body of the dialog.
  • DialogActions: The footer that holds action buttons.

Usage

<script>
	import {
		Dialog,
		DialogTrigger,
		DialogSurface,
		DialogTitle,
		DialogContent,
		DialogActions,
		Button
	} from 'fluentui-svelte';

	let dialog = $state();
</script>

<Dialog bind:this={dialog}>
	<DialogTrigger>Open Dialog</DialogTrigger>
	<DialogSurface>
		<DialogTitle>Dialog Title</DialogTitle>
		<DialogContent>
			<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
		</DialogContent>
		<DialogActions fluid>
			<Button>Save</Button>
			<Button appearance="standard" onclick={() => dialog.closeDialog()}>Close</Button>
		</DialogActions>
	</DialogSurface>
</Dialog>

Position

Combine top, middle, or bottom with start, center, or end to position the dialog in the viewport. The default is middle-center. Start and end follow the text direction; all positions keep a 1rem gap from viewport edges.

top-start

Dialog body content.

top-center

Dialog body content.

top-end

Dialog body content.

middle-start

Dialog body content.

middle-center

Dialog body content.

middle-end

Dialog body content.

bottom-start

Dialog body content.

bottom-center

Dialog body content.

bottom-end

Dialog body content.

Entrance and exit motion

Choose fade, zoom, slide, or a subtle bounce for both entrance and exit. Duration accepts a theme name such as normal, a CSS variable name such as --fs-fast-duration, or milliseconds as a number. Use 0 to disable motion. Reduced-motion preferences are respected.

fade

Press Escape or click outside the dialog to see its exit transition.

zoom

Press Escape or click outside the dialog to see its exit transition.

slide

Press Escape or click outside the dialog to see its exit transition.

bounce

Press Escape or click outside the dialog to see its exit transition.

With Actions

Add a DialogActions region to render action buttons in the dialog footer. Use bind:this on the Dialog to call closeDialog() programmatically.

Dialog Title

Dialog body content.

Non-modal

A non-modal dialog keeps the page behind it interactive and shows a close button in its corner.

Dialog Title

The page behind this dialog stays interactive.

Alert

An alert dialog is a modal that cannot be dismissed with Escape or by clicking outside of it, so the user has to choose one of its actions.

Discard changes?

Your changes will be lost.

Controlled

Bind open to read and control a non-modal dialog from your own state.

open: false

Controlled Dialog

This dialog follows the bound open state.

On Open Change

Pass onOpenChange to be told whenever the dialog opens or closes: from the trigger, a button that calls closeDialog(), Escape, or a click outside.

Dialog Title

Close it with Escape, by clicking outside or with the button.

No changes yet

Dialog Props

NameTypeDefaultDescription
type'modal' | 'non-modal' | 'alert''modal'How the dialog behaves once open.
positionDialogPosition'middle-center'Where the dialog sits in the viewport. Start and end follow the text direction.
animation'fade' | 'zoom' | 'slide' | 'bounce''zoom'The entrance and exit animation. Bounce uses a subtle overshoot.
durationDialogDuration'normal'Duration in milliseconds, a theme duration name, or a CSS custom property name. Use 0 for no motion.
open bindableboolean | nullControls the open state of the dialog.
onOpenChange(open: boolean) => voidCalled whenever the dialog opens or closes.
childrenSnippetThe parts of the dialog: a trigger and a surface.

DialogTrigger Props

NameTypeDefaultDescription
ref bindableHTMLButtonElement | nullThe DOM reference of the trigger element.
ButtonProps<'button'>

DialogSurface Props

NameTypeDefaultDescription
ref bindableHTMLDialogElement | nullThe DOM reference of the dialog element.
Element Attributes (dialog)

DialogTitle Props

NameTypeDefaultDescription
ref bindableHTMLDivElement | HTMLHeadingElementThe DOM reference of the title element.
asDialogTitleTag'h3'The HTML element to render the title as.
HTML Attributes

DialogContent Props

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

DialogActions Props

NameTypeDefaultDescription
ref bindableHTMLDivElement | nullThe DOM reference of the actions element.
fluidbooleanStretches every action to share the available width evenly.
position'start' | 'center' | 'end''end'Where the actions sit along the main axis.
Element Attributes (div)
Edit this Doc View as Markdown