enes

Dialog

Is a window overlaid on either the primary window or another dialog window. Windows under a modal dialog are inert. That is, users cannot interact with content outside an active dialog window. Inert content outside an active dialog is typically visually obscured or dimmed so it is difficult to discern, and in some implementations, attempts to interact with the inert content cause the dialog to close.

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>

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.

Dialog Props

NameTypeDescription
type'modal' | 'non-modal' | 'alert'The behavior type of the dialog. Default: `modal`.
openbindable booleanWhether the dialog is open.
onOpenChange(open: boolean) => voidCallback fired when the dialog opens or closes.
childrenSnippetThe dialog sub-components to render.

DialogTrigger Props

NameTypeDescription
refHTMLButtonElementThe DOM reference of the trigger button.
childrenSnippetThe content of the trigger button.
…ButtonPropsButtonProps<'button'>Inherits all `Button` props.

DialogSurface Props

NameTypeDescription
refbindable HTMLDialogElementThe DOM reference of the dialog element.
childrenSnippetThe content to render inside the dialog surface.
…AttributesHTMLAttributes<HTMLDialogElement>All native `<dialog>` attributes are forwarded.

DialogTitle Props

NameTypeDescription
as'div' | 'h1''h6'The element to render the title as. Default: `h3`.
refbindable elementThe DOM reference of the title element.
childrenSnippetThe title content.
…AttributesPolymorphicAll HTML attributes of the chosen `as` element are forwarded.

DialogContent Props

NameTypeDescription
refHTMLDivElementThe DOM reference of the content element.
childrenSnippetThe content to render inside the dialog body.
…AttributesHTMLAttributes<HTMLDivElement>All native `<div>` attributes are forwarded.

DialogActions Props

NameTypeDescription
refbindable HTMLDivElementThe DOM reference of the actions element.
position'start' | 'center' | 'end'Horizontal alignment of the actions. Default: `end`.
fluidbooleanWhether the actions container uses a full-width layout.
childrenSnippetThe action elements to render, typically buttons.
…AttributesHTMLAttributes<HTMLDivElement>All native `<div>` attributes are forwarded.