From 2ecbddc795b3904a2913e87f06a901bfb2614df2 Mon Sep 17 00:00:00 2001 From: Dustin Tran Date: Thu, 24 Feb 2022 12:54:10 +1300 Subject: [PATCH] Add an option to keep the menu open after selecting --- src/Blazored.Typeahead/BlazoredTypeahead.razor.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Blazored.Typeahead/BlazoredTypeahead.razor.cs b/src/Blazored.Typeahead/BlazoredTypeahead.razor.cs index 623aaf6..54a06a6 100644 --- a/src/Blazored.Typeahead/BlazoredTypeahead.razor.cs +++ b/src/Blazored.Typeahead/BlazoredTypeahead.razor.cs @@ -55,6 +55,8 @@ public partial class BlazoredTypeahead : ComponentBase, IDisposab [Parameter] public bool StopPropagation { get; set; } = false; [Parameter] public bool PreventDefault { get; set; } = false; + /// The option to keep the menu open after selecting + [Parameter] public bool CloseOnSelect { get; set; } = true; private bool IsSearching { get; set; } = false; private bool IsShowingSuggestions { get; set; } = false; @@ -132,10 +134,10 @@ protected override async Task OnAfterRenderAsync(bool firstRender) } } - private void Initialize() + private void Initialize(bool isShowingSuggestions = false) { SearchText = ""; - IsShowingSuggestions = false; + IsShowingSuggestions = isShowingSuggestions; IsShowingMask = Value != null; } @@ -424,7 +426,7 @@ private async Task SelectResult(TItem item) _editContext?.NotifyFieldChanged(_fieldIdentifier); - Initialize(); + Initialize(isShowingSuggestions: !CloseOnSelect); } private async Task SelectNotFoundPlaceholder()