File tree Expand file tree Collapse file tree
src/BootstrapBlazor/Components/AutoComplete Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55{
66 <BootstrapLabel required =" @Required" for =" @InputId" ShowLabelTooltip =" ShowLabelTooltip" Value =" @DisplayText" />
77}
8- <div class =" @ClassString " id =" @Id" >
8+ <div class =" auto-complete " id =" @Id" >
99 <input @attributes =" AdditionalAttributes" id =" @InputId" class =" @ClassName" autocomplete =" off" type =" text"
1010 data-bs-toggle =" @ToggleString" data-bs-placement =" @PlacementString"
1111 data-bs-offset =" @OffsetString" data-bs-custom-class =" @CustomClassString"
1212 data-bb-auto-dropdown-focus =" @ShowDropdownListOnFocusString" data-bb-debounce =" @DurationString"
1313 data-bb-skip-esc =" @SkipEscString" data-bb-skip-enter =" @SkipEnterString" data-bb-blur =" @TriggerBlurString"
14- data-bb-scroll-behavior =" @ScrollIntoViewBehaviorString"
14+ data-bb-scroll-behavior =" @ScrollIntoViewBehaviorString" data-bb-trigger-delete = " true "
1515 value =" @CurrentValueAsString"
1616 placeholder =" @PlaceHolder" disabled =" @Disabled" @ref =" FocusElement" />
1717 <span class =" form-select-append" ><i class =" @Icon" ></i ></span >
Original file line number Diff line number Diff line change @@ -12,12 +12,6 @@ namespace BootstrapBlazor.Components;
1212/// </summary>
1313public partial class AutoComplete
1414{
15- /// <summary>
16- /// Gets the component style
17- /// </summary>
18- private string ? ClassString => CssBuilder . Default ( "auto-complete" )
19- . Build ( ) ;
20-
2115 /// <summary>
2216 /// Gets or sets the collection of matching data obtained by inputting a string
2317 /// </summary>
@@ -179,14 +173,26 @@ public override async Task TriggerFilter(string val)
179173 [ JSInvokable ]
180174 public override Task TriggerChange ( string val )
181175 {
176+ // client input does not need to be re-rendered to prevent jitter when the network is congested
182177 _render = false ;
178+ CurrentValue = val ;
179+ _render = true ;
180+ _dropdown . Render ( ) ;
181+ return Task . CompletedTask ;
182+ }
183+
184+ /// <summary>
185+ /// TriggerChange method
186+ /// </summary>
187+ /// <param name="val"></param>
188+ [ JSInvokable ]
189+ public Task TriggerDeleteCallback ( string val )
190+ {
183191 CurrentValue = val ;
184192 if ( ! ValueChanged . HasDelegate )
185193 {
186194 StateHasChanged ( ) ;
187195 }
188- _render = true ;
189- _dropdown . Render ( ) ;
190196 return Task . CompletedTask ;
191197 }
192198}
Original file line number Diff line number Diff line change @@ -157,6 +157,11 @@ const handlerKeyup = (ac, e) => {
157157 current . classList . add ( 'active' ) ;
158158 scrollIntoView ( el , current ) ;
159159 }
160+ else if ( key === 'Backspace' || key === 'Delete' ) {
161+ if ( input . getAttribute ( 'data-bb-trigger-delete' ) === 'true' ) {
162+ invoke . invokeMethodAsync ( 'TriggerDeleteCallback' , input . value ) ;
163+ }
164+ }
160165}
161166
162167export function showList ( id ) {
Original file line number Diff line number Diff line change 33// See the LICENSE file in the project root for more information.
44// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
55
6- using Microsoft . AspNetCore . Components . Web ;
7-
86namespace UnitTest . Components ;
97
108public class AutoCompleteTest : BootstrapBlazorTestBase
119{
1210 [ Fact ]
13- public void Items_Ok ( )
11+ public async Task Items_Ok ( )
1412 {
1513 var cut = Context . RenderComponent < AutoComplete > ( pb =>
1614 {
1715 pb . Add ( a => a . IsSelectAllTextOnFocus , true ) ;
1816 pb . Add ( a => a . IsSelectAllTextOnEnter , true ) ;
1917 } ) ;
2018 Assert . Contains ( "<div class=\" auto-complete\" " , cut . Markup ) ;
19+ Assert . Contains ( "data-bb-trigger-delete=\" true\" " , cut . Markup ) ;
20+
2121 var menus = cut . FindAll ( ".dropdown-item" ) ;
2222 Assert . Single ( menus ) ;
2323
@@ -35,6 +35,9 @@ public void Items_Ok()
3535 } ) ;
3636 menus = cut . FindAll ( ".dropdown-item" ) ;
3737 Assert . Equal ( 2 , menus . Count ) ;
38+
39+ await cut . InvokeAsync ( ( ) => cut . Instance . TriggerDeleteCallback ( "Test" ) ) ;
40+ Assert . Equal ( "Test" , cut . Instance . Value ) ;
3841 }
3942
4043 [ Fact ]
You can’t perform that action at this time.
0 commit comments