@implements IDisposable; @inject ISearchService searchService @inject IJSRuntime jsRuntime @code { protected override void OnInitialized() { searchService.Subscribe(OnUpdate); } protected override async Task OnInitializedAsync() { try { await searchService.Load(); } catch { } try { await jsRuntime.InvokeVoidAsync("SetDotnetReference", DotNetObjectReference.Create(this)); } catch { } } public void Dispose() { searchService.Unsubscribe(OnUpdate); } void OnUpdate() { StateHasChanged(); } [JSInvokable("OnKeyPress")] public async Task OnKeyPress(string code, bool ctrlKey, bool shiftKey, bool altKey, bool metaKey) { if (code.ToLower().Equals("/")) { if (searchService.IsVisible) { searchService.Hide(); } else { searchService.Show(); } } } }