diff --git a/src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj b/src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj index 91a9a635..52d4ef57 100644 --- a/src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj +++ b/src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj @@ -1,11 +1,11 @@  - 9.0.8 + 9.0.9 - 10.0.0-rc.2.1.0 + 10.0.0-rc.2.1.1 diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs index 5ba16656..9eac13fb 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs @@ -1,4 +1,4 @@ -// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. +// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/ @@ -55,6 +55,7 @@ public partial class SelectCity private readonly HashSet _values = []; private string? _searchText; + private bool _showSearch; private string? GetActiveClass(string item) => CssBuilder.Default() .AddClass("active", _values.Contains(item) && IsMultiple) @@ -75,6 +76,32 @@ protected override void OnParametersSet() { _values.Clear(); } + + if (ShowSearch == false) + { + _searchText = ""; + } + } + + /// + /// + /// + /// + /// + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await base.OnAfterRenderAsync(firstRender); + + if (firstRender) + { + _showSearch = ShowSearch; + } + + if (!_showSearch != ShowSearch) + { + _showSearch = ShowSearch; + await InvokeVoidAsync("resetSearch", Id, ShowSearch); + } } /// diff --git a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.js b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.js index 8c4e9a4d..311d51fe 100644 --- a/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.js +++ b/src/components/BootstrapBlazor.Region/Components/SelectCity.razor.js @@ -1,13 +1,14 @@ -import Data from "../../BootstrapBlazor/modules/data.js" +import Data from "../../BootstrapBlazor/modules/data.js" import EventHandler from "../../BootstrapBlazor/modules/event-handler.js" import Input from "../../BootstrapBlazor/modules/input.js" import Popover from "../../BootstrapBlazor/modules/base-popover.js" export function init(id, invoke, options) { - const el = document.getElementById(id) + const el = document.getElementById(id); if (el === null) { return } + const popover = Popover.init(el, { shownCallback: () => { if (searchInput != null) { @@ -16,6 +17,24 @@ export function init(id, invoke, options) { } }); + const region = { el, invoke, options, popover }; + initSearch(region); + Data.set(id, region); +} + +export function resetSearch(id, search) { + const region = Data.get(id); + + if (search) { + initSearch(region) + } + else { + disposeSearch(region); + } +} + +const initSearch = region => { + const { el, invoke, options } = region; const searchInput = el.querySelector(".search-text"); if (searchInput) { Input.composition(searchInput, async v => { @@ -31,7 +50,18 @@ export function init(id, invoke, options) { }); } - Data.set(id, { el, popover, searchInput, search }); + region.searchInput = searchInput; + region.search = search; +} + +const disposeSearch = region => { + const { searchInput, search } = region; + if (searchInput) { + Input.dispose(searchInput); + } + if (search) { + EventHandler.off(search, 'click'); + } } export function hide(id) { @@ -46,14 +76,10 @@ export function dispose(id) { const region = Data.get(id) Data.remove(id) - const { popover, searchInput, search } = region; + const { popover } = region; if (popover) { Popover.dispose(popover); } - if (searchInput) { - Input.dispose(searchInput); - } - if (search) { - EventHandler.off(search, 'click'); - } + + disposeSearch(region); }