Tabs
Switch between labelled local or server-selected panels with orientation-aware keyboard navigation.
Default
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let codePreviewTabs =
fveTabs {
_id "components-example-format"
_ariaLabel "Example format"
fveTabsItem {
_value "code"
fveTabsTrigger { "Code" }
pre {
_role "region"
_ariaLabel "Button F# code"
_tabindex 0
_dataOn (
"keydown",
"""
if (evt.target === el && !evt.altKey && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey
&& (evt.key === 'ArrowLeft' || evt.key === 'ArrowRight')) {
evt.preventDefault();
el.scrollBy({left: evt.key === 'ArrowLeft' ? -80 : 80});
}
"""
)
_class
"overflow-x-auto rounded-[var(--fve-radius-control)] bg-[var(--fve-surface-subtle)] p-4 text-sm outline-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-[var(--fve-brand-ring)]"
"fveButton { \"Create\" }"
}
}
fveTabsItem {
_value "preview"
fveTabsTrigger { "Preview" }
div {
_class "rounded-[var(--fve-radius-control)] border border-[var(--fve-border)] p-4"
fveButton { "Create" }
}
}
}On this page
Installation
Copy this component and its required dependencies into the consumer-owned Components project.
dotnet fve add tabs --config src/Acme.Components/fve.jsonAdd to src/Acme.Web/js/app.js once, alongside your other component imports:
import '../../Acme.Components/Components/Assets/tabs.js';The CLI resolves dependencies and preserves consumer-authored files. See Installation for project initialization, Tailwind, the shared runtime, and building/loading your app entry.
Usage
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let codePreviewTabs =
fveTabs {
_id "components-example-format"
_ariaLabel "Example format"
fveTabsItem {
_value "code"
fveTabsTrigger { "Code" }
pre {
_role "region"
_ariaLabel "Button F# code"
_tabindex 0
_dataOn (
"keydown",
"""
if (evt.target === el && !evt.altKey && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey
&& (evt.key === 'ArrowLeft' || evt.key === 'ArrowRight')) {
evt.preventDefault();
el.scrollBy({left: evt.key === 'ArrowLeft' ? -80 : 80});
}
"""
)
_class
"overflow-x-auto rounded-[var(--fve-radius-control)] bg-[var(--fve-surface-subtle)] p-4 text-sm outline-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-[var(--fve-brand-ring)]"
"fveButton { \"Create\" }"
}
}
fveTabsItem {
_value "preview"
fveTabsTrigger { "Preview" }
div {
_class "rounded-[var(--fve-radius-control)] border border-[var(--fve-border)] p-4"
fveButton { "Create" }
}
}
}Server-owned selection
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let serverTabsExampleFor (submit: HtmlAttribute list) selection =
let selected = if selection = "activity" then "activity" else "summary"
form {
_id "server-tabs-preview"
_method "get"; _action "/components/tabs"
for attribute in submit do attribute
fveTabs {
_id "components-server-tabs"; _ariaLabel "Server-selected view"
_selection TabsSelection.Server
_value selected
for value, label, description in [ "summary", "Summary", "The server selected the summary."; "activity", "Activity", "The server selected recent activity." ] do
fveTabsItem {
_value value
fveTabsTrigger { _name "tab"; _value value; label }
p { description }
}
}
}
let serverTabsExample = serverTabsExampleFor [] "summary"_selection TabsSelection.Server submits the trigger's native form. Only the accepted panel is rendered, with one stable panel ID; the current panel stays visible until the server responds. Use ordinary GET forms or your application's Datastar form enhancement.
Underlined tabs with refresh
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let reviewTabsRegion refreshed =
let refreshActivityButton =
fveButton {
_id "components-tabs-refresh"
_dataOn ("click", "evt.currentTarget.focus(); @get('/components/tabs/review')")
"Refresh activity"
}
let activity =
if refreshed then
div {
p {
_role "status"
_class "font-medium"
"Review refreshed"
}
p {
_class "mt-1 text-sm text-[var(--fve-muted-text)]"
"Updated just now."
}
refreshActivityButton
}
else
div {
p {
_class "text-sm text-[var(--fve-muted-text)]"
"Three items need review."
}
refreshActivityButton
}
fveTabs {
_id "components-review-tabs"
_ariaLabel "Item sections"
fveTabsItem {
_value "overview"
fveTabsTrigger { "Overview" }
p {
_class "text-sm text-[var(--fve-muted-text)]"
"24 items updated this month"
}
}
fveTabsItem {
_value "activity"
fveTabsTrigger { "Activity" }
activity
}
fveTabsItem {
_value "settings"
fveTabsTrigger { "Settings" }
a {
_href "/guides/theming"
_class "font-medium text-[var(--fve-brand-text)]"
"Review appearance settings"
}
}
_variant TabsVariant.Underlined
}Vertical, icons and disabled items
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let refreshIcon =
fveIcon { _name IconName.ArrowPath; _variant IconVariant.Micro }
let plusIcon = fveIcon { _name IconName.Plus; _variant IconVariant.Micro }
let removeIcon = fveIcon { _name IconName.Trash; _variant IconVariant.Micro }
let verticalTabs =
fveTabs {
_id "components-vertical-tabs"
_ariaLabel "Workspace settings"
fveTabsItem {
_value "profile"
fveTabsTrigger {
span {
_ariaHidden true
_class "mr-2 inline-flex size-4 items-center justify-center align-text-bottom"
plusIcon
}
"Profile"
}
p {
_class "text-sm text-[var(--fve-muted-text)]"
"Update your name and profile image."
}
}
fveTabsItem {
_value "notifications"
fveTabsTrigger {
span {
_ariaHidden true
_class "mr-2 inline-flex size-4 items-center justify-center align-text-bottom"
refreshIcon
}
"Notifications"
}
p {
_class "text-sm text-[var(--fve-muted-text)]"
"Choose which updates send alerts."
}
}
fveTabsItem {
_value "administration"
fveTabsTrigger {
span {
_ariaHidden true
_class "mr-2 inline-flex size-4 items-center justify-center align-text-bottom"
removeIcon
}
_disabled true
"Administration"
}
p {
_class "text-sm text-[var(--fve-muted-text)]"
"These settings require administrator access."
}
}
_orientation Orientation.Vertical
}This example also uses Icon. See their Installation sections for any additional setup.
API reference
type TabsVariant =
| Segmented
| Underlined
type TabsSelection =
| Local
| Server
module TabsDsl =
val fveTabs : ComponentElementBuilder
val fveTabsItem : ComponentElementBuilder
val fveTabsTrigger : ComponentElementBuilder
module TabsAttributes =
val Html._variant.Static : value:TabsVariant -> HtmlAttribute
val Html._selection.Static : value:TabsSelection -> HtmlAttribute