From 99eb98bb08c2a5a5c038630e5ee57f52589c0f71 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Fri, 15 May 2020 14:51:27 +0300 Subject: [PATCH] Fixed issues: https://github.com/SamProf/MatBlazor/issues/315 - clear button https://github.com/SamProf/MatBlazor/issues/430 https://github.com/SamProf/MatBlazor/issues/246 - partial https://github.com/SamProf/MatBlazor/issues/213 --- .../Demo/DemoAutocomplete.razor | 4 +- .../Demo/DemoAutocompleteList.razor | 98 ++++++++++++++----- .../BaseMatAutocompleteList.cs | 11 ++- .../MatAutocompleteList.razor | 16 ++- 4 files changed, 99 insertions(+), 30 deletions(-) diff --git a/src/MatBlazor.Demo/Demo/DemoAutocomplete.razor b/src/MatBlazor.Demo/Demo/DemoAutocomplete.razor index e4a6139e..3e040f60 100644 --- a/src/MatBlazor.Demo/Demo/DemoAutocomplete.razor +++ b/src/MatBlazor.Demo/Demo/DemoAutocomplete.razor @@ -7,7 +7,7 @@
Example
- + @code { @@ -26,7 +26,7 @@ + @code { diff --git a/src/MatBlazor.Demo/Demo/DemoAutocompleteList.razor b/src/MatBlazor.Demo/Demo/DemoAutocompleteList.razor index 9bc931f2..fe91cb19 100644 --- a/src/MatBlazor.Demo/Demo/DemoAutocompleteList.razor +++ b/src/MatBlazor.Demo/Demo/DemoAutocompleteList.razor @@ -20,7 +20,7 @@ - @code @@ -45,7 +45,7 @@ - ")> @@ -57,7 +57,7 @@ - ")> @@ -75,7 +75,7 @@ -

+

Selected value: @(value?.Name)

@@ -110,9 +110,9 @@ } - + - i.Name)"" @bind-Value=""@value""> @@ -162,20 +162,20 @@
-
With Full Width
- - - - -
-
@context.Name
-
@context.Price$
-
-
-
-
- - With Full Width + + + + +
+
@context.Name
+
@context.Price$
+
+
+
+
+ + i.Name)"">
@@ -185,5 +185,59 @@ ")> - - \ No newline at end of file + + + +
In an edit form with a Data Annotation Validator
+ + + + + + + Submit + + @code + { + class AutocompleteContextModel + { + public List Options { get; set; } = new List() { "A test option", "Another test option", "One more option" }; + + [System.ComponentModel.DataAnnotations.Required] + public string SelectedOption { get; set; } + } + AutocompleteContextModel model = new AutocompleteContextModel(); + + void HandleValidSubmit() + { + Console.WriteLine("On Valid Submit"); + } + } + + + + + + + Submit + + @code + { + class AutocompleteContextModel + { + public List Options { get; set; } = new List() { ""A test option"", ""Another test option"", ""One more option"" }; + + [System.ComponentModel.DataAnnotations.Required] + public string SelectedOption { get; set; } + } + AutocompleteContextModel model = new AutocompleteContextModel(); + + void HandleValidSubmit() + { + Console.WriteLine(""On Valid Submit""); + } + } + ")> + + diff --git a/src/MatBlazor/Components/MatAutocompleteList/BaseMatAutocompleteList.cs b/src/MatBlazor/Components/MatAutocompleteList/BaseMatAutocompleteList.cs index 8a701433..4f904a2b 100644 --- a/src/MatBlazor/Components/MatAutocompleteList/BaseMatAutocompleteList.cs +++ b/src/MatBlazor/Components/MatAutocompleteList/BaseMatAutocompleteList.cs @@ -90,10 +90,13 @@ public TItem Value get { return _value; } set { - var newerStringValue = EqualValues(value, default) ? string.Empty : ComputeStringValue(value); - if (newerStringValue != StringValue) + if (!EqualValues(value, default)) { - StringValue = newerStringValue; + var newValue = ComputeStringValue(value); + if (newValue != StringValue) + { + StringValue = newValue; + } } if (EqualValues(value, _value)) @@ -175,6 +178,7 @@ protected void ClosePopup() if (StringValue != ComputeStringValue(Value)) { _value = default; + ValueChanged.InvokeAsync(_value); } IsOpened = false; } @@ -190,7 +194,6 @@ public async void OnKeyDown(KeyboardEventArgs ev) if (ev.Key == "ArrowDown" || ev.Key == "ArrowUp") { int currentIndex = await ListRef.GetSelectedIndex(); - int nextIndex = (ev.Key == "ArrowDown") ? currentIndex++ : currentIndex--; await ListRef.SetSelectedIndex(currentIndex); } else if (ev.Key == "Enter") diff --git a/src/MatBlazor/Components/MatAutocompleteList/MatAutocompleteList.razor b/src/MatBlazor/Components/MatAutocompleteList/MatAutocompleteList.razor index eeacf4be..b571f480 100644 --- a/src/MatBlazor/Components/MatAutocompleteList/MatAutocompleteList.razor +++ b/src/MatBlazor/Components/MatAutocompleteList/MatAutocompleteList.razor @@ -5,11 +5,23 @@
- + @if (IsShowingClearButton) {
- +
} @if (Items != null && IsOpened)