Blazor.FocusTrapJs
1.0.2
dotnet add package Blazor.FocusTrapJs --version 1.0.2
NuGet\Install-Package Blazor.FocusTrapJs -Version 1.0.2
<PackageReference Include="Blazor.FocusTrapJs" Version="1.0.2" />
paket add Blazor.FocusTrapJs --version 1.0.2
#r "nuget: Blazor.FocusTrapJs, 1.0.2"
// Install Blazor.FocusTrapJs as a Cake Addin #addin nuget:?package=Blazor.FocusTrapJs&version=1.0.2 // Install Blazor.FocusTrapJs as a Cake Tool #tool nuget:?package=Blazor.FocusTrapJs&version=1.0.2
FocusTrapJs
All documentation on this site and parameters were taken from this documentation.
Installation
dotnet add package Blazor.FocusTrapJs
Program.cs
builder.Services.AddScoped<FocusTrapJsProvider>();
Description
This is a basic library that provides access to the focus-trap
library and makes it easy to capture focus within a DOM node.
There may come a time when you find it important to catch focus inside a DOM node - so that when the user presses Tab or Shift+Tab or clicks the mouse, the user cannot escape from a particular loop of focused elements.
Examples
The template must have tabindex
otherwise nothing will work.
@inherits FocusTrapComponent
@implements IAsyncDisposable
<div id="@_id">
<div tabindex="0"></div>
</div>
@code {
private string _id => $"F{GetHashCode()}";
[Inject] public required FocusTrapJsProvider FocusTrap { get; set; }
[Parameter] public EventCallback<bool> OnFocusChanged { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await FocusTrap.InitTrap(_id, DotObj, Settings);
}
await base.OnAfterRenderAsync(firstRender);
}
[JSInvokable]
public override async ValueTask OnActivate()
{
await OnFocusChanged.InvokeAsync(true);
}
[JSInvokable]
public override async ValueTask OnDeactivate()
{
await OnFocusChanged.InvokeAsync(false);
}
public async ValueTask DisposeAsync()
{
await FocusTrap.RemoveTrap(_id);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.12)
-
net9.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.12)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Blazor.FocusTrapJs:
Package | Downloads |
---|---|
Blazor.HeadlessUI.Dropdown
A lightweight and customizable headless UI Dropdown component for Blazor projects. |
GitHub repositories
This package is not used by any popular GitHub repositories.