File tree 4 files changed +27
-13
lines changed
src/BootstrapBlazor/Components/AutoComplete
4 files changed +27
-13
lines changed Original file line number Diff line number Diff line change 5
5
{
6
6
<BootstrapLabel required =" @Required" for =" @InputId" ShowLabelTooltip =" ShowLabelTooltip" Value =" @DisplayText" />
7
7
}
8
- <div class =" @ClassString " id =" @Id" >
8
+ <div class =" auto-complete " id =" @Id" >
9
9
<input @attributes =" AdditionalAttributes" id =" @InputId" class =" @ClassName" autocomplete =" off" type =" text"
10
10
data-bs-toggle =" @ToggleString" data-bs-placement =" @PlacementString"
11
11
data-bs-offset =" @OffsetString" data-bs-custom-class =" @CustomClassString"
12
12
data-bb-auto-dropdown-focus =" @ShowDropdownListOnFocusString" data-bb-debounce =" @DurationString"
13
13
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 "
15
15
value =" @CurrentValueAsString"
16
16
placeholder =" @PlaceHolder" disabled =" @Disabled" @ref =" FocusElement" />
17
17
<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;
12
12
/// </summary>
13
13
public partial class AutoComplete
14
14
{
15
- /// <summary>
16
- /// Gets the component style
17
- /// </summary>
18
- private string ? ClassString => CssBuilder . Default ( "auto-complete" )
19
- . Build ( ) ;
20
-
21
15
/// <summary>
22
16
/// Gets or sets the collection of matching data obtained by inputting a string
23
17
/// </summary>
@@ -179,14 +173,26 @@ public override async Task TriggerFilter(string val)
179
173
[ JSInvokable ]
180
174
public override Task TriggerChange ( string val )
181
175
{
176
+ // client input does not need to be re-rendered to prevent jitter when the network is congested
182
177
_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
+ {
183
191
CurrentValue = val ;
184
192
if ( ! ValueChanged . HasDelegate )
185
193
{
186
194
StateHasChanged ( ) ;
187
195
}
188
- _render = true ;
189
- _dropdown . Render ( ) ;
190
196
return Task . CompletedTask ;
191
197
}
192
198
}
Original file line number Diff line number Diff line change @@ -157,6 +157,11 @@ const handlerKeyup = (ac, e) => {
157
157
current . classList . add ( 'active' ) ;
158
158
scrollIntoView ( el , current ) ;
159
159
}
160
+ else if ( key === 'Backspace' || key === 'Delete' ) {
161
+ if ( input . getAttribute ( 'data-bb-trigger-delete' ) === 'true' ) {
162
+ invoke . invokeMethodAsync ( 'TriggerDeleteCallback' , input . value ) ;
163
+ }
164
+ }
160
165
}
161
166
162
167
export function showList ( id ) {
Original file line number Diff line number Diff line change 3
3
// See the LICENSE file in the project root for more information.
4
4
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
5
5
6
- using Microsoft . AspNetCore . Components . Web ;
7
-
8
6
namespace UnitTest . Components ;
9
7
10
8
public class AutoCompleteTest : BootstrapBlazorTestBase
11
9
{
12
10
[ Fact ]
13
- public void Items_Ok ( )
11
+ public async Task Items_Ok ( )
14
12
{
15
13
var cut = Context . RenderComponent < AutoComplete > ( pb =>
16
14
{
17
15
pb . Add ( a => a . IsSelectAllTextOnFocus , true ) ;
18
16
pb . Add ( a => a . IsSelectAllTextOnEnter , true ) ;
19
17
} ) ;
20
18
Assert . Contains ( "<div class=\" auto-complete\" " , cut . Markup ) ;
19
+ Assert . Contains ( "data-bb-trigger-delete=\" true\" " , cut . Markup ) ;
20
+
21
21
var menus = cut . FindAll ( ".dropdown-item" ) ;
22
22
Assert . Single ( menus ) ;
23
23
@@ -35,6 +35,9 @@ public void Items_Ok()
35
35
} ) ;
36
36
menus = cut . FindAll ( ".dropdown-item" ) ;
37
37
Assert . Equal ( 2 , menus . Count ) ;
38
+
39
+ await cut . InvokeAsync ( ( ) => cut . Instance . TriggerDeleteCallback ( "Test" ) ) ;
40
+ Assert . Equal ( "Test" , cut . Instance . Value ) ;
38
41
}
39
42
40
43
[ Fact ]
You can’t perform that action at this time.
0 commit comments