Dialog
Present modal content with labelled structure, focus management, dismissal, and form composition.
Default
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let defaultDialog =
fveDialog {
_id "default-dialog"
_label "Review changes"
p { "Check your changes before continuing." }
}
let defaultDialogExample =
div {
fveDialogTrigger {
fveButton {
_ariaControls "default-dialog"
"Open dialog"
}
}
defaultDialog
}On this page
Installation
Copy this component and its required dependencies into the consumer-owned Components project.
dotnet fve add dialog --config src/Acme.Components/fve.jsonAdd to src/Acme.Web/js/app.js once, alongside your other component imports:
import '../../Acme.Components/Components/Assets/button.js';
import '../../Acme.Components/Components/Assets/dialog.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 defaultDialog =
fveDialog {
_id "default-dialog"
_label "Review changes"
p { "Check your changes before continuing." }
}
let defaultDialogExample =
div {
fveDialogTrigger {
fveButton {
_ariaControls "default-dialog"
"Open dialog"
}
}
defaultDialog
}Modal dialog
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let dialogConfig =
fveDialog {
_id "review-changes-dialog"
_label "Review changes"
_description "You can close this dialog to make further changes."
_initialFocus "review-changes-dialog-close"
_dismissOnBackdrop true
p { "Check your changes before continuing." }
fveDialogFooter {
fveDialogClose {
_id "review-changes-dialog-close"
_ariaControls "review-changes-dialog"
"Close"
}
}
}
let reviewDialogTrigger =
fveDialogTrigger {
fveButton {
_ariaControls "review-changes-dialog"
"Review changes"
}
}
let reviewDialog = dialogConfigServer-validated confirmation
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let itemDeletionForm (dialogId: string) (validation: string option) =
let requestSignal = "_" + dialogId.Replace('-', '_') + "_pending"
let pendingExpression = "$" + requestSignal
form {
_id $"{dialogId}-content"
_method "post"
_action "/components/dialogs/confirm"
_dataIndicator requestSignal
_dataOn (
"submit",
$"!({pendingExpression}) && @post('/components/dialogs/confirm').then(() => document.getElementById('{dialogId}-confirm')?.focus())"
)
_dataAttr ("aria-busy", $"{pendingExpression} ? 'true' : 'false'")
match validation with
| Some message ->
p {
_id $"{dialogId}-validation"
_role "alert"
_class
"rounded-[var(--fve-radius-control)] bg-[var(--fve-critical-subtle)] p-3 text-sm text-[var(--fve-critical-text)] ring-1 ring-inset ring-[var(--fve-critical-ring)]"
message
}
| None -> ()
p {
_id $"{dialogId}-status"
_tabindex -1
_role "status"
_dataShow pendingExpression
_style "display:none"
_class "mt-4 text-sm text-[var(--fve-muted-text)]"
"Confirmation in progress."
}
div {
_class "mt-6 flex flex-wrap justify-end gap-3"
fveButton {
_id $"{dialogId}-cancel"
_dataAttr ("disabled", pendingExpression)
_dataOn ("click", "el.closest('dialog').close()")
"Cancel"
}
fveButton {
_color Color.Error
_variant ButtonVariant.Solid
_dataAttr ("disabled", pendingExpression)
_dataAttr ("aria-busy", $"{pendingExpression} ? 'true' : null")
_type "submit"
_id $"{dialogId}-confirm"
"Delete"
}
}
}
let itemDeletionContent validation =
itemDeletionForm "delete-item-confirmation" validation
let itemDeletionDialog =
fveDialog {
_id "delete-item-confirmation"
_label "Delete item?"
itemDeletionContent None
_description "Delete Project notes? This action cannot be undone."
_initialFocus "delete-item-confirmation-cancel"
_role "alertdialog"
_dataSignals "{_delete_item_confirmation_pending: false}"
_dataOn ("cancel", "$_delete_item_confirmation_pending && evt.preventDefault()")
}
let confirmationExample =
div {
fveDialogTrigger {
fveButton {
_ariaControls "delete-item-confirmation"
"Delete"
}
}
itemDeletionDialog
}App-contained dialog
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let containedDialogConfig =
fveDialog {
_id "contained-dialog"
_label "Review changes"
_container "contained-dialog-background"
_initialFocus "contained-dialog-close"
_dismissOnBackdrop true
p { "Check your changes before continuing." }
fveDialogFooter {
fveDialogClose {
_id "contained-dialog-close"
_ariaControls "contained-dialog"
"Cancel"
}
}
}
let containedDialogExample =
div {
_class "relative h-80 overflow-hidden rounded-lg border border-[var(--fve-border)]"
div {
_id "contained-dialog-background"
_class "h-full p-5"
p {
_class "mb-4 text-sm"
"Surrounding documentation stays available."
}
fveDialogTrigger {
fveButton {
_ariaControls "contained-dialog"
"Open contained dialog"
}
}
}
containedDialogConfig
}_container keeps the dialog in a positioned app viewport rather than the document top layer. The component owns the backdrop, app-background inertness, Escape and focus return; review chrome remains usable. _open true supports server-rendered open states; mark the background inert in that native state too.
Labels and focus
Use the title part to name the dialog. Set _initialFocus to a control ID when the default first focus target is not appropriate; Escape dismisses the overlay and restores its opener.
API reference
module DialogDsl =
val fveDialog : ComponentElementBuilder
val fveDialogFooter : ComponentElementBuilder
val fveDialogTrigger : ComponentTriggerBuilder
val fveDialogClose : ComponentElementBuilder
module OverlayAttributes =
val Html._initialFocus.Static : value:string -> HtmlAttribute
val Html._container.Static : value:string -> HtmlAttribute
val Html._dismissOnBackdrop.Static : value:bool -> HtmlAttribute