Rask
Rask
v0.24.1-alpha.0.419

Components

Modal

A real modal <dialog> with a Name, opened by the button inside a Ui.DialogTrigger of that name. No handler runs: the browser gives it the top layer, an inert page behind it, Escape, and focus back on the trigger when it closes, on a prerendered page too.

Drawn and behaving as Flux UI's modal does, measured against its live docs.

Modal

The modal draws the panel and the close button; what it holds is yours. A width in Class replaces its own. OnClose hears every way it closed.

ModalExample.cs
namespace Rask.Site.Features.UiDocs.Examples;

public sealed partial class ModalExample : Component
{
    private int _closed;

    protected override Component? Render() =>
        Div.Class("flex flex-wrap items-center gap-4")[
            Ui.DialogTrigger.Name("edit-profile")[Ui.Button["Edit profile"]],
            Ui.Dialog.Name("edit-profile").Class("md:w-96").OnClose(() => { _closed++; })[
                Div.Class("space-y-6")[
                    Div[
                        Ui.Heading.Level(2).Lg["Update profile"],
                        Ui.Text.Class("mt-2")["Make changes to your personal details."]
                    ],
                    Ui.Input.Of<string>().Label("Name").Placeholder("Your name"),
                    Ui.Input.Of<string>().Label("Date of birth").Type(InputType.Date),
                    // Opening this inside the dialog is not the dialog closing.
                    Details.Data("testid", "ui-modal-more")[
                        Summary["More"],
                        P["Opening this does not close the dialog."]
                    ],
                    Div.Class("flex")[Ui.Spacer, Ui.Button.Primary["Save changes"]]
                ]
            ],
            Ui.Text[$"Closed {_closed} time{(_closed == 1 ? "" : "s")}."]
        ];
}
Live result

Update profile

Make changes to your personal details.

More

Opening this does not close the dialog.

Closed 0 times.

Data binding

For when C# decides it should appear: Open is the page's field, Flux's wire:model, and it is the same modal. OnCancel hears a dismissal, Escape or a click outside, before OnClose.

ModalOpenExample.cs
namespace Rask.Site.Features.UiDocs.Examples;

public sealed partial class ModalOpenExample : Component
{
    private bool _confirming;
    private string _last = "nothing yet";

    protected override Component? Render() =>
        Div.Class("flex flex-wrap items-center gap-4")[
            Ui.Button.Danger.OnClick(() => { _confirming = true; })["Delete order"],
            Ui.Dialog
                .Open(_confirming)
                .OnCancel(() => { _last = "dismissed the dialog"; })
                .OnClose(() => { _confirming = false; })[
                Div.Class("space-y-6")[
                    Div[
                        Ui.Heading.Level(2).Lg["Delete order"],
                        Ui.Text.Class("mt-2")["This cannot be undone."]
                    ],
                    Div.Class("flex gap-2")[
                        Ui.Spacer,
                        Ui.DialogClose[Ui.Button.Ghost["Cancel"]],
                        Ui.Button.Danger.OnClick(() =>
                        {
                            _confirming = false;
                            _last = "deleted the order";
                        })["Delete"]
                    ]
                ]
            ],
            Ui.Text[$"Last action: {_last}."]
        ];
}
Live result

Delete order

This cannot be undone.

Last action: nothing yet.

Disable click outside

Dismissible(false) keeps a stray click outside from losing what is being edited.

ModalDismissibleExample.cs
namespace Rask.Site.Features.UiDocs.Examples;

public sealed partial class ModalDismissibleExample : Component
{
    protected override Component? Render() =>
        Div[
            Ui.DialogTrigger.Name("demo-filters")[Ui.Button["Filters"]],
            Ui.Dialog.Name("demo-filters").Flyout().Dismissible(false)[
                Div.Class("space-y-6")[
                    Ui.Heading.Level(2).Lg["Filters"],
                    Ui.Text["Only the close button, Escape, or Apply closes this one."],
                    Div.Class("flex")[Ui.Spacer, Ui.DialogClose[Ui.Button.Primary["Apply"]]]
                ]
            ]
        ];
}
Live result

Filters

Only the close button, Escape, or Apply closes this one.

Disable escape

Escapable(false) takes Escape away; Closable(false) takes the corner button.

ModalEscapableExample.cs
namespace Rask.Site.Features.UiDocs.Examples;

public sealed partial class ModalEscapableExample : Component
{
    protected override Component? Render() =>
        Div[
            Ui.DialogTrigger.Name("demo-session")[Ui.Button["Session"]],
            Ui.Dialog.Name("demo-session").Escapable(false)[
                Div.Class("space-y-6")[
                    Ui.Heading.Level(2).Lg["Session expiring"],
                    Ui.Text["Escape does not close this one; a click outside, the corner button or Stay does."],
                    Div.Class("flex")[Ui.Spacer, Ui.DialogClose[Ui.Button.Primary["Stay signed in"]]]
                ]
            ]
        ];
}
Live result

Session expiring

Escape does not close this one; a click outside, the corner button or Stay does.

Scrolling long content

Scroll Body lets a long modal run past the bottom of the screen, so it is plain there is more.

ModalScrollExample.cs
namespace Rask.Site.Features.UiDocs.Examples;

public sealed partial class ModalScrollExample : Component
{
    protected override Component? Render() =>
        Div[
            Ui.DialogTrigger.Name("demo-terms")[Ui.Button["Terms"]],
            Ui.Dialog.Name("demo-terms").Scroll(Ui.DialogScroll.Body).Class("md:w-lg")[
                Div.Class("space-y-6")[
                    Ui.Heading.Level(2).Lg["Terms of service"],
                    Enumerable.Range(1, 24)
                        .Select(n => Ui.Text.Key(n)[$"{n}. The whole layer scrolls, not a box inside it."])
                        .ToArray(),

                    Div.Class("flex")[Ui.Spacer, Ui.DialogClose[Ui.Button.Primary["Accept"]]]
                ]
            ]
        ];
}
Live result

Terms of service

1. The whole layer scrolls, not a box inside it.

2. The whole layer scrolls, not a box inside it.

3. The whole layer scrolls, not a box inside it.

4. The whole layer scrolls, not a box inside it.

5. The whole layer scrolls, not a box inside it.

6. The whole layer scrolls, not a box inside it.

7. The whole layer scrolls, not a box inside it.

8. The whole layer scrolls, not a box inside it.

9. The whole layer scrolls, not a box inside it.

10. The whole layer scrolls, not a box inside it.

11. The whole layer scrolls, not a box inside it.

12. The whole layer scrolls, not a box inside it.

13. The whole layer scrolls, not a box inside it.

14. The whole layer scrolls, not a box inside it.

15. The whole layer scrolls, not a box inside it.

16. The whole layer scrolls, not a box inside it.

17. The whole layer scrolls, not a box inside it.

18. The whole layer scrolls, not a box inside it.

19. The whole layer scrolls, not a box inside it.

20. The whole layer scrolls, not a box inside it.

21. The whole layer scrolls, not a box inside it.

22. The whole layer scrolls, not a box inside it.

23. The whole layer scrolls, not a box inside it.

24. The whole layer scrolls, not a box inside it.

Confirmation

Ask before a dangerous action. Ui.DialogClose makes the button inside it close the modal: a close, not a dismissal, and the button's own handler still runs.

ModalConfirmationExample.cs
namespace Rask.Site.Features.UiDocs.Examples;

public sealed partial class ModalConfirmationExample : Component
{
    private bool _deleted;

    protected override Component? Render() =>
        Div.Class("flex flex-wrap items-center gap-4")[
            Ui.DialogTrigger.Name("delete-profile")[Ui.Button.Danger["Delete"]],
            Ui.Dialog.Name("delete-profile").Class("min-w-[22rem]")[
                Div.Class("space-y-6")[
                    Div[
                        Ui.Heading.Level(2).Lg["Delete project?"],
                        Ui.Text.Class("mt-2")["You're about to delete this project.", Br, "This action cannot be reversed."]
                    ],
                    Div.Class("flex gap-2")[
                        Ui.Spacer,
                        Ui.DialogClose.Key("cancel")[Ui.Button.Ghost["Cancel"]],
                        // A close, and the button's own handler still runs.
                        Ui.DialogClose.Key("delete")[
                            Ui.Button.Danger.OnClick(() => { _deleted = true; })["Delete project"]
                        ]
                    ]
                ]
            ],
            Ui.Text[_deleted ? "You deleted the project." : "The project is still there."]
        ];
}
Live result

Delete project?

You're about to delete this project.
This action cannot be reversed.

The project is still there.

Dialog buttons

Not Flux's, and drawn as its footer: Ui.DialogButtons is Cancel, which closes the modal it stands in, and the primary action, a click handler that shows it is busy while it runs and sends no form. The words are the catalog's until Save("…") and Cancel("…") name them. In a dialog that is a form, Submit() makes the action the form's submit: it is validated, busy while OnSubmit runs, and Enter in a field sends it. Danger() draws the action red. Heading("…") and Text("…"), not Flux's either, write the title and the sentence every Flux example opens with, the title clear of the close button and naming the dialog.

ModalDialogButtonsExample.cs
using System.ComponentModel.DataAnnotations;

namespace Rask.Site.Features.UiDocs.Examples;

public sealed partial class ModalDialogButtonsExample : Component
{
    private readonly Merger _merger = new();
    private bool _booking;
    private bool _merging;
    private string _last = "nothing booked yet";

    protected override Component? Render() =>
        Div.Class("flex flex-wrap items-center gap-4")[
            Ui.Button.OnClick(() => { _booking = true; })["Book stock"],
            // Heading and Text open it as Flux's examples do, the heading clear of the close button.
            Ui.Dialog.Open(_booking).OnClose(() => { _booking = false; }).Class("md:w-96")
                .Heading("Book 12 pallets?").Text("They move into the warehouse today.")[
                    // Cancel closes the modal; Book runs the handler, busy while it waits.
                    Ui.DialogButtons.Save("Book").OnSave(async () =>
                    {
                        await Task.Delay(600);
                        _last = "booked 12 pallets";
                        _booking = false;
                    })
                ],
            Ui.Button.OnClick(() => { _merging = true; })["Merge suppliers"],
            Ui.Dialog.Open(_merging).OnClose(() => { _merging = false; }).Class("md:w-96")[
                // A dialog that IS a form: Submit() makes Merge the form's submit — validated, busy, Enter sends it.
                Form.Model(_merger).OnSubmit(async m =>
                {
                    await Task.Delay(600);
                    _last = $"merged into {m.Name}";
                    _merging = false;
                }).Class("space-y-6")[
                    Ui.Heading.Level(2).Lg["Merge two suppliers"],
                    Ui.Input.Bind(() => _merger.Name).Label("Merged name"),
                    Ui.DialogButtons.Submit().Save("Merge")
                ]
            ],
            Ui.Text[$"Last action: {_last}."]
        ];

    private sealed class Merger
    {
        [Required]
        public string? Name { get; set; }
    }
}
Live result

Book 12 pallets?

They move into the warehouse today.

Merge two suppliers

Last action: nothing booked yet.

Confirm an action

Not Flux's, and drawn as the confirmation above: place Ui.Confirm in the layout once, and .Confirm("…") on any button or form asks in it instead of the browser. With expect: Yes waits for the answer typed exactly. Opening it, typing and No send nothing; Yes lets the press go. Every way of asking is on the Confirm page.

ModalConfirmActionExample.cs
namespace Rask.Site.Features.UiDocs.Examples;

// The layout places the dialog once — Ui.Confirm, or Ui.Confirm.Heading("Megerősítés").No("Nem").Yes("Igen") —
// and every .Confirm("…") on every page asks in it, under the layout's title or, with heading:, one of its own.
public sealed partial class ModalConfirmActionExample : Component
{
    private string _project = "Rask";

    protected override Component? Render() =>
        Div.Class("flex flex-wrap items-center gap-4")[
            Ui.Button.Danger.Id("ui-confirm-delete")
                .OnClick(() => _project = "")
                .Confirm("You're about to delete this project. This action cannot be reversed.", heading: "Delete project?")["Delete"],
            Ui.Button.Id("ui-confirm-delete-by-name")
                .OnClick(() => _project = "")
                .Confirm("Type the project's name, Rask, to delete it.", expect: "Rask")["Delete by name"],
            Ui.Button.Ghost.Id("ui-confirm-restore").OnClick(() => _project = "Rask")["Restore"],
            Ui.Text.Id("ui-confirm-state")[_project.Length > 0 ? $"The {_project} project is still there." : "You deleted the project."]
        ];
}
Live result

The Rask project is still there.

Flyout

Flyout anchors it to an edge at full height, for longer forms.

ModalFlyoutExample.cs
namespace Rask.Site.Features.UiDocs.Examples;

public sealed partial class ModalFlyoutExample : Component
{
    protected override Component? Render() =>
        Div[
            Ui.DialogTrigger.Name("edit-profile-flyout")[Ui.Button["Edit profile"]],
            Ui.Dialog.Name("edit-profile-flyout").Flyout().Class("md:w-lg")[
                Div.Class("space-y-6")[
                    Div[
                        Ui.Heading.Level(2).Lg["Update profile"],
                        Ui.Text.Class("mt-2")["Make changes to your personal details."]
                    ],
                    Ui.Input.Of<string>().Label("Name").Placeholder("Your name"),
                    Ui.Input.Of<string>().Label("Date of birth").Type(InputType.Date),
                    Div.Class("flex")[Ui.Spacer, Ui.Button.Primary["Save changes"]]
                ]
            ]
        ];
}
Live result

Update profile

Make changes to your personal details.

Flyout positioning

The right edge by default; Left or Bottom when asked.

ModalFlyoutPositionExample.cs
namespace Rask.Site.Features.UiDocs.Examples;

public sealed partial class ModalFlyoutPositionExample : Component
{
    protected override Component? Render() =>
        Div.Class("flex flex-wrap gap-2")[
            Ui.DialogTrigger.Name("flyout-left")[Ui.Button["From the left"]],
            Ui.DialogTrigger.Name("flyout-bottom")[Ui.Button["From the bottom"]],
            Ui.Dialog.Name("flyout-left").Flyout().Left[
                Div.Class("space-y-6")[Ui.Heading.Level(2).Lg["Navigation"], Ui.Text["A flyout from the left edge."]]
            ],
            Ui.Dialog.Name("flyout-bottom").Flyout().Bottom[
                Div.Class("space-y-6")[Ui.Heading.Level(2).Lg["Share"], Ui.Text["A flyout from the bottom edge."]]
            ]
        ];
}
Live result

Navigation

A flyout from the left edge.

Share

A flyout from the bottom edge.

Floating flyout

The Floating variant stands the flyout off the edges of the viewport, rounded and shadowed like a panel.

ModalFloatingExample.cs
namespace Rask.Site.Features.UiDocs.Examples;

public sealed partial class ModalFloatingExample : Component
{
    protected override Component? Render() =>
        Div[
            Ui.DialogTrigger.Name("edit-profile-floating")[Ui.Button["Edit profile"]],
            Ui.Dialog.Name("edit-profile-floating").Flyout().Floating.Class("md:w-lg")[
                Div.Class("space-y-6")[
                    Ui.Heading.Level(2).Lg["Update profile"],
                    Ui.Subheading["Make changes to your personal details."],
                    Ui.Input.Of<string>().Label("Name").Placeholder("Your name"),
                    Ui.Input.Of<string>().Label("Date of birth").Type(InputType.Date),
                    Div.Class("flex items-center justify-end gap-2")[
                        Ui.DialogClose[Ui.Button.Filled["Cancel"]],
                        Ui.Button.Primary["Save changes"]
                    ]
                ]
            ]
        ];
}
Live result

Update profile

Make changes to your personal details.

Lazy

Lazy() sends what it holds only while it is open: closed, the page carries the dialog alone, and opening it is answered with one frame of content. Not Flux's: the kit's, for a panel most readers never open, as Ui.Filters' is.

ModalLazyExample.cs
namespace Rask.Site.Features.UiDocs.Examples;

public sealed partial class ModalLazyExample : Component
{
    protected override Component? Render() =>
        Div[
            Ui.DialogTrigger.Name("lazy-profile")[Ui.Button["Edit profile"]],
            Ui.Dialog.Name("lazy-profile").Lazy().Class("md:w-96")[
                Div.Class("space-y-6")[
                    Div[
                        Ui.Heading.Level(2).Lg["Update profile"],
                        Ui.Text.Class("mt-2")["None of this reached the browser until you opened it."]
                    ],
                    Ui.Input.Of<string>().Label("Name").Placeholder("Your name"),
                    Div.Class("flex")[Ui.Spacer, Ui.DialogClose[Ui.Button.Primary["Done"]]]
                ]
            ]
        ];
}
Live result

Behaviour

Who opens it

No handler runs. The trigger makes its button an HTML invoker (command="show-modal" commandfor), so the browser supplies the top layer, an inert page behind it so Tab cannot wander out, Escape, and focus handed back to the trigger on close.

What Flux adds in script, the dialog asks Rask's runtime for by attribute: data-rask-modal for a click outside and for which of the two dismissals are allowed, data-rask-lock="scroll" for the page held still behind it, and the invoker commands themselves in a browser that has none (before Chrome 135, Firefox 144 and Safari 26.2).

While a modal is open the page behind it does not scroll, and keeps its scrollbar's gutter where a scrollbar is showing, so it neither shifts sideways nor moves from where it was scrolled to.

Closing, and dismissing

A modal draws the panel and the close button in its corner; what it holds (a heading, fields, a row of buttons) is yours, as in Flux.

Step
What happens
Dismissible(false)A click outside does nothing.
Escapable(false)Escape does nothing. Alone, it still closes on a click outside: all four combinations of the two switches work.
Closable(false)No close button in the corner.
OnCloseHears every way it closed.
OnCancelHears only a dismissal, Escape or a click outside, and runs before OnClose: a dialog holding a draft can throw it away when the reader backs out and keep it when they press a button that closes it. The close button and a Ui.DialogClose are not dismissals.

Both are the dialog's own events: a dismissal raises cancel before close, in every browser.

Width, and the close button

A modal with no width of its own is as wide as what it holds, between Flux's two defaults: at least 20rem and at most 36rem (a side flyout: at least 25rem from md). A width handed to Class replaces them: md:w-96 for a form, and min-w-[22rem] for a confirmation, which is what Flux's own example writes; a short question over two buttons is a narrow box without it.

The close button is 32px, 16px in from the top and from the end edge, at every width. The heading keeps no room for it, in Flux as here: the panel's padding is 24px, so a first line that fills the panel (and a one-line question the modal hugs always does) ends 24px under the button.

Flux's examples avoid that the way the confirmation above does: a short heading, "Delete project?", with the sentence in a Ui.Text under it. Where the heading is the sentence, Ui.Heading.Class("pe-8") keeps it clear of the button.

When the page owns it

Where Flux controls a modal from PHP (Flux::modal('confirm')->show()), a Rask page owns the state instead: Ui.Dialog.Open(_confirming).OnClose(() => _confirming = false)[…], which is Rask's wire:model.

It is the same modal: the dialog says data-rask-modal-open and the runtime shows and closes it to match, so it is in the top layer behind the same backdrop, Escape and a click outside run OnCancel then OnClose, and focus returns when it closes. OnClose is where the page hears that the reader closed it: set the field there, or the page goes on saying it is open and the runtime opens it again.

What the page says last is what the browser shows, however slow the line: a close that arrives while the dialog is still animating, or one the browser did not carry out the first time, is carried out once the page has its answers.

A modal with neither a Name nor Open is open for as long as the page renders it. A modal without a Key beside keyed ones is fine: it keeps its instance by its order among the unkeyed modals of the page.

Shapes

Each is a step on the same modal. Ui.Drawer is gone: a panel that slides in from an edge is a flyout.

Step
What happens
Flyout()Against the right edge, at full height.
Flyout().Left, Flyout().BottomAgainst another edge: Ui.DialogPosition is Right, Left or Bottom.
Flyout().FloatingStanding off the edges, rounded.
Variant(Ui.DialogVariant.Bare)No panel and no close button: what it holds is all there is.
Scroll(Ui.DialogScroll.Body)The whole layer scrolls, not the dialog.
Ui.DialogTrigger.Shortcut("mod+k")Opens it from anywhere on the page: Flux's cmd.k.

Reference

Ui.Dialog

flux:modal

A real modal <dialog>: the top layer, an inert page behind it, Escape, and focus handed back.

Step
Takes
What it does
.Name(…)stringWhat a Ui.DialogTrigger opens it by. Unique on the page: it is the dialog's id.
.Flyout()boolAnchors it to an edge of the viewport at full height, for longer forms.
.Position(…)
Ui.DialogPosition
Right
Left
Bottom

Each is a step of its own too, unless an HTML tag has its name.

The edge a flyout opens from. Right when unset.
.Variant(…)
Ui.DialogVariant
Default
Floating
Bare
Flyout

Each is a step of its own too, unless an HTML tag has its name.

How it is drawn: the panel, a floating flyout, or nothing around the content.
.Scroll(…)
Ui.DialogScroll
Body

Each is a step of its own too, unless an HTML tag has its name.

What scrolls when it is taller than the viewport: the dialog, or the whole layer.
.Dismissible()boolWhether a click outside closes it. On unless false.
.Escapable()boolWhether Escape closes it. On unless false.
.Closable()boolWhether it shows the close button in its corner. On unless false.
.Heading(…)stringThe title it opens with, large, clear of the close button, as Flux's examples write it; it names the dialog. Not Flux's.
.Text(…)stringThe sentence under the heading, as Flux's examples write it. Not Flux's.
.Open()boolHands the open state to the page, Flux's wire:model. Unset, its triggers open it.
.Lazy()boolSends what it holds only while it is open: closed, it is the dialog alone. Not Flux's.
.OnClose(…)a handler, with no argumentRuns when it closes, by any means: where a page that set Open hears it.
.OnCancel(…)a handler, with no argumentRuns when it is dismissed, by Escape or a click outside, before OnClose.

Ui.DialogTrigger

flux:modal.trigger

Makes the button inside it open the modal of that name, with no handler.

Step
Takes
What it does
.Name(…)stringThe Name of the modal it opens. Required, and taken first.
.Shortcut(…)stringKeys that open it from anywhere on the page: "mod+k" is ⌘K on a Mac and Ctrl K elsewhere.

Ui.DialogClose

flux:modal.close

Makes the button inside it close the modal it is in: a close, not a dismissal.

No steps of its own: what goes inside it is its content.

Ui.DialogButtons

not in Flux UI

A dialog's footer as Flux draws one: Cancel, which closes the modal, then the primary action.

Step
Takes
What it does
.OnSave(…)a handler, with no argumentRuns when the action is pressed: a click, not a submit. The button is busy while it runs.
.Submit()boolMakes the action the enclosing form's submit, as FormButtons' Save is: the form validates, its OnSubmit runs, Enter submits, and it is busy meanwhile. Not with OnSave.
.Danger()boolDraws the action as Flux's danger button, for a footer that deletes or cannot be undone. With OnSave or Submit.
.Save(…)stringThe label of the action. The catalog's "Save" when unset.
.Cancel(…)stringThe label of the button that closes the modal. The catalog's "Cancel" when unset.

Confirm