Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}
@if (!string.IsNullOrWhiteSpace(yesButtonText))
{
<button id="bb-confirm-@Id" class="@yesButtonColor px-4" type="button" @onclick="OnYesClick">@yesButtonText</button>
<button @ref="@yesButtonElement" class="@yesButtonColor px-4" type="button" @onclick="OnYesClick">@yesButtonText</button>
}
</div>
</div>
Expand Down
19 changes: 12 additions & 7 deletions blazorbootstrap/Components/ConfirmDialog/ConfirmDialog.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ public partial class ConfirmDialog : BlazorBootstrapComponentBase
#region Fields and Constants

private Type? childComponent;

private string? dialogCssClass;
private bool dismissable;
private string? headerCssClass;

private bool isVisible;
private string? message1;
private string? message2;
Expand All @@ -18,20 +16,27 @@ public partial class ConfirmDialog : BlazorBootstrapComponentBase
private string? noButtonText;
private Dictionary<string, object>? parameters;
private string? scrollable;

private bool shouldAutoFocusYesButton;
private bool showBackdrop;

private TaskCompletionSource<bool>? taskCompletionSource;

private string? title;
private string? verticallyCentered;
private ElementReference yesButtonElement;
private string? yesButtonColor;
private string? yesButtonText;

#endregion

#region Methods

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(isVisible && shouldAutoFocusYesButton)
await yesButtonElement.FocusAsync();

await base.OnAfterRenderAsync(firstRender);
}

/// <summary>
/// Shows confirm dialog.
/// </summary>
Expand Down Expand Up @@ -116,13 +121,13 @@ private Task<bool> Show(string title, string? message1, string? message2, Type?
modalSize = confirmDialogOptions.Size.ToDialogSizeClass();
yesButtonColor = $"{BootstrapClass.Button} {confirmDialogOptions.YesButtonColor.ToButtonColorClass()}";
yesButtonText = confirmDialogOptions.YesButtonText;

shouldAutoFocusYesButton = confirmDialogOptions.AutoFocusYesButton;
isVisible = true;
showBackdrop = true;

StateHasChanged();

Task.Run(async () => await SafeInvokeVoidAsync("window.blazorBootstrap.confirmDialog.show", Id, confirmDialogOptions.AutoFocusYesButton));
Task.Run(async () => await SafeInvokeVoidAsync("window.blazorBootstrap.confirmDialog.show", Id));

return task;
}
Expand Down
9 changes: 1 addition & 8 deletions blazorbootstrap/wwwroot/blazor.bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,14 @@ window.blazorBootstrap = {
}
},
confirmDialog: {
show: (elementId, autoFocusYesButton) => {
show: (elementId) => {
let confirmDialogEl = document.getElementById(elementId);
if (confirmDialogEl != null)
setTimeout(() => confirmDialogEl.classList.add('show'), 90); // added delay for server

let bodyEl = document.getElementsByTagName('body');
if (bodyEl.length > 0)
bodyEl[0].style['overflow'] = 'hidden';

if (!autoFocusYesButton)
return;

let yesButtonEl = document.getElementById(`bb-confirm-${elementId}`);
if (yesButtonEl)
yesButtonEl.focus();
},
hide: (elementId) => {
let confirmDialogEl = document.getElementById(elementId);
Expand Down
Loading