Skip to content

Commit

Permalink
🆕 feat(Dialog): add DisableAutoFocus parameter (#2261)
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem authored Nov 25, 2024
1 parent 1bfd33e commit ac2435a
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Masa.Blazor/Components/Dialog/MDialog.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public partial class MDialog : MBootable, IThemeable, IDependent
/// </summary>
[Parameter] [MasaApiParameter(Ignored = true)] public bool NoOutsideClick { get; set; }

/// <summary>
/// Disable to focus on the dialog when it's opened.
/// </summary>
[Parameter]
[MasaApiParameter(ReleasedOn = "v1.8.0")]
public bool DisableAutoFocus { get; set; }

private readonly List<IDependent> _dependents = new();

private bool _attached;
Expand Down Expand Up @@ -127,15 +134,18 @@ protected override async Task WhenIsActiveUpdating(bool value)
{
ZIndex = await GetActiveZIndex(true);

NextTick(async () =>
if (!DisableAutoFocus)
{
// TODO: previousActiveElement
var contains = await Js.InvokeAsync<bool>(JsInteropConstants.ContainsActiveElement, DialogRef);
if (!contains)
NextTick(async () =>
{
await Js.InvokeVoidAsync(JsInteropConstants.Focus, DialogRef);
}
});
// TODO: previousActiveElement
var contains = await Js.InvokeAsync<bool>(JsInteropConstants.ContainsActiveElement, DialogRef);
if (!contains)
{
await Js.InvokeVoidAsync(JsInteropConstants.Focus, DialogRef);
}
});
}
}

await base.WhenIsActiveUpdating(value);
Expand Down

0 comments on commit ac2435a

Please sign in to comment.