feat: update launch configurations and add outside click handling for date input component
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
parent
bc28d869eb
commit
c0180aab13
7 changed files with 193 additions and 14 deletions
|
|
@ -1,6 +1,8 @@
|
|||
@using System.Globalization
|
||||
@implements IAsyncDisposable
|
||||
@inject IJSRuntime JS
|
||||
|
||||
<div class="localized-date-input" @onkeydown="HandleKeyDown">
|
||||
<div class="localized-date-input" @ref="rootElement" @onkeydown="HandleKeyDown">
|
||||
<div class="input-group">
|
||||
<input id="@InputId"
|
||||
data-testid="@GetInputTestId()"
|
||||
|
|
@ -75,8 +77,28 @@
|
|||
private DateOnly? lastValue;
|
||||
private string displayValue = string.Empty;
|
||||
private bool isOpen;
|
||||
private bool outsideClickListenerActive;
|
||||
private DateOnly visibleMonth;
|
||||
private IReadOnlyList<CalendarDayCell> calendarDays = [];
|
||||
private ElementReference rootElement;
|
||||
private DotNetObjectReference<LocalizedDateInput>? dotNetReference;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (isOpen && !outsideClickListenerActive)
|
||||
{
|
||||
dotNetReference ??= DotNetObjectReference.Create(this);
|
||||
await JS.InvokeVoidAsync("workTrackerDateInput.registerOutsideClick", rootElement, dotNetReference);
|
||||
outsideClickListenerActive = true;
|
||||
}
|
||||
else if (!isOpen && outsideClickListenerActive)
|
||||
{
|
||||
await JS.InvokeVoidAsync("workTrackerDateInput.unregisterOutsideClick", rootElement);
|
||||
outsideClickListenerActive = false;
|
||||
}
|
||||
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
|
|
@ -190,6 +212,34 @@
|
|||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public Task ClosePopupFromOutsideClickAsync()
|
||||
{
|
||||
if (!isOpen)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
isOpen = false;
|
||||
return InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (outsideClickListenerActive)
|
||||
{
|
||||
try
|
||||
{
|
||||
await JS.InvokeVoidAsync("workTrackerDateInput.unregisterOutsideClick", rootElement);
|
||||
}
|
||||
catch (JSDisconnectedException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
dotNetReference?.Dispose();
|
||||
}
|
||||
|
||||
private string GetInputTestId() => string.IsNullOrWhiteSpace(TestId) ? "localized-date-input" : $"{TestId}-input";
|
||||
|
||||
private string GetPopoverTestId() => string.IsNullOrWhiteSpace(TestId) ? "localized-date-popover" : $"{TestId}-popover";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue