From 45380821ad5d42972d7209ea349a1074e2f6162c Mon Sep 17 00:00:00 2001 From: markosteger Date: Wed, 15 Feb 2023 13:04:44 +0100 Subject: [PATCH] SimpleSelect - working example, waiting for css fix for not closing the select box upon clicking inside it --- .../Components/SimpleSelect.razor | 59 +++++++++++++++---- .../Components/SimpleSelect.razor.cs | 26 +++++++- 2 files changed, 70 insertions(+), 15 deletions(-) diff --git a/src/Connected.Components/Components/SimpleSelect.razor b/src/Connected.Components/Components/SimpleSelect.razor index 2d895a7..ec9c163 100644 --- a/src/Connected.Components/Components/SimpleSelect.razor +++ b/src/Connected.Components/Components/SimpleSelect.razor @@ -6,20 +6,53 @@ @if (Items is not null) { -
- @if (EnableSearch) - { - - } - + + @if (IsLabel) { - @if (item is not null) + + } + + + + + + @if (Clearable) { - + + + } - } - -
+ + + + @if (IsError) + { + + + + } + + + } \ No newline at end of file diff --git a/src/Connected.Components/Components/SimpleSelect.razor.cs b/src/Connected.Components/Components/SimpleSelect.razor.cs index d94a841..2baadb7 100644 --- a/src/Connected.Components/Components/SimpleSelect.razor.cs +++ b/src/Connected.Components/Components/SimpleSelect.razor.cs @@ -1,7 +1,5 @@ using Connected.Models; using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Web; -using System; namespace Connected.Components; public partial class SimpleSelect : InputBase @@ -31,6 +29,29 @@ public partial class SimpleSelect : InputBase } } + private string DropDownClass { get; set; } = "drop-down"; + + bool DropDownClicked = false; + + public void DropDownClassToggle() + { + DropDownClicked = !DropDownClicked; + if (DropDownClicked) + { + DropDownClass = ""; + } else + { + DropDownClass = "drop-down"; + } + StateHasChanged(); + } + + private async Task SetSelectedItem(ValueType item) + { + //DropDownClassToggle(); + await ValueChanged.InvokeAsync(item); + } + private async Task FilterItems() { if (string.IsNullOrEmpty(_searchText)) @@ -61,6 +82,7 @@ public partial class SimpleSelect : InputBase if (base.InputAttributes.ContainsKey("required")) base.InputAttributes.Add("required", true); } OriginalItems = Items; + if (_searchText.Length>0) await FilterItems(); await base.OnInitializedAsync(); } } \ No newline at end of file