From bd3c3bb4a52ef81b069f94fb20d289189f153e3a Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Fri, 11 Mar 2022 22:09:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?doc:=20=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Samples/Selects.razor.cs | 272 +++++++++--------- 1 file changed, 136 insertions(+), 136 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Samples/Selects.razor.cs b/src/BootstrapBlazor.Shared/Samples/Selects.razor.cs index 19a4c8cba..5c1f2963a 100644 --- a/src/BootstrapBlazor.Shared/Samples/Selects.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/Selects.razor.cs @@ -39,63 +39,63 @@ public sealed partial class Selects /// private IEnumerable Items { get; set; } = new[] { - new SelectedItem ("Beijing", "北京"), - new SelectedItem ("Shanghai", "上海") { Active = true }, - }; + new SelectedItem ("Beijing", "北京"), + new SelectedItem ("Shanghai", "上海") { Active = true }, + }; /// /// 获得 默认数据集合 /// private readonly IEnumerable Items4 = new[] { - new SelectedItem ("Beijing", "北京") { IsDisabled = true}, - new SelectedItem ("Shanghai", "上海") { Active = true }, - new SelectedItem ("Guangzhou", "广州") - }; + new SelectedItem ("Beijing", "北京") { IsDisabled = true}, + new SelectedItem ("Shanghai", "上海") { Active = true }, + new SelectedItem ("Guangzhou", "广州") + }; /// /// 获得 默认数据集合 /// private readonly IEnumerable StringItems = new[] { - new SelectedItem ("1", "1"), - new SelectedItem ("12", "12"), - new SelectedItem ("123", "123"), - new SelectedItem ("1234", "1234"), - new SelectedItem ("a", "a"), - new SelectedItem ("ab", "ab"), - new SelectedItem ("abc", "abc"), - new SelectedItem ("abcd", "abcd"), - new SelectedItem ("abcde", "abcde") - }; + new SelectedItem ("1", "1"), + new SelectedItem ("12", "12"), + new SelectedItem ("123", "123"), + new SelectedItem ("1234", "1234"), + new SelectedItem ("a", "a"), + new SelectedItem ("ab", "ab"), + new SelectedItem ("abc", "abc"), + new SelectedItem ("abcd", "abcd"), + new SelectedItem ("abcde", "abcde") + }; /// /// 获得 默认数据集合 /// private readonly IEnumerable Items3 = new SelectedItem[] { - new SelectedItem ("", "请选择 ..."), - new SelectedItem ("Beijing", "北京") { Active = true }, - new SelectedItem ("Shanghai", "上海"), - new SelectedItem ("Hangzhou", "杭州") + new SelectedItem ("", "请选择 ..."), + new SelectedItem ("Beijing", "北京") { Active = true }, + new SelectedItem ("Shanghai", "上海"), + new SelectedItem ("Hangzhou", "杭州") }; private readonly IEnumerable GroupItems = new SelectedItem[] { - new SelectedItem ("Jilin", "吉林") { GroupName = "东北"}, - new SelectedItem ("Liaoning", "辽宁") {GroupName = "东北", Active = true }, - new SelectedItem ("Beijing", "北京") { GroupName = "华中"}, - new SelectedItem ("Shijiazhuang", "石家庄") { GroupName = "华中"}, - new SelectedItem ("Shanghai", "上海") {GroupName = "华东", Active = true }, - new SelectedItem ("Ningbo", "宁波") {GroupName = "华东", Active = true } + new SelectedItem ("Jilin", "吉林") { GroupName = "东北"}, + new SelectedItem ("Liaoning", "辽宁") {GroupName = "东北", Active = true }, + new SelectedItem ("Beijing", "北京") { GroupName = "华中"}, + new SelectedItem ("Shijiazhuang", "石家庄") { GroupName = "华中"}, + new SelectedItem ("Shanghai", "上海") {GroupName = "华东", Active = true }, + new SelectedItem ("Ningbo", "宁波") {GroupName = "华东", Active = true } }; private Guid CurrentGuid { get; set; } private readonly IEnumerable GuidItems = new SelectedItem[] { - new SelectedItem(Guid.NewGuid().ToString(), "Guid1"), - new SelectedItem(Guid.NewGuid().ToString(), "Guid2") + new SelectedItem(Guid.NewGuid().ToString(), "Guid1"), + new SelectedItem(Guid.NewGuid().ToString(), "Guid2") }; /// @@ -121,16 +121,16 @@ public sealed partial class Selects { Items2 = new SelectedItem[] { - new SelectedItem("1","朝阳区") { Active = true}, - new SelectedItem("2","海淀区"), + new SelectedItem("1","朝阳区") { Active = true}, + new SelectedItem("2","海淀区"), }; } else if (item.Value == "Shanghai") { Items2 = new SelectedItem[] { - new SelectedItem("1","静安区"), - new SelectedItem("2","黄浦区") { Active = true } , + new SelectedItem("1","静安区"), + new SelectedItem("2","黄浦区") { Active = true } , }; } else @@ -150,9 +150,9 @@ public sealed partial class Selects private IEnumerable NullableIntItems { get; set; } = new SelectedItem[] { - new SelectedItem() { Text = "Item 1", Value = "" }, - new SelectedItem() { Text = "Item 2", Value = "2" }, - new SelectedItem() { Text = "Item 3", Value = "3" } + new SelectedItem() { Text = "Item 1", Value = "" }, + new SelectedItem() { Text = "Item 2", Value = "2" }, + new SelectedItem() { Text = "Item 3", Value = "3" } }; private int? SelectedIntItem { get; set; } @@ -164,9 +164,9 @@ public sealed partial class Selects private IEnumerable NullableBoolItems { get; set; } = new SelectedItem[] { - new SelectedItem() { Text = "空值", Value = "" }, - new SelectedItem() { Text = "True 值", Value = "true" }, - new SelectedItem() { Text = "False 值", Value = "false" } + new SelectedItem() { Text = "空值", Value = "" }, + new SelectedItem() { Text = "True 值", Value = "true" }, + new SelectedItem() { Text = "False 值", Value = "false" } }; private bool? SelectedBoolItem { get; set; } @@ -191,18 +191,18 @@ public sealed partial class Selects /// private IEnumerable GetEvents() => new EventItem[] { - new EventItem() - { - Name = "OnSelectedItemChanged", - Description = Localizer["OnSelectedItemChanged"], - Type = "Func" - }, - new EventItem() - { - Name = "OnBeforeSelectedItemChange", - Description = Localizer["OnBeforeSelectedItemChange"], - Type = "Func>" - } + new EventItem() + { + Name = "OnSelectedItemChanged", + Description = Localizer["OnSelectedItemChanged"], + Type = "Func" + }, + new EventItem() + { + Name = "OnBeforeSelectedItemChange", + Description = Localizer["OnBeforeSelectedItemChange"], + Type = "Func>" + } }; /// @@ -211,90 +211,90 @@ public sealed partial class Selects /// private IEnumerable GetAttributes() => new AttributeItem[] { - // TODO: 移动到数据库中 - new AttributeItem() { - Name = "ShowLabel", - Description = Localizer["ShowLabel"], - Type = "bool", - ValueList = "true|false", - DefaultValue = "true" - }, - new AttributeItem() { - Name = "ShowSearch", - Description = Localizer["ShowSearch"], - Type = "bool", - ValueList = "true|false", - DefaultValue = "false" - }, - new AttributeItem() { - Name = "DisplayText", - Description = Localizer["DisplayText"], - Type = "string", - ValueList = " — ", - DefaultValue = " — " - }, - new AttributeItem() { - Name = "Class", - Description = Localizer["Class"], - Type = "string", - ValueList = " — ", - DefaultValue = " — " - }, - new AttributeItem() { - Name = "Color", - Description = Localizer["Color"], - Type = "Color", - ValueList = "Primary / Secondary / Success / Danger / Warning / Info / Dark", - DefaultValue = "Primary" - }, - new AttributeItem() { - Name = "IsDisabled", - Description = Localizer["IsDisabled"], - Type = "boolean", - ValueList = "true / false", - DefaultValue = "false" - }, - new AttributeItem() { - Name = "Items", - Description = Localizer["Items"], - Type = "IEnumerable", - ValueList = " — ", - DefaultValue = " — " - }, - new AttributeItem() { - Name = "SelectItems", - Description = Localizer["SelectItems"], - Type = "RenderFragment", - ValueList = " — ", - DefaultValue = " — " - }, - new AttributeItem() { - Name = "ItemTemplate", - Description = Localizer["ItemTemplate"], - Type = "RenderFragment", - ValueList = " — ", - DefaultValue = " — " - }, - new AttributeItem() { - Name = "ChildContent", - Description = Localizer["ChildContent"], - Type = "RenderFragment", - ValueList = " — ", - DefaultValue = " — " - }, - new AttributeItem() { - Name = "Category", - Description = Localizer["Category"], - Type = "SwalCategory", - ValueList = " — ", - DefaultValue = " SwalCategory.Information " - }, - new AttributeItem() { - Name = "Content", - Description = Localizer["Content"], - Type = "string?", - ValueList = " — ", - DefaultValue = Localizer["ContentDefaultValue"]! - } + // TODO: 移动到数据库中 + new AttributeItem() { + Name = "ShowLabel", + Description = Localizer["ShowLabel"], + Type = "bool", + ValueList = "true|false", + DefaultValue = "true" + }, + new AttributeItem() { + Name = "ShowSearch", + Description = Localizer["ShowSearch"], + Type = "bool", + ValueList = "true|false", + DefaultValue = "false" + }, + new AttributeItem() { + Name = "DisplayText", + Description = Localizer["DisplayText"], + Type = "string", + ValueList = " — ", + DefaultValue = " — " + }, + new AttributeItem() { + Name = "Class", + Description = Localizer["Class"], + Type = "string", + ValueList = " — ", + DefaultValue = " — " + }, + new AttributeItem() { + Name = "Color", + Description = Localizer["Color"], + Type = "Color", + ValueList = "Primary / Secondary / Success / Danger / Warning / Info / Dark", + DefaultValue = "Primary" + }, + new AttributeItem() { + Name = "IsDisabled", + Description = Localizer["IsDisabled"], + Type = "boolean", + ValueList = "true / false", + DefaultValue = "false" + }, + new AttributeItem() { + Name = "Items", + Description = Localizer["Items"], + Type = "IEnumerable", + ValueList = " — ", + DefaultValue = " — " + }, + new AttributeItem() { + Name = "SelectItems", + Description = Localizer["SelectItems"], + Type = "RenderFragment", + ValueList = " — ", + DefaultValue = " — " + }, + new AttributeItem() { + Name = "ItemTemplate", + Description = Localizer["ItemTemplate"], + Type = "RenderFragment", + ValueList = " — ", + DefaultValue = " — " + }, + new AttributeItem() { + Name = "ChildContent", + Description = Localizer["ChildContent"], + Type = "RenderFragment", + ValueList = " — ", + DefaultValue = " — " + }, + new AttributeItem() { + Name = "Category", + Description = Localizer["Category"], + Type = "SwalCategory", + ValueList = " — ", + DefaultValue = " SwalCategory.Information " + }, + new AttributeItem() { + Name = "Content", + Description = Localizer["Content"], + Type = "string?", + ValueList = " — ", + DefaultValue = Localizer["ContentDefaultValue"]! + } }; } -- Gitee From 3d876d2bbf934dd8055a7b818784bb3102df0653 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Sat, 12 Mar 2022 00:50:51 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=BB=9A=E5=8A=A8=E4=B8=8B=E6=8B=89=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Select/Select.js | 34 ++++++++++++++++--- .../wwwroot/js/bootstrap.blazor.bundle.min.js | 2 +- .../wwwroot/js/bootstrap.blazor.min.js | 2 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/BootstrapBlazor/Components/Select/Select.js b/src/BootstrapBlazor/Components/Select/Select.js index 4bd58681b..148ca6a2a 100644 --- a/src/BootstrapBlazor/Components/Select/Select.js +++ b/src/BootstrapBlazor/Components/Select/Select.js @@ -4,6 +4,27 @@ var $el = $(el); var $search = $el.find('input.search-text'); + var bb_scrollToActive = function ($el) { + var $menu = $el.find('.dropdown-menu'); + var $activeItem = $menu.children('.preActive'); + if ($activeItem.length === 0) { + $activeItem = $menu.children('.active'); + $activeItem.addClass('preActive'); + } + if ($activeItem.length === 1) { + var height = $menu.innerHeight(); + var itemHeight = $activeItem.outerHeight(); + var index = $activeItem.index() + 1; + var margin = 11 + itemHeight * index - height; + if (margin >= 0) { + $menu.scrollTop(margin); + } + else { + $menu.scrollTop(0); + } + } + }; + $el.on('show.bs.dropdown', function (e) { if ($el.find('.form-select').prop('disabled')) { e.preventDefault(); @@ -14,6 +35,7 @@ if ($search.length > 0) { $search.focus(); } + bb_scrollToActive($(this)); }); $el.on('keyup', function (e) { @@ -22,25 +44,27 @@ var $items = $this.find('.dropdown-menu.show > .dropdown-item').not('.disabled, .search'); var $activeItem = $items.filter(function (index, ele) { - return $(ele).hasClass('active'); + return $(ele).hasClass('preActive'); }); if ($items.length > 1) { if (e.key === "ArrowUp") { - $activeItem.removeClass('active'); + $activeItem.removeClass('preActive'); var $prev = $activeItem.prev().not('.disabled, .search'); if ($prev.length === 0) { $prev = $items.last(); } - $prev.addClass('active'); + $prev.addClass('preActive'); + bb_scrollToActive($this); } else if (e.key === "ArrowDown") { - $activeItem.removeClass('active'); + $activeItem.removeClass('preActive'); var $next = $activeItem.next().not('.disabled, .search'); if ($next.length === 0) { $next = $items.first(); } - $next.addClass('active'); + $next.addClass('preActive'); + bb_scrollToActive($this); } } diff --git a/src/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js b/src/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js index e84fd4103..a6c2146be 100644 --- a/src/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js +++ b/src/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js @@ -13,4 +13,4 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this /*! Summernote v0.8.18 | (c) 2013- Alan Hong and other contributors | MIT license */ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("jquery"));else if("function"==typeof define&&define.amd)define(["jquery"],e);else{var n="object"==typeof exports?e(require("jquery")):e(t.jQuery);for(var o in n)("object"==typeof exports?exports:t)[o]=n[o]}}(self,(function(t){return(()=>{"use strict";var e={9458:e=>{e.exports=t}},n={};function o(t){var i=n[t];if(void 0!==i)return i.exports;var r=n[t]={exports:{}};return e[t](r,r.exports,o),r.exports}o.amdO={},o.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return o.d(e,{a:e}),e},o.d=(t,e)=>{for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{o.r(i);var t=o(9458),e=o.n(t);function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,e){for(var n=0;n'),u=s('