ActionSheet
Since 0.1.0-alpha.24ActionSheet: 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
Code
@* 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>
{
[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:
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 anActionSheet: a menu row, larger for a finger.
Mode support
| Feature | Static | Interactive |
|---|---|---|
| Opens from a trigger or a ?dialog= link | Yes | Yes |
| Items as links and form posts | Yes | Yes |
| Closes when an item is chosen | Yes | Yes |
| Focus moves in when opened and back when closed | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Every page starts as plain HTML: before IzzyBlazor's script loads on a static page, while an interactive page prerenders, and with JavaScript off. With JavaScript off, a sheet opened from the server isn't modal: focus can leave it, and Escape or a click outside closes it only in browsers with closedby (not Safari).
Accessibility
- It's a native modal
dialognamed byTitle(anh2); without aTitle, pass anaria-label. The page behind it is inert, and focus returns to the trigger. - Each item is a native
buttonor 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
| Prop | Type | Default |
|---|---|---|
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. | bool | false |
ShowCancelShows Cancel after the items. | bool | true |
CancelTextCancel's text. | string? | computed |
CloseOnBackdropCloses the sheet on a tap outside it. | bool | true |
SizeThe width at most: DialogSize.Md (the default) is 40rem, Sm 24rem, Lg 48rem, Xl 64rem, Full the screen's. | DialogSize | DialogSize.Md |
QueryKeyThe query-string key that opens it from a link, as on Dialog. | string? | "dialog" |
Plus 4 common props.
Full APISee 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#.