FloatingNav
A white pill bar. Narrow widths open the same links in a menu panel.
More examples
Narrow width with Menu
Below 640px of component width, Menu opens the same links.
Source
<script lang="ts">
import 'portal-bits/styles.css';
import 'portal-bits/tokens.css';
import type { Snippet } from 'svelte';
let { children }: { children: Snippet } = $props();
</script>
{@render children()}
<script lang="ts">
import FloatingNavExample from './FloatingNavExample.svelte';
</script>
<FloatingNavExample actions={true} />
<script lang="ts">
import { FloatingNav } from 'portal-bits';
let { actions = true }: { actions?: boolean } = $props();
</script>
{#snippet brand()}<a href="#home">Home</a>{/snippet}
{#snippet items()}<a href="#docs" aria-current="page">Docs</a>{/snippet}
{#snippet links()}<a href="https://github.com/AddeyX/portal-bits">GitHub</a>{/snippet}
<FloatingNav label="Example" {brand} {items} actions={actions ? links : undefined} />
API reference
These tables list the props and snippets that FloatingNav declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.
Props
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
label | string | None | Yes | One-way | Names the `nav` landmark. |
open | boolean | false | No | Bindable | Whether the narrow-width menu is open. |
Snippets
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
brand | Snippet | None | Yes | One-way | The leading mark, usually a home link. |
items | Snippet | None | Yes | One-way | The middle links. Each destination is one anchor. |
actions | Snippet | None | No | One-way | An optional trailing group, such as a repository link. |
Forwarded attributes
None. FloatingNav forwards no attributes.
No data attributes are documented as stable.
Limits
- Below 640px of component width the links move into a Menu panel. The 640px threshold is an adaptation.
- Escape and an outside pointer press close the menu. Both are adaptations. The source site did not close on Escape.
- Focus trapping and scroll locking are not provided.
- The Menu and Close button text is English text inside the component.