File tree Expand file tree Collapse file tree 4 files changed +26
-3
lines changed
src/Forms/InputComponents
testassets/BasicTestApp/FormsTest Expand file tree Collapse file tree 4 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ public abstract class InputBase<T> : ComponentBase
42
42
/// <summary>
43
43
/// Gets or sets a callback that updates the bound value.
44
44
/// </summary>
45
- [ Parameter ] Action < T > ValueChanged { get ; set ; }
45
+ [ Parameter ] EventCallback < T > ValueChanged { get ; set ; }
46
46
47
47
/// <summary>
48
48
/// Gets or sets an expression that identifies the bound value.
@@ -71,7 +71,7 @@ protected T CurrentValue
71
71
if ( hasChanged )
72
72
{
73
73
Value = value ;
74
- ValueChanged ? . Invoke ( value ) ;
74
+ _ = ValueChanged . InvokeAsync ( value ) ;
75
75
EditContext . NotifyFieldChanged ( FieldIdentifier ) ;
76
76
}
77
77
}
Original file line number Diff line number Diff line change @@ -459,7 +459,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
459
459
{
460
460
childBuilder . OpenComponent < TComponent > ( 0 ) ;
461
461
childBuilder . AddAttribute ( 0 , "Value" , Value ) ;
462
- childBuilder . AddAttribute ( 1 , "ValueChanged" , ValueChanged ) ;
462
+ childBuilder . AddAttribute ( 1 , "ValueChanged" ,
463
+ EventCallback . Factory . Create ( this , ValueChanged ) ) ;
463
464
childBuilder . AddAttribute ( 2 , "ValueExpression" , ValueExpression ) ;
464
465
childBuilder . AddAttribute ( 3 , nameof ( Id ) , Id ) ;
465
466
childBuilder . AddAttribute ( 4 , nameof ( Class ) , Class ) ;
Original file line number Diff line number Diff line change @@ -316,6 +316,27 @@ public void ValidationMessageDisplaysMessagesForField()
316
316
WaitAssert . Empty ( emailMessagesAccessor ) ;
317
317
}
318
318
319
+ [ Fact ]
320
+ public void InputComponentsCauseContainerToRerenderOnChange ( )
321
+ {
322
+ var appElement = MountTestComponent < TypicalValidationComponent > ( ) ;
323
+ var ticketClassInput = new SelectElement ( appElement . FindElement ( By . ClassName ( "ticket-class" ) ) . FindElement ( By . TagName ( "select" ) ) ) ;
324
+ var selectedTicketClassDisplay = appElement . FindElement ( By . Id ( "selected-ticket-class" ) ) ;
325
+ var messagesAccessor = CreateValidationMessagesAccessor ( appElement ) ;
326
+
327
+ // Shows initial state
328
+ WaitAssert . Equal ( "Economy" , ( ) => selectedTicketClassDisplay . Text ) ;
329
+
330
+ // Refreshes on edit
331
+ ticketClassInput . SelectByValue ( "Premium" ) ;
332
+ WaitAssert . Equal ( "Premium" , ( ) => selectedTicketClassDisplay . Text ) ;
333
+
334
+ // Leaves previous value unchanged if new entry is unparseable
335
+ ticketClassInput . SelectByText ( "(select)" ) ;
336
+ WaitAssert . Equal ( new [ ] { "The TicketClass field is not valid." } , messagesAccessor ) ;
337
+ WaitAssert . Equal ( "Premium" , ( ) => selectedTicketClassDisplay . Text ) ;
338
+ }
339
+
319
340
private Func < string [ ] > CreateValidationMessagesAccessor ( IWebElement appElement )
320
341
{
321
342
return ( ) => appElement . FindElements ( By . ClassName ( "validation-message" ) )
Original file line number Diff line number Diff line change 34
34
<option value =" @TicketClass.Premium" >Premium class</option >
35
35
<option value =" @TicketClass.First" >First class</option >
36
36
</InputSelect >
37
+ <span id =" selected-ticket-class" >@person.TicketClass </span >
37
38
</p >
38
39
<p class =" accepts-terms" >
39
40
Accepts terms: <InputCheckbox bind-Value =" @person.AcceptsTerms" />
You can’t perform that action at this time.
0 commit comments