protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { // Register resize-handler to window await WindowService.EventManager .AddResizeHandlerAsync(WindowResizeHandler); } // Ensure that the dropdown isn't cut off EnsureCorrectDropDownPosition(); if (_callbackId > -1) { // Ensure that callback is cleaned up await ElementService.RemoveClickOutsideOfElementHandlerAsync(_callbackId); _callbackId = -1; } if (IsActive) { // Register callback if user clicks outside of dropdown _callbackId = await ElementService.AddClickOutsideOfElementHandlerAsync( new[] { _targetReference.Current, _contentReference.Current }, () => { _callbackId = -1; IsActive = false; IsActiveChanged.InvokeAsync(false); // Notify parent that dropdown closed StateHasChanged(); }); } }
protected override async Task OnAfterRenderAsync(bool firstRender) { if (_callbackId > -1) { // Ensure that callback is cleaned up await ElementService.RemoveClickOutsideOfElementHandlerAsync(_callbackId); _callbackId = -1; } if (EnableClickOutside && Context != null && Context.IsActive) { // Register callback if user clicks outside of dropdown _callbackId = await ElementService.AddClickOutsideOfElementHandlerAsync( new[] { _modalReference }, () => { _callbackId = -1; Context.Close(); }); } }