Skip to content

Commit

Permalink
Disabled rerenders when background click is disabled (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissainty authored Sep 17, 2022
1 parent 2ba25c0 commit 3ba585d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Blazored.Modal/BlazoredModalInstance.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,22 @@ public partial class BlazoredModalInstance : IDisposable
[SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "This is assigned in Razor code and isn't currently picked up by the tooling.")]
private ElementReference _modalReference;
private bool _setFocus;
private bool _disableNextRender;

// Temporarily add a tabindex of -1 to the close button so it doesn't get selected as the first element by activateFocusTrap
private readonly Dictionary<string, object> _closeBtnAttributes = new() { { "tabindex", "-1" } };

protected override bool ShouldRender()
{
if (!_disableNextRender)
{
return true;
}

_disableNextRender = false;
return false;
}

protected override void OnInitialized()
=> ConfigureInstance();

Expand Down Expand Up @@ -313,7 +325,11 @@ private bool SetActivateFocusTrap()

private async Task HandleBackgroundClick()
{
if (DisableBackgroundCancel) return;
if (DisableBackgroundCancel)
{
_disableNextRender = true;
return;
}

await CancelAsync();
}
Expand Down

0 comments on commit 3ba585d

Please sign in to comment.