enes

TitleBar

A title bar is the top bar of an app shell, laid out like the one of a Windows 11 app: the identity of the app and its navigation at the start, a search that grows and shrinks at the center, and the person picture and window controls at the end. It paints no background of its own, since it sits on the component that renders the window.

FluentUI App PREVIEW

To create a title bar, you will need to use the following components:

  • TitleBar: The root component. It lays the three areas out, keeps the search between its width limits and collapses it when asked.
  • TitleBarLeftControls: The controls at the start of the bar: a back button, a global navigation button, and the icon, the name and the release tag of the app.
  • TitleBarRightControls: The controls at the end of the bar: custom menus, the person picture, and the minimize, maximize and close buttons of the window.

Usage

Compose the bar from its three areas through the leftControls, search and rightControls snippets. Every area is optional. TitleBarLeftControls and TitleBarRightControls follow the settings of the bar when they are rendered inside a TitleBar, and also work on their own. The window buttons only report the press, since minimizing, maximizing and closing the window is up to the host of your app.

<script>
	import { TitleBar, TitleBarLeftControls, TitleBarRightControls } from 'fluentui-svelte';
	import { AppsRegular } from 'fluentui-icons-svelte';
	import { getCurrentWindow } from '@tauri-apps/api/window';

	const appWindow = getCurrentWindow();
	let maximized = $state(false);
	appWindow.isMaximized().then((value) => (maximized = value));
</script>

<TitleBar>
	{#snippet leftControls()}
		<TitleBarLeftControls back globalNav appIcon={AppsRegular} appName="FluentUI App" releaseTag="PREVIEW" />
	{/snippet}
	{#snippet rightControls()}
		<TitleBarRightControls
			{maximized}
			personPic={{ name: 'Ada Lovelace' }}
			onMinimize={() => appWindow.minimize()}
			onWindowToggle={async () => {
				await appWindow.toggleMaximize();
				maximized = await appWindow.isMaximized();
			}}
			onClose={() => appWindow.close()}
		/>
	{/snippet}
</TitleBar>

Left Controls

back and globalNav show a button each and report the press through onBack and onGlobalNav. Set globalNavExpanded while the navigation is open, or pass a snippet to globalNav to draw the button yourself.

FluentUI App

App Icon

appIcon takes the URL of an image, a Fluent icon component, or a snippet that draws a custom SVG. It is decorative, so the name of the app is what identifies it.

Image URL
Fluent icon
Custom SVG

Release Tag

releaseTag marks the release status of the app, such as PREVIEW or BETA, in a badge next to its name. It takes a string or a snippet.

FluentUI App PREVIEW
FluentUI App BETA

Search

The search snippet sits at the center of the bar and takes up the width the bar gives it, growing and shrinking with the window. A bar with a search is tall by default, which leaves the search room to breathe.

Search Width

searchMinWidth and searchMaxWidth set how far the search shrinks and grows. Numbers are pixel values converted to rem using the current root font size, with a 16px fallback during SSR. For example, 200 becomes 10rem at a 20px root and still renders as 200px. A string is any CSS length.

Collapsed Search

searchCollapsed manually folds the search into a button; resizing does not collapse it automatically. Pressing the button expands the search and moves the focus into the first available control. Bind it to follow the state. Leave enough room for the expanded search and the side controls, or lower searchMinWidth. Long app names are truncated, but navigation and window buttons still need room.

Window Controls

hideMinimize, hideWindowToggle and hideClose each take a window button out of the bar. onMinimize, onWindowToggle and onClose report the press.

Maximized

While maximized is set, the maximize button becomes a restore button, with the icon and the label that go with it.

Person Picture

personPic takes the props of an Avatar, such as its image, drawn at 24 pixels unless you set a size. Add onPersonPicClick to turn the picture into a button, such as the one that opens an account.

Custom Menu

The customMenu snippet places your own actions before the person picture, such as a settings menu.

Labels

The accessible names of the buttons default to English. Pass backLabel, globalNavLabel, searchLabel, minimizeLabel, maximizeLabel, restoreLabel and closeLabel to translate them.

Tab Order

The buttons of the bar are in the tab order by default. Set tabbable to false only when a desktop host provides an alternative keyboard route to these actions. The content you place in the snippets keeps its own tab order.

FluentUI App

Drag Region

dragRegionProps is spread on the bar, its start and end areas, and the app identity, so a host that moves the window can tell where to grab the bar. Use data-tauri-drag-region for Tauri, or a pointer handler for any other host.

<TitleBar dragRegionProps={{ 'data-tauri-drag-region': true }}>
	...
</TitleBar>

<TitleBar dragRegionProps={{ onpointerdown: (e) => e.target === e.currentTarget && appWindow.startDragging() }}>
	...
</TitleBar>

Component Props (TitleBar)

NameTypeDefaultDescription
ref bindableHTMLElement | nullThe DOM reference of the title bar element.
leftControlsSnippetThe controls at the start of the bar: back, navigation, and the identity of the app. Render a TitleBarLeftControls here.
searchSnippetThe search at the center of the bar, which grows and shrinks with the window between searchMinWidth and searchMaxWidth.
rightControlsSnippetThe controls at the end of the bar: custom menus, the person picture, and the window buttons. Render a TitleBarRightControls here.
tallbooleanUses the tall bar, which leaves a search room to breathe. It is on by default when search is provided.
searchMinWidthnumber | string200The narrowest the search gets while the window shrinks. A number is in pixels, converted to rem using the current root font size, with a 16px fallback during SSR. A string is any CSS length.
searchMaxWidthnumber | string480The widest the search gets while the window grows. A number is in pixels, converted to rem using the current root font size, with a 16px fallback during SSR. A string is any CSS length.
searchCollapsed bindablebooleanfalseManually collapses the search into a button; it does not collapse automatically on resize. Pressing the button expands the search again and moves the focus into the first available control. The host must leave enough room for the expanded search and the side controls.
searchLabelstring'Search'The accessible name of the button that stands in for a collapsed search.
tabbablebooleantrueLets the Tab key reach the buttons of the bar. Set to false only when the desktop host provides an alternative keyboard route to these actions. The content you render in the snippets is not affected.
dragRegionPropsHTMLAttributesThe attributes that make the bar draggable for the host that moves the window, such as data-tauri-drag-region for Tauri. They are spread on the bar, its start and end areas, and the app identity.
HTMLAttributes<HTMLElement> without children

Component Props (TitleBarLeftControls)

NameTypeDefaultDescription
ref bindableHTMLDivElement | nullThe DOM reference of the controls element.
backbooleanfalseShows the back button.
backDisabledbooleanfalseDisables the back button, for when there is nowhere to go back to.
onBackMouseEventHandler<HTMLButtonElement>Called when the back button is pressed.
backLabelstring'Back'The accessible name of the back button.
globalNavboolean | SnippetfalseShows the global navigation button, or replaces it with the snippet you provide.
globalNavExpandedbooleanfalseWhether the navigation the global navigation button controls is expanded. Inside an AppWindow with a SideNav, it follows the SideNav and the button expands and collapses it.
onGlobalNavMouseEventHandler<HTMLButtonElement>Called when the global navigation button is pressed. Call preventDefault() to keep it from toggling the SideNav of the window.
globalNavLabelstring'Navigation menu'The accessible name of the global navigation button.
appIconstring | Snippet | ComponentThe icon of the app: the URL of an image, an icon component, or a snippet that draws a custom SVG.
appIconLabelstring'Application'The accessible name of the app icon when appName is absent. Set it to the app's name for an icon-only identity.
appNamestringThe name of the app.
releaseTagstring | SnippetThe release status of the app, such as PREVIEW or BETA.
childrenSnippetMore content after the release tag, such as a subtitle.
HTMLAttributes<HTMLDivElement> without children

Component Props (TitleBarRightControls)

NameTypeDefaultDescription
ref bindableHTMLDivElement | nullThe DOM reference of the controls element.
hideMinimizebooleanfalseHides the minimize button.
hideWindowTogglebooleanfalseHides the maximize and restore button.
hideClosebooleanfalseHides the close button.
maximizedbooleanfalseWhether the window is maximized, which turns the maximize button into a restore button. Inherits AppWindow's maximized state when omitted, or false when standalone.
onMinimizeMouseEventHandler<HTMLButtonElement>Called when the minimize button is pressed.
onWindowToggleMouseEventHandler<HTMLButtonElement>Called when the maximize or restore button is pressed.
onCloseMouseEventHandler<HTMLButtonElement>Called when the close button is pressed.
minimizeLabelstring'Minimize'The accessible name of the minimize button.
maximizeLabelstring'Maximize'The accessible name of the maximize button.
restoreLabelstring'Restore'The accessible name of the restore button.
closeLabelstring'Close'The accessible name of the close button.
personPicAvatarPropsThe props of the Avatar that shows the person. Its size is 24 unless you set one.
onPersonPicClickMouseEventHandler<HTMLButtonElement>Called when the person picture is pressed, which turns it into a button.
customMenuSnippetThe custom menus or actions placed before the person picture.
HTMLAttributes<HTMLDivElement> without children
Edit this Doc View as Markdown