Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

ActionSheet

Since 0.1.0-alpha.24
Offers a few actions on one thing in a sheet from the bottom, with Cancel last.

ActionSheet: a few actions on one thing, such as a photo or a message, in a sheet that slides up from the bottom, with Cancel last. It suits phones; on wide screens a Menu fits better. Its items are a menu's rows, made larger for a finger, with an optional icon each.

A photo's actions

Open the sheet with a DialogTrigger, give it a Title that names what the actions act on, and write an ActionSheetItem per action. Mark a destructive one with Accent.Danger. To post the choice, put the sheet inside the form and give each item Submit, Name and Value.

Static

Preview

Nothing chosen yet

IMG_2041.jpg

Taken Oct 12 in Lisbon, 3.2 MB


Code

Usage.razor
@* A photo's actions on a phone. The sheet is inside the form its items post. *@
<form method="post" @onsubmit="Chosen" @formname="action-sheet-usage" data-enhance>
    <AntiforgeryToken />
    <Row Gap="3" Wrap Align="Align.Center">
        <DialogTrigger For="photo-actions" StartIcon="Lucide.Ellipsis" Variant="ButtonVariant.Outline" Accent="Accent.Neutral">IMG_2041.jpg</DialogTrigger>
        <TextBlock As="span" Size="TextSize.Sm" Color="Color.Muted">@_result</TextBlock>
    </Row>

    <ActionSheet Id="photo-actions" Title="IMG_2041.jpg" Description="Taken Oct 12 in Lisbon, 3.2 MB">
        @* Static pages post the chosen item's Name=Value; interactive ones run OnClick. *@
        <ActionSheetItem Submit Name="choice" Value="Shared" OnClick='() => _pressed = "Shared"'
                         Icon="Lucide.Share2">Share</ActionSheetItem>
        <ActionSheetItem Submit Name="choice" Value="Duplicated" OnClick='() => _pressed = "Duplicated"'
                         Icon="Lucide.Copy">Duplicate</ActionSheetItem>
        <ActionSheetItem Submit Name="choice" Value="Deleted" OnClick='() => _pressed = "Deleted"'
                         Accent="Accent.Danger" Icon="Lucide.Trash">Delete</ActionSheetItem>
    </ActionSheet>
</form>

@code {
    [SupplyParameterFromForm(FormName = "action-sheet-usage", Name = "choice")]
    private string? Choice { get; set; }

    private string? _pressed;
    private string _result = "Nothing chosen yet";

    private void Chosen() => _result = $"{Choice ?? _pressed} IMG_2041.jpg";
}

Static: An item posts without a full reload, and the sheet closes.

Add this example to a page with the izzy CLI:

bash
izzy add component ActionSheet --at <file>:<line>

Details

It opens as a Dialog does: a DialogTrigger, a ?dialog=id link, or @bind-Open. Its items take MenuItem's parameters, so they act on static pages too: Href is a link, Submit posts the form the sheet is in (or Form="id"), and OnClick runs C# on interactive pages. Choosing one closes the sheet: a link or a post renders the page with it closed, and on an interactive page the sheet closes after OnClick. Put the sheet inside the form its items post, as with a Menu.

The sheet is centered and 40rem wide at most, the full width on phones. Cancel (CancelText), after a rule, closes it, as do Escape and a tap outside.

Parts

Written inside ActionSheet. The API page lists their parameters.

  • ActionSheetItem: one action in an ActionSheet: a menu row, larger for a finger.

Mode support

What works in each mode, ActionSheet
FeatureStaticInteractive
Opens from a trigger or a ?dialog= linkYesYes
Items as links and form postsYesYes
Closes when an item is chosenYesYes
Focus moves in when opened and back when closedYesYes

Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.

Accessibility

  • It's a native modal dialog named by Title (an h2); without a Title, pass an aria-label. The page behind it is inert, and focus returns to the trigger.
  • Each item is a native button or link, so it's reached with Tab and named by its text. Its icon is decoration.
  • Cancel is a real button, not only a tap outside, so every way out can be reached.

Parameters

ActionSheet parameters
PropTypeDefault
IdThe id a DialogTrigger's For or a ?dialog= link opens it by.string?
TitleThe heading, which names the sheet for screen readers: what the actions act on, such as a file's name.string?
DescriptionA short line under the title, such as a file's size or a warning about what's undone.string?
ChildContentThe ActionSheetItems, in order.RenderFragment?
@bind-OpenWhether it is open.boolfalse
ShowCancelShows Cancel after the items.booltrue
CancelTextCancel's text.string?computed
CloseOnBackdropCloses the sheet on a tap outside it.booltrue
SizeThe width at most: DialogSize.Md (the default) is 40rem, Sm 24rem, Lg 48rem, Xl 64rem, Full the screen's.DialogSizeDialogSize.Md
QueryKeyThe query-string key that opens it from a link, as on Dialog.string?"dialog"

See also

  • Menu: opens a popover menu of links, form posts and actions.
  • Drawer: opens a dialog that slides in from an edge.
  • Dialog: opens a native modal dialog from a trigger, a link or C#.

Connection lost

Rejoining the server…