diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index c4efc71a97..1529ed3156 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -15,6 +15,61 @@ timeline: true --- +### 0.8.1 + +`2021-05-13` + +- Overlay + - 🐞 Fixed positioning should take scroll into account. [#1511](https://github.com/ant-design-blazor/ant-design-blazor/pull/1511) [@ocoka](https://github.com/ocoka) + - 🐞 Fixed issues in boundaryAdjustMode. [#1420](https://github.com/ant-design-blazor/ant-design-blazor/pull/1420) [@mutouzdl](https://github.com/mutouzdl) + +- Input + - 🐞 Fixed for Guid type. [#1510](https://github.com/ant-design-blazor/ant-design-blazor/pull/1510) [@anranruye](https://github.com/anranruye) + - 🐞 Added `CultureInfo` attribute to `Input` type components. [#1480](https://github.com/ant-design-blazor/ant-design-blazor/pull/1480) [@anddrzejb](https://github.com/anddrzejb) + - 🐞 Fixed binding data when the Enter key is pressed. [#1375](https://github.com/ant-design-blazor/ant-design-blazor/pull/1375) [@ElderJames](https://github.com/ElderJames) + +- Table + - 🐞 Fixed built-in filter select option width. [#1500](https://github.com/ant-design-blazor/ant-design-blazor/pull/1500) [@anranruye](https://github.com/anranruye) + - 🐞 Fixed error for EndsWith filter operator. [#1434](https://github.com/ant-design-blazor/ant-design-blazor/pull/1434) [@anranruye](https://github.com/anranruye) + - 🐞 Fixed column header sorter not refresh after ClearSorter is called [#1385](https://github.com/ant-design-blazor/ant-design-blazor/pull/1385) [@anranruye](https://github.com/anranruye) + - 🐞 Fixed can not use DataIndex nullable mode with not nullable property [#1382](https://github.com/ant-design-blazor/ant-design-blazor/pull/1382) [@anranruye](https://github.com/anranruye) + - 🐞 Fixed Filter for DataIndex. Unify FieldName, add DisplayAttribute for DiplayName. [#1372](https://github.com/ant-design-blazor/ant-design-blazor/pull/1372) [@Zonciu](https://github.com/Zonciu) + - 🐞 Fixed ellipsis can't work. [#1376](https://github.com/ant-design-blazor/ant-design-blazor/pull/1376) [@ElderJames](https://github.com/ElderJames) + +- Cascader + - 🐞 Fixed showSearch. [#1484](https://github.com/ant-design-blazor/ant-design-blazor/pull/1484) [@ElderJames](https://github.com/ElderJames) + - 🐞 Fixed invoking SelectedNodesChanged after clear selected. [#1437](https://github.com/ant-design-blazor/ant-design-blazor/pull/1437) [@ElderJames](https://github.com/ElderJames) + - 🐞 Fixed incorrect size. [#1432](https://github.com/ant-design-blazor/ant-design-blazor/pull/1432) [@ElderJames](https://github.com/ElderJames) + +- DatePicker + - 🐞 Fixed panel click closing + some issues from #1431. [#1452](https://github.com/ant-design-blazor/ant-design-blazor/pull/1452) [@anddrzejb](https://github.com/anddrzejb) + - 🐞 Fixed validate manually entered date against format. [#1389](https://github.com/ant-design-blazor/ant-design-blazor/pull/1389) [@anddrzejb](https://github.com/anddrzejb) + +- Modal + - 🐞 Fixed Delay time to DOM_ MIN_ TIMEOUT_ VALUE (4ms). [#1445](https://github.com/ant-design-blazor/ant-design-blazor/pull/1445) [@zxyao145](https://github.com/zxyao145) + - 🐞 Fixed add Dispose lifecycle function to Dialog. [#1379](https://github.com/ant-design-blazor/ant-design-blazor/pull/1379) [@zxyao145](https://github.com/zxyao145) + - 🆕 support define modal's style in ModalOptions [#1400](https://github.com/ant-design-blazor/ant-design-blazor/pull/1400) [@zxyao145](https://github.com/zxyao145) + +- Form + - 🆕 Select mutliple/tags can be used in forms. [#1460](https://github.com/ant-design-blazor/ant-design-blazor/pull/1460) [@anddrzejb](https://github.com/anddrzejb) + - 🐞 Fixed validation message unique [#1391](https://github.com/ant-design-blazor/ant-design-blazor/pull/1391) [@ElderJames](https://github.com/ElderJames) + +- Select + - 🐞 Fixed error for nullable TItem of SelectOption. [#1451](https://github.com/ant-design-blazor/ant-design-blazor/pull/1451) [@anranruye](https://github.com/anranruye) + - 🛠 Refactor: use ResizeObserver Api instead of window.resize. [#1392](https://github.com/ant-design-blazor/ant-design-blazor/pull/1392) [@anddrzejb](https://github.com/anddrzejb) + - 🐞 Fixed OnDataSourceChange called when expected. [#1419](https://github.com/ant-design-blazor/ant-design-blazor/pull/1419) [@anddrzejb](https://github.com/anddrzejb) + - 🐞 Fixed enum default value protection. [#1368](https://github.com/ant-design-blazor/ant-design-blazor/pull/1368) [@anddrzejb](https://github.com/anddrzejb) + +- 🐞 Fixed checkbox remove Value initialization blocking. [#1459](https://github.com/ant-design-blazor/ant-design-blazor/pull/1459) [@anddrzejb](https://github.com/anddrzejb) +- 🐞 Fixed input number self changing. [#1490](https://github.com/ant-design-blazor/ant-design-blazor/pull/1490) [@CAPCHIK](https://github.com/CAPCHIK) +- 🐞 `Checkbox` and `Switch` allow now binding to `Changed` property. `Value` and `Changed` properties can be used interchangeably. [#1394](https://github.com/ant-design-blazor/ant-design-blazor/pull/1394) [@anddrzejb](https://github.com/anddrzejb) +- 🐞 Fixed Tag closable typo and delete mode [#1393](https://github.com/ant-design-blazor/ant-design-blazor/pull/1393) [@ElderJames](https://github.com/ElderJames) +- 🐞 Fixed PasswordInput for retrieving and setting the `selectionStart`; Override `onClick`. [#1377](https://github.com/ant-design-blazor/ant-design-blazor/pull/1377) [@MihailsKuzmins](https://github.com/MihailsKuzmins) +- 🆕 feat: add element component. [#1378](https://github.com/ant-design-blazor/ant-design-blazor/pull/1378) [@ElderJames](https://github.com/ElderJames) +- 🐞 Fixed Affix can't affix while OffsetTop is zero. [#1373](https://github.com/ant-design-blazor/ant-design-blazor/pull/1373) [@ElderJames](https://github.com/ElderJames) +- 🐞 Fixed js function getDom return null bug. [#1417](https://github.com/ant-design-blazor/ant-design-blazor/pull/1417) [@zxyao145](https://github.com/zxyao145) +- 🐞 Fixed dropdown width for IE. [#1469](https://github.com/ant-design-blazor/ant-design-blazor/pull/1469) [@anranruye](https://github.com/anranruye) + ### 0.8.0 `2021-04-15` diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index e365ef1a95..38285e7c5a 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -15,24 +15,91 @@ timeline: true --- +### 0.8.1 + +`2021-05-13` + +- Overlay + + - 🐞 修复 计算高度时加上滚动高度[#1511](https://github.com/ant-design-blazor/ant-design-blazor/pull/1511) [@ocoka](https://github.com/ocoka) + - 🐞 修复 边界调整的问题[#1420](https://github.com/ant-design-blazor/ant-design-blazor/pull/1420) [@mutouzdl](https://github.com/mutouzdl) + +- Input + + - 🐞 修复 不能使用 Guid 类型的问题。[#1510](https://github.com/ant-design-blazor/ant-design-blazor/pull/1510) [@anranruye](https://github.com/anranruye) + - 🐞 修复 字符串与特定类型的转换问题,增加了 `CultureInfo` 属性。[#1480](https://github.com/ant-design-blazor/ant-design-blazor/pull/1480) [@anddrzejb](https://github.com/anddrzejb) + - 🐞 修复 按回车键的数据绑定问题。[#1375](https://github.com/ant-design-blazor/ant-design-blazor/pull/1375) [@ElderJames](https://github.com/ElderJames) + +- Table + + - 🐞 修复 内置筛选器选项菜单的宽度[#1500](https://github.com/ant-design-blazor/ant-design-blazor/pull/1500) [@anranruye](https://github.com/anranruye) + - 🐞 修复 使用“结尾是”过滤条件时的错误。[#1434](https://github.com/ant-design-blazor/ant-design-blazor/pull/1434) [@anranruye](https://github.com/anranruye) + - 🐞 修复 点击清除排序时不刷新的问题。[#1385](https://github.com/ant-design-blazor/ant-design-blazor/pull/1385) [@anranruye](https://github.com/anranruye) + - 🐞 修复 无法使用 DataIndex 绑定可空属性的问题[#1382](https://github.com/ant-design-blazor/ant-design-blazor/pull/1382) [@anranruye](https://github.com/anranruye) + - 🐞 修复 筛选器对 DataIndex 的支持,统一 FieldName 定义,添加列名 DisplayAttribute 支持。[#1372](https://github.com/ant-design-blazor/ant-design-blazor/pull/1372) [@Zonciu](https://github.com/Zonciu) + - 🐞 修复 ellipsis 无效的问题。[#1376](https://github.com/ant-design-blazor/ant-design-blazor/pull/1376) [@ElderJames](https://github.com/ElderJames) + +- Cascader + + - 🐞 修复 搜索功能。[#1484](https://github.com/ant-design-blazor/ant-design-blazor/pull/1484) [@ElderJames](https://github.com/ElderJames) + - 🐞 修复 当点击清楚按钮时触发 SelectedNodesChanged。[#1437](https://github.com/ant-design-blazor/ant-design-blazor/pull/1437) [@ElderJames](https://github.com/ElderJames) + - 🐞 修复 无法设置 Size 的问题。[#1432](https://github.com/ant-design-blazor/ant-design-blazor/pull/1432) [@ElderJames](https://github.com/ElderJames) + +- DatePicker + + - 🐞 修复 DatePicker 点击面板头部会关闭问题[#1452](https://github.com/ant-design-blazor/ant-design-blazor/pull/1452) [@anddrzejb](https://github.com/anddrzejb) + - 🐞 修复 验证手动输入格式的问题[#1389](https://github.com/ant-design-blazor/ant-design-blazor/pull/1389) [@anddrzejb](https://github.com/anddrzejb) + +- Modal + + - 🆕 可通过 ModalOptions 设置 Style。 [#1400](https://github.com/ant-design-blazor/ant-design-blazor/pull/1400) [@zxyao145](https://github.com/zxyao145) + - 🐞 修改 Dialog 组件中 Mask 点击判断 Task.Delay 的时间为 DOM* MIN* TIMEOUT\_ VALUE (4ms)。[#1445](https://github.com/ant-design-blazor/ant-design-blazor/pull/1445) [@zxyao145](https://github.com/zxyao145) + - 🐞 修复 Dialog 关闭时不恢复显示滚动条的问题,为 Dialog 添加 Dispose。[#1379](https://github.com/ant-design-blazor/ant-design-blazor/pull/1379) [@zxyao145](https://github.com/zxyao145) + +- Form + + - 🆕 使 Form 支持集合,Select 可绑定 Values[#1460](https://github.com/ant-design-blazor/ant-design-blazor/pull/1460) [@anddrzejb](https://github.com/anddrzejb) + - 🐞 修复验证信息会重复的问题[#1391](https://github.com/ant-design-blazor/ant-design-blazor/pull/1391) [@ElderJames](https://github.com/ElderJames) + +- Select + + - 🐞 修复在 SelectOption 中使用可空值类型时的错误。[#1451](https://github.com/ant-design-blazor/ant-design-blazor/pull/1451) [@anranruye](https://github.com/anranruye) + - 🛠 使用 ResizeObserver 重构响应式时浏览器尺寸事件的订阅[#1392](https://github.com/ant-design-blazor/ant-design-blazor/pull/1392) [@anddrzejb](https://github.com/anddrzejb) + - 🐞 当 DataSource 改变时触发 OnDataSourceChanged[#1419](https://github.com/ant-design-blazor/ant-design-blazor/pull/1419) [@anddrzejb](https://github.com/anddrzejb) + - 🐞 修复值为枚举时的问题[#1368](https://github.com/ant-design-blazor/ant-design-blazor/pull/1368) [@anddrzejb](https://github.com/anddrzejb) + +- 🆕 新增 Element 组件,用于动态渲染元素[#1378](https://github.com/ant-design-blazor/ant-design-blazor/pull/1378) [@ElderJames](https://github.com/ElderJames) +- 🐞 修复 Checkbox 的 Value 在初始化时是阻塞[#1459](https://github.com/ant-design-blazor/ant-design-blazor/pull/1459) [@anddrzejb](https://github.com/anddrzejb) +- 🐞 修复 InputNumber 按住时,离开组件还会自增的问题。[#1490](https://github.com/ant-design-blazor/ant-design-blazor/pull/1490) [@CAPCHIK](https://github.com/CAPCHIK) +- 🐞 修复 `Checkbox` and `Switch` 组件的 Value 和 Checked 绑定问题[#1394](https://github.com/ant-design-blazor/ant-design-blazor/pull/1394) [@anddrzejb](https://github.com/anddrzejb) +- 🐞 修复 Tag 的 closable 拼写错误,和删除 Mode 属性[#1393](https://github.com/ant-design-blazor/ant-design-blazor/pull/1393) [@ElderJames](https://github.com/ElderJames) +- 🐞 修复 InputPassword 切换明文时,保持焦点和光标位置。[#1377](https://github.com/ant-design-blazor/ant-design-blazor/pull/1377) [@MihailsKuzmins](https://github.com/MihailsKuzmins) +- 🐞 修复 Affix 当 OffsetTop 为 0 时不能钉住的问题。[#1373](https://github.com/ant-design-blazor/ant-design-blazor/pull/1373) [@ElderJames](https://github.com/ElderJames) +- 🐞 修复 getDom 函数可能返回 null 的 bug。[#1417](https://github.com/ant-design-blazor/ant-design-blazor/pull/1417) [@zxyao145](https://github.com/zxyao145) +- 🐞 修复 IE 浏览器下拉选项宽度为 0 的问题。[#1469](https://github.com/ant-design-blazor/ant-design-blazor/pull/1469) [@anranruye](https://github.com/anranruye) + ### 0.8.0 `2021-04-15` - 主题和国际化 + - 🔥 文档支持主题色的动态切换[#1332](https://github.com/ant-design-blazor/ant-design-blazor/pull/1332) [@ElderJames](https://github.com/ElderJames) - 🔥 增加 RTL 切换。[#1238](https://github.com/ant-design-blazor/ant-design-blazor/pull/1238) [@ElderJames](https://github.com/ElderJames) - 🔥 加入内置主题样式。[#1286](https://github.com/ant-design-blazor/ant-design-blazor/pull/1286) [@ElderJames](https://github.com/ElderJames) - Form + - 📖 修改 IsModified 的实例。[#1344](https://github.com/ant-design-blazor/ant-design-blazor/pull/1344) [@anddrzejb](https://github.com/anddrzejb) - 🆕 增加 LabelAlign 属性,可使 Label 左对齐[#1292](https://github.com/ant-design-blazor/ant-design-blazor/pull/1292) [@unsung189](https://github.com/unsung189) - Select - - 🆕 增加 `MaxCountTag`, `MaxTagPlaceholder` 和 `MaxTagTextLenght`,以支持Tag模式的响应式处理。[#1338](https://github.com/ant-design-blazor/ant-design-blazor/pull/1338) [@anddrzejb](https://github.com/anddrzejb) - - 🆕 增加 `PopupContainerGrowToMatchWidestItem` 和`PopupContainerMaxWidth` ,使下拉列表的宽度适应内容或Input的宽度[#1309](https://github.com/ant-design-blazor/ant-design-blazor/pull/1309) [@anddrzejb](https://github.com/anddrzejb) + + - 🆕 增加 `MaxCountTag`, `MaxTagPlaceholder` 和 `MaxTagTextLenght`,以支持 Tag 模式的响应式处理。[#1338](https://github.com/ant-design-blazor/ant-design-blazor/pull/1338) [@anddrzejb](https://github.com/anddrzejb) + - 🆕 增加 `PopupContainerGrowToMatchWidestItem` 和`PopupContainerMaxWidth` ,使下拉列表的宽度适应内容或 Input 的宽度[#1309](https://github.com/ant-design-blazor/ant-design-blazor/pull/1309) [@anddrzejb](https://github.com/anddrzejb) - Table + - 🔥 增加内置筛选器[#1267](https://github.com/ant-design-blazor/ant-design-blazor/pull/1267) [@YMohd](https://github.com/YMohd) - 🆕 支持 DisplayAttribute 特性指定列名[#1310](https://github.com/ant-design-blazor/ant-design-blazor/pull/1310) [@anranruye](https://github.com/anranruye) - 🆕 增加总结行。[#1218](https://github.com/ant-design-blazor/ant-design-blazor/pull/1218) [@ElderJames](https://github.com/ElderJames) @@ -40,8 +107,9 @@ timeline: true - 🆕 增加 `GetQueryModel` 方法。[#1202](https://github.com/ant-design-blazor/ant-design-blazor/pull/1202) [@ElderJames](https://github.com/ElderJames) - Date Picker + - 🐞 修复在输入后触发 OnChange 事件[#1347](https://github.com/ant-design-blazor/ant-design-blazor/pull/1347) [@anddrzejb](https://github.com/anddrzejb) - - 🐞 修复resize事件处理方法[#1322](https://github.com/ant-design-blazor/ant-design-blazor/pull/1322) [@anddrzejb](https://github.com/anddrzejb) + - 🐞 修复 resize 事件处理方法[#1322](https://github.com/ant-design-blazor/ant-design-blazor/pull/1322) [@anddrzejb](https://github.com/anddrzejb) - 🆕 Space 增加 Wrap、Split 以及 Size 支持数组。[#1314](https://github.com/ant-design-blazor/ant-design-blazor/pull/1314) [@ElderJames](https://github.com/ElderJames) - 🆕 Alert 增加 Message 模板,增加轮播公告示例[#1250](https://github.com/ant-design-blazor/ant-design-blazor/pull/1250) [@MutatePat](https://github.com/MutatePat) @@ -63,15 +131,16 @@ timeline: true `2021-04-08` - Table - - 🐞 修复设置ScrollX时表格不重新渲染的问题。[#1311](https://github.com/ant-design-blazor/ant-design-blazor/pull/1311) [@Zonciu](https://github.com/Zonciu) - - 🐞 修改修改DataSource会抛出异常的问题。[5b0dbfb](https://github.com/ant-design-blazor/ant-design-blazor/commit/5b0dbfb) [@Andrzej Bakun](https://github.com/Andrzej Bakun) - - 🐞 修复DataIndex列过滤器无效的问题, 修复DataIndex列不刷新的问题。[#1295](https://github.com/ant-design-blazor/ant-design-blazor/pull/1295) [@Zonciu](https://github.com/Zonciu) + + - 🐞 修复设置 ScrollX 时表格不重新渲染的问题。[#1311](https://github.com/ant-design-blazor/ant-design-blazor/pull/1311) [@Zonciu](https://github.com/Zonciu) + - 🐞 修改修改 DataSource 会抛出异常的问题。[5b0dbfb](https://github.com/ant-design-blazor/ant-design-blazor/commit/5b0dbfb) [@Andrzej Bakun](https://github.com/Andrzej Bakun) + - 🐞 修复 DataIndex 列过滤器无效的问题, 修复 DataIndex 列不刷新的问题。[#1295](https://github.com/ant-design-blazor/ant-design-blazor/pull/1295) [@Zonciu](https://github.com/Zonciu) - 🐞 ExpandIconColumnIndex 指定到 ActionColumn 时无效的问题。[#1285](https://github.com/ant-design-blazor/ant-design-blazor/pull/1285) [@Magehernan](https://github.com/Magehernan) - 🐞 优化性能并修复 DataSource 更新问题 [#1304](https://github.com/ant-design-blazor/ant-design-blazor/pull/1304) [@anddrzejb](https://github.com/anddrzejb) - Select - 🐞 修复多选时点击关闭选项时,会触发下拉菜单的问题。[#1308](https://github.com/ant-design-blazor/ant-design-blazor/pull/1308) [@anddrzejb](https://github.com/anddrzejb) - - 🐞 修复 Tag模式的 Loading 图标问题。[12ca2f7](https://github.com/ant-design-blazor/ant-design-blazor/commit/12ca2f7) [@Andrzej Bakun](https://github.com/Andrzej Bakun) + - 🐞 修复 Tag 模式的 Loading 图标问题。[12ca2f7](https://github.com/ant-design-blazor/ant-design-blazor/commit/12ca2f7) [@Andrzej Bakun](https://github.com/Andrzej Bakun) - 💄 修复 flex 和 wrap 的样式。[#1296](https://github.com/ant-design-blazor/ant-design-blazor/pull/1296) [@ElderJames](https://github.com/ElderJames) - 🐞 使默认值为空字符串。[6944c13](https://github.com/ant-design-blazor/ant-design-blazor/commit/6944c13) [@Andrzej Bakun](https://github.com/Andrzej Bakun) - 🐞 修复文件列表。[53c1285](https://github.com/ant-design-blazor/ant-design-blazor/commit/53c1285) [@Andrzej Bakun](https://github.com/Andrzej Bakun) diff --git a/components/affix/Affix.razor b/components/affix/Affix.razor index c56ee5860c..8a95d07d61 100644 --- a/components/affix/Affix.razor +++ b/components/affix/Affix.razor @@ -4,8 +4,7 @@
@if (_affixed) { - + }
@ChildContent diff --git a/components/affix/Affix.razor.cs b/components/affix/Affix.razor.cs index 104e3f60fd..9cad946f37 100644 --- a/components/affix/Affix.razor.cs +++ b/components/affix/Affix.razor.cs @@ -23,7 +23,7 @@ private bool Affixed if (_affixed != value) { _affixed = value; - StateHasChanged(); + if (OnChange.HasDelegate) { OnChange.InvokeAsync(_affixed); @@ -45,13 +45,13 @@ private bool Affixed /// Offset from the bottom of the viewport (in pixels) /// [Parameter] - public uint? OffsetBottom { get; set; } + public int OffsetBottom { get; set; } /// /// Offset from the top of the viewport (in pixels) /// [Parameter] - public uint? OffsetTop { get; set; } = 0; + public int OffsetTop { get; set; } [Parameter] public string TargetSelector { get; set; } @@ -68,7 +68,8 @@ protected override void OnInitialized() { base.OnInitialized(); - SetClasses(); + ClassMapper + .If(PrefixCls, () => _affixed); } public async override Task SetParametersAsync(ParameterView parameters) @@ -80,14 +81,20 @@ protected async override Task OnFirstAfterRenderAsync() { await base.OnFirstAfterRenderAsync(); + if (ChildContent == null) + { + return; + } + var domRect = await JsInvokeAsync(JSInteropConstants.GetBoundingClientRect, _childRef); - _hiddenStyle = $"width: {domRect.width}px; height: {domRect.height}px;"; + _hiddenStyle = $"width: {domRect.Width}px; height: {domRect.Height}px;"; - DomEventService.AddEventListener(RootScollSelector, "scroll", OnWindowScroll, false); - DomEventService.AddEventListener(RootScollSelector, "resize", OnWindowResize, false); await RenderAffixAsync(); if (!_rootListened && string.IsNullOrEmpty(TargetSelector)) { + DomEventService.AddEventListener(RootScollSelector, "scroll", OnWindowScroll, false); + DomEventService.AddEventListener(RootScollSelector, "resize", OnWindowResize, false); + _rootListened = true; } else if (!string.IsNullOrEmpty(TargetSelector)) @@ -98,46 +105,17 @@ protected async override Task OnFirstAfterRenderAsync() } } - private async void OnWindowScroll(JsonElement obj) - { - await RenderAffixAsync(true); - } + private async void OnWindowScroll(JsonElement obj) => await RenderAffixAsync(); - private async void OnWindowResize(JsonElement obj) - { - await RenderAffixAsync(true); - } + private async void OnWindowResize(JsonElement obj) => await RenderAffixAsync(); - private async void OnTargetScroll(JsonElement obj) - { - await RenderAffixAsync(); - } + private async void OnTargetScroll(JsonElement obj) => await RenderAffixAsync(); - private async void OnTargetResize(JsonElement obj) - { - await RenderAffixAsync(); - } + private async void OnTargetResize(JsonElement obj) => await RenderAffixAsync(); - private void SetClasses() + private async Task RenderAffixAsync() { - ClassMapper.Clear() - .If(PrefixCls, () => _affixed); - } - - private async Task RenderAffixAsync(bool windowscrolled = false) - { - if (windowscrolled && !string.IsNullOrEmpty(TargetSelector)) - { - if (!Affixed) - { - return; - } - _affixStyle = string.Empty; - Affixed = false; - StateHasChanged(); - return; - } - + var originalAffixStyle = _affixStyle; DomRect childRect = null; DomRect domRect = null; Window window = null; @@ -163,30 +141,31 @@ async Task GetChildReact() return; } - _hiddenStyle = $"width: {childRect.width}px; height: {childRect.height}px;"; + _hiddenStyle = $"width: {childRect.Width}px; height: {childRect.Height}px;"; DomRect containerRect; if (string.IsNullOrEmpty(TargetSelector)) { containerRect = new DomRect() { - top = 0, - bottom = window.innerHeight, - height = window.innerHeight, + Top = 0, + Bottom = window.innerHeight, + Height = window.innerHeight, }; } else { containerRect = await JsInvokeAsync(JSInteropConstants.GetBoundingClientRect, TargetSelector); } - // become affixed - if (OffsetBottom.HasValue) + + var topDist = containerRect.Top + OffsetTop; + var bottomDist = containerRect.Bottom - OffsetBottom; + + if (OffsetBottom > 0) // only affix bottom { - // domRect.bottom / domRect.top have the identical value here. - var bottom = containerRect.bottom - OffsetBottom; - if (domRect.bottom > bottom) + if (domRect.Bottom > bottomDist) { - _affixStyle = _hiddenStyle + $"bottom: { window.innerHeight - bottom}px; position: fixed;"; + _affixStyle = _hiddenStyle + $"bottom: { window.innerHeight - bottomDist}px; position: fixed;"; Affixed = true; } else @@ -195,29 +174,37 @@ async Task GetChildReact() Affixed = false; } } - else if (OffsetTop.HasValue) + else if (domRect.Top < topDist) { - var top = containerRect.top + OffsetTop; - if (domRect.top < top && top > 0) - { - _affixStyle = _hiddenStyle + $"top: {top}px; position: fixed;"; - Affixed = true; - } - else - { - _affixStyle = string.Empty; - Affixed = false; - } + _affixStyle = _hiddenStyle + $"top: {topDist}px; position: fixed;"; + Affixed = true; + } + else + { + _affixStyle = string.Empty; + Affixed = false; } - StateHasChanged(); + if (originalAffixStyle != _affixStyle) + { + StateHasChanged(); + } } protected override void Dispose(bool disposing) { base.Dispose(disposing); - DomEventService.RemoveEventListerner(RootScollSelector, "scroll", OnWindowScroll); - DomEventService.RemoveEventListerner(RootScollSelector, "resize", OnWindowResize); + + if (string.IsNullOrEmpty(TargetSelector)) + { + DomEventService.RemoveEventListerner(RootScollSelector, "scroll", OnWindowScroll); + DomEventService.RemoveEventListerner(RootScollSelector, "resize", OnWindowResize); + } + else + { + DomEventService.RemoveEventListerner(TargetSelector, "scroll", OnWindowScroll); + DomEventService.RemoveEventListerner(TargetSelector, "resize", OnWindowResize); + } } } } diff --git a/components/alert/Alert.razor.cs b/components/alert/Alert.razor.cs index cb1d628ece..62beee5230 100644 --- a/components/alert/Alert.razor.cs +++ b/components/alert/Alert.razor.cs @@ -148,8 +148,8 @@ protected override async Task OnAfterRenderAsync(bool firstRender) if (firstRender) { - Element element = await JsInvokeAsync(JSInteropConstants.GetDomInfo, Ref); - _height = element.clientHeight; + HtmlElement element = await JsInvokeAsync(JSInteropConstants.GetDomInfo, Ref); + _height = element.ClientHeight; } } diff --git a/components/anchor/Anchor.razor.cs b/components/anchor/Anchor.razor.cs index 7d485b58e7..001abe48c1 100644 --- a/components/anchor/Anchor.razor.cs +++ b/components/anchor/Anchor.razor.cs @@ -158,7 +158,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) _activatedByClick = false; await ActivateAsync(link, true); // the offset does not matter, since the dictionary's value will not change any more in case user set up GetCurrentAnchor - _linkTops[link.Href] = hrefDom.top; + _linkTops[link.Href] = hrefDom.Top; StateHasChanged(); } } @@ -223,7 +223,7 @@ private async void OnScroll(JsonElement obj) DomRect hrefDom = await link.GetHrefDom(); if (hrefDom != null) { - _linkTops[link.Href] = hrefDom.top + offset; + _linkTops[link.Href] = hrefDom.Top + offset; } } catch (Exception ex) @@ -242,7 +242,7 @@ private async void OnScroll(JsonElement obj) if (Affix && _activeLink != null) { _ballClass = "ant-anchor-ink-ball visible"; - decimal top = (_activeLink.LinkDom.top - _selfDom.top) + _activeLink.LinkDom.height / 2 - 2; + decimal top = (_activeLink.LinkDom.Top - _selfDom.Top) + _activeLink.LinkDom.Height / 2 - 2; _ballStyle = $"top: {top}px;"; } else diff --git a/components/auto-complete/AutoComplete.razor.cs b/components/auto-complete/AutoComplete.razor.cs index cf2519c5f1..eacb09e3d6 100644 --- a/components/auto-complete/AutoComplete.razor.cs +++ b/components/auto-complete/AutoComplete.razor.cs @@ -23,6 +23,7 @@ public partial class AutoComplete : AntInputComponentBase, IAut [Parameter] public bool DefaultActiveFirstOption { get; set; } = true; + [Parameter] public bool Backfill { get; set; } = false; @@ -40,6 +41,7 @@ public partial class AutoComplete : AntInputComponentBase, IAut /// 列表绑定数据源集合 /// private IEnumerable _options; + [Parameter] public IEnumerable Options { @@ -72,6 +74,7 @@ public IEnumerable> OptionDataItems [Parameter] public EventCallback OnSelectionChange { get; set; } + [Parameter] public EventCallback OnActiveChange { get; set; } @@ -138,6 +141,7 @@ public IEnumerable> OptionDataItems private OverlayTrigger _overlayTrigger; public object SelectedValue { get; set; } + /// /// 选择的项 /// @@ -149,7 +153,6 @@ public IEnumerable> OptionDataItems /// public object ActiveValue { get; set; } - [Parameter] public bool ShowPanel { get; set; } = false; @@ -163,6 +166,7 @@ public void SetInputComponent(IAutoCompleteInput input) } #region 子控件触发事件 + public async Task InputFocus(FocusEventArgs e) { if (!_isOptionsZero) @@ -208,7 +212,7 @@ public async Task InputKeyDown(KeyboardEventArgs args) } } - #endregion + #endregion 子控件触发事件 protected override void OnParametersSet() { @@ -222,8 +226,6 @@ protected override async Task OnFirstAfterRenderAsync() await base.OnFirstAfterRenderAsync(); } - - public void AddOption(AutoCompleteOption option) { AutoCompleteOptions.Add(option); @@ -371,7 +373,7 @@ public async Task SetSelectedItem(AutoCompleteOption item) this.ClosePanel(); } - bool _parPanelVisible = false; + private bool _parPanelVisible = false; private async void OnOverlayTriggerVisibleChange(bool visible) { @@ -388,6 +390,7 @@ private async void OnOverlayTriggerVisibleChange(bool visible) } private string _minWidth = ""; + private async Task SetOverlayWidth() { string newWidth; @@ -398,7 +401,7 @@ private async Task SetOverlayWidth() } else { - Element element = await JsInvokeAsync(JSInteropConstants.GetDomInfo, _overlayTrigger.RefBack.Current); ; + HtmlElement element = await JsInvokeAsync(JSInteropConstants.GetDomInfo, _overlayTrigger.RefBack.Current); ; //Element element; //if (_divRef.Id != null) //{ @@ -408,7 +411,7 @@ private async Task SetOverlayWidth() //{ // element = await JsInvokeAsync(JSInteropConstants.GetDomInfo, _overlayTrigger.RefBack.Current); //} - newWidth = $"min-width:{element.clientWidth}px"; + newWidth = $"min-width:{element.ClientWidth}px"; } if (newWidth != _minWidth) _minWidth = newWidth; } @@ -416,7 +419,9 @@ private async Task SetOverlayWidth() public class AutoCompleteDataItem { - public AutoCompleteDataItem() { } + public AutoCompleteDataItem() + { + } public AutoCompleteDataItem(TOption value, string label) { @@ -430,4 +435,3 @@ public AutoCompleteDataItem(TOption value, string label) public bool IsDisabled { get; set; } } } - diff --git a/components/avatar/Avatar.razor.cs b/components/avatar/Avatar.razor.cs index 4c8abc603c..0d4f0e0031 100644 --- a/components/avatar/Avatar.razor.cs +++ b/components/avatar/Avatar.razor.cs @@ -161,8 +161,8 @@ private async Task CalcStringSize() return; } - var childrenWidth = (await JsInvokeAsync(JSInteropConstants.GetDomInfo, TextEl))?.offsetWidth ?? 0; - var avatarWidth = (await JsInvokeAsync(JSInteropConstants.GetBoundingClientRect, Ref))?.width ?? 0; + var childrenWidth = (await JsInvokeAsync(JSInteropConstants.GetDomInfo, TextEl))?.OffsetWidth ?? 0; + var avatarWidth = (await JsInvokeAsync(JSInteropConstants.GetBoundingClientRect, Ref))?.Width ?? 0; var scale = childrenWidth != 0 && avatarWidth - 8 < childrenWidth ? (avatarWidth - 8) / childrenWidth : 1; _textStyles = $"transform: scale({new CssSizeLength(scale, true)}) translateX(-50%);"; if (decimal.TryParse(Size, out var pxSize)) diff --git a/components/carousel/Carousel.razor.cs b/components/carousel/Carousel.razor.cs index 4e511f725d..ceb02d3099 100644 --- a/components/carousel/Carousel.razor.cs +++ b/components/carousel/Carousel.razor.cs @@ -137,13 +137,13 @@ protected async override Task OnAfterRenderAsync(bool firstRender) private async void Resize(JsonElement e = default) { DomRect listRect = await JsInvokeAsync(JSInteropConstants.GetBoundingClientRect, Ref); - if ((SlickWidth != (int)listRect.width && IsHorizontal) - || (SlickHeight != (int)listRect.height && !IsHorizontal) + if ((SlickWidth != (int)listRect.Width && IsHorizontal) + || (SlickHeight != (int)listRect.Height && !IsHorizontal) || IsHorizontal && !string.IsNullOrEmpty(SlickListStyle) || !IsHorizontal && string.IsNullOrEmpty(SlickListStyle)) { - SlickWidth = (int)listRect.width; - SlickHeight = (int)listRect.height; + SlickWidth = (int)listRect.Width; + SlickHeight = (int)listRect.Height; StateHasChanged(); } } diff --git a/components/cascader/Cascader.razor b/components/cascader/Cascader.razor index 6247948d11..2c40bdfa03 100644 --- a/components/cascader/Cascader.razor +++ b/components/cascader/Cascader.razor @@ -3,73 +3,116 @@ @inherits AntInputComponentBase - - - - - - @if (string.IsNullOrWhiteSpace(Value) || !ShowClearIcon) + + + + @_displayText + + @if (!_showClearIcon) + { + + } + else + { + + } + + + +
+
+ @if (!ShowSearch || string.IsNullOrWhiteSpace(_searchValue)) { - - } - else - { - - } - - - -
-
    - @foreach (CascaderNode nd in _nodelist) - { - bool isActive = _renderNodes.Where(n => n == nd).Any(); - string activeClass = isActive ? "ant-cascader-menu-item-active" : string.Empty; - - - } + @menuList((_nodelist, this))
@foreach (CascaderNode node in _renderNodes) { if (node.HasChildren) {
    - @foreach (CascaderNode m in node.Children) - { - bool isActive = _renderNodes.Where(n => n == m).Any(); - string activeClass = isActive ? "ant-cascader-menu-item-active" : string.Empty; - - - } + @menuList((node.Children, this))
} } -
+ } + else + { +
    + @searchList(this) +
+ } +
+
+ + + + +@code{ + RenderFragment<(IEnumerable nodes, Cascader cascader)> menuList = context =>@; + + RenderFragment searchList = cascader =>@; +} \ No newline at end of file diff --git a/components/cascader/Cascader.razor.cs b/components/cascader/Cascader.razor.cs index a219146770..904d98a89b 100644 --- a/components/cascader/Cascader.razor.cs +++ b/components/cascader/Cascader.razor.cs @@ -2,64 +2,41 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Components; using System.Linq; -using System.Collections; using System.Threading.Tasks; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.JSInterop; +using AntDesign.JsInterop; namespace AntDesign { public partial class Cascader : AntInputComponentBase { - [Parameter] public bool Readonly { get; set; } = true; - - /// - /// 是否支持清除 - /// [Parameter] public bool AllowClear { get; set; } = true; - /// - /// 是否显示关闭图标 - /// - private bool ShowClearIcon { get; set; } - - /// - /// 当此项为 true 时,点选每级菜单选项值都会发生变化 - /// [Parameter] public bool ChangeOnSelect { get; set; } - /// - /// 默认的选中项 - /// [Parameter] public string DefaultValue { get; set; } - /// - /// 次级菜单的展开方式,可选 'click' 和 'hover' - /// [Parameter] public string ExpandTrigger { get; set; } - /// - /// 当下拉列表为空时显示的内容 - /// - [Parameter] public string NotFoundContent { get; set; } = "Not Found"; + [Parameter] public string NotFoundContent { get; set; } = LocaleProvider.CurrentLocale.Empty.Description; - /// - /// 输入框占位文本 - /// - [Parameter] public string PlaceHolder { get; set; } = "请选择"; + [Parameter] public string Placeholder { get => _placeHolder; set => _placeHolder = value; } [Parameter] public string PopupContainerSelector { get; set; } = "body"; - /// - /// 在选择框中显示搜索框 - /// [Parameter] public bool ShowSearch { get; set; } /// - /// 选择完成后的回调(参数为选中的节点集合及选中值) + /// Please use SelectedNodesChanged instead. /// + [Obsolete("Instead use SelectedNodesChanged.")] [Parameter] public Action, string, string> OnChange { get; set; } + [Parameter] public EventCallback SelectedNodesChanged { get; set; } + [Parameter] - public IReadOnlyCollection Options + public IEnumerable Options { get { @@ -69,7 +46,7 @@ public IReadOnlyCollection Options } set { - if (value == null || value.Count == 0) + if (value?.Any() != true) { _nodelist = null; return; @@ -83,42 +60,30 @@ public IReadOnlyCollection Options } private List _nodelist; - - /// - /// 选中节点集合(click) - /// - internal List _selectedNodes = new List(); - - /// - /// 选中节点集合(hover) - /// - internal List _hoverSelectedNodes = new List(); - - /// - /// 用于渲染下拉节点集合(一级节点除外) - /// - internal List _renderNodes = new List(); + private List _selectedNodes = new List(); + private List _hoverSelectedNodes = new List(); + private List _renderNodes = new List(); + private List _searchList = new List(); + private IEnumerable _matchList; private ClassMapper _menuClassMapper = new ClassMapper(); private ClassMapper _inputClassMapper = new ClassMapper(); - /// - /// 浮层 展开/折叠状态 - /// - private bool ToggleState { get; set; } - - /// - /// 鼠标是否处于 浮层 之上 - /// - private bool IsOnCascader { get; set; } + private EventCallbackFactory _callbackFactory = new EventCallbackFactory(); - /// - /// 选择节点类型 - /// Click: 点击选中节点, Hover: 鼠标移入选中节点 - /// - private SelectedTypeEnum SelectedType { get; set; } + private bool _dropdownOpened; + private bool _isOnCascader; + private SelectedTypeEnum _selectedType; + private bool _showClearIcon; private string _displayText; + private bool _initialized; + private string _searchValue; + private ElementReference _inputRef; + private string _placeHolder = LocaleProvider.CurrentLocale.Global.Placeholder; + + private bool _focused; + private string _menuStyle; private static Dictionary _sizeMap = new Dictionary() { @@ -129,47 +94,45 @@ public IReadOnlyCollection Options protected override void OnInitialized() { base.OnInitialized(); + string prefixCls = "ant-cascader"; ClassMapper - .Add("ant-cascader-picker") - .GetIf(() => $"ant-cascader-picker-{Size}", () => _sizeMap.ContainsKey(Size)) - .If("ant-cascader-picker-rtl", () => RTL); + .Add($"{prefixCls}-picker") + .GetIf(() => $"{prefixCls}-picker-{Size}", () => _sizeMap.ContainsKey(Size)) + .If($"{prefixCls}-picker-show-search", () => ShowSearch) + .If($"{prefixCls}-picker-with-value", () => !string.IsNullOrEmpty(_searchValue)) + .If($"{prefixCls}-picker-rtl", () => RTL); _inputClassMapper .Add("ant-input") - .Add("ant-cascader-input") - .GetIf(() => $"ant-cascader-input-{_sizeMap[Size]}", () => _sizeMap.ContainsKey(Size)) - .If("ant-cascader-input-rtl", () => RTL); + .GetIf(() => $"ant-input-{_sizeMap[Size]}", () => _sizeMap.ContainsKey(Size)) + .Add($"{prefixCls}-input") + .If($"{prefixCls}-input-rtl", () => RTL); _menuClassMapper - .Add("ant-cascader-menu") - .If($"ant-cascader-menu-rtl", () => RTL); - } - - protected override void OnParametersSet() - { - base.OnParametersSet(); + .Add($"{prefixCls}-menu") + .If($"{prefixCls}-menu-rtl", () => RTL); - ProcessParentAndDefault(); + SetDefaultValue(Value ?? DefaultValue); } protected override void OnValueChange(string value) { base.OnValueChange(value); - RefreshNodeValue(value); } - #region event - /// /// 输入框单击(显示/隐藏浮层) /// private void InputOnToggle() { - SelectedType = SelectedTypeEnum.Click; + _selectedType = SelectedTypeEnum.Click; _hoverSelectedNodes.Clear(); - ToggleState = !ToggleState; + if (!_dropdownOpened) + { + _dropdownOpened = true; + } } /// @@ -177,9 +140,9 @@ private void InputOnToggle() /// private void CascaderOnBlur() { - if (!IsOnCascader) + if (!_isOnCascader) { - ToggleState = false; + _dropdownOpened = false; _renderNodes = _selectedNodes; } } @@ -191,7 +154,7 @@ private void InputOnMouseOver() { if (!AllowClear) return; - ShowClearIcon = true; + _showClearIcon = !string.IsNullOrWhiteSpace(Value) || !string.IsNullOrEmpty(_searchValue); } /// @@ -201,7 +164,7 @@ private void InputOnMouseOut() { if (!AllowClear) return; - ShowClearIcon = false; + _showClearIcon = false; } /// @@ -212,7 +175,8 @@ private void ClearSelected() _selectedNodes.Clear(); _hoverSelectedNodes.Clear(); _displayText = string.Empty; - CurrentValueAsString = string.Empty; + SetValue(string.Empty); + _dropdownOpened = false; } /// @@ -222,7 +186,7 @@ private void NodesOnMouseOver() { if (!AllowClear) return; - IsOnCascader = true; + _isOnCascader = true; } /// @@ -232,7 +196,7 @@ private void NodesOnMouseOut() { if (!AllowClear) return; - IsOnCascader = false; + _isOnCascader = false; } /// @@ -242,7 +206,7 @@ private void NodesOnMouseOut() private void NodeOnClick(CascaderNode node) { if (node.Disabled) return; - + _searchValue = string.Empty; SetSelectedNode(node, SelectedTypeEnum.Click); } @@ -260,18 +224,39 @@ private void NodeOnMouseOver(CascaderNode node) SetSelectedNode(node, SelectedTypeEnum.Hover); } - #endregion event + private void OnSearchInput(ChangeEventArgs e) + { + _searchValue = e.Value?.ToString(); + } + + private async Task OnSearchKeyUp(KeyboardEventArgs e) + { + if (string.IsNullOrEmpty(_searchValue)) + { + _showClearIcon = false; + return; + } + + var inputElemnet = await Js.InvokeAsync(JSInteropConstants.GetDomInfo, _inputRef); + _menuStyle = $"width:{inputElemnet.ClientWidth}px;"; + _matchList = _searchList.Where(x => x.Label.Contains(_searchValue, StringComparison.OrdinalIgnoreCase)); + _showClearIcon = true; + if (!_matchList.Any()) + { + _menuStyle += "height:auto;"; + } + } /// - /// 选中节点 + /// Selected nodes /// /// /// - internal void SetSelectedNode(CascaderNode cascaderNode, SelectedTypeEnum selectedType) + private void SetSelectedNode(CascaderNode cascaderNode, SelectedTypeEnum selectedType) { if (cascaderNode == null) return; - SelectedType = selectedType; + _selectedType = selectedType; if (selectedType == SelectedTypeEnum.Click) { _selectedNodes.Clear(); @@ -279,7 +264,9 @@ internal void SetSelectedNode(CascaderNode cascaderNode, SelectedTypeEnum select _renderNodes = _selectedNodes; if (ChangeOnSelect || !cascaderNode.HasChildren) + { SetValue(cascaderNode.Value); + } } else { @@ -291,13 +278,13 @@ internal void SetSelectedNode(CascaderNode cascaderNode, SelectedTypeEnum select if (!cascaderNode.HasChildren) { - ToggleState = false; - IsOnCascader = false; + _dropdownOpened = false; + _isOnCascader = false; } } /// - /// 设置选中所有父节点 + /// Set all parent nodes to be selected /// /// /// @@ -310,7 +297,7 @@ private void SetSelectedNodeWithParent(CascaderNode node, ref List } /// - /// Options 更新后处理父节点和默认值 + /// handles parent nodes and defaults after Options updating /// private void ProcessParentAndDefault() { @@ -319,12 +306,12 @@ private void ProcessParentAndDefault() } /// - /// 初始化节点属性(Level, ParentNode) + /// Initialize nodes (Level, ParentNode) /// /// /// /// - private void InitCascaderNodeState(List list, CascaderNode parentNode, int level) + private void InitCascaderNodeState(List list, CascaderNode parentNode, int level, bool recursive = false) { if (list == null) return; @@ -334,84 +321,100 @@ private void InitCascaderNodeState(List list, CascaderNode parentN node.ParentNode = parentNode; if (node.HasChildren) - InitCascaderNodeState(node.Children.ToList(), node, level + 1); + { + InitCascaderNodeState(node.Children.ToList(), node, level + 1, true); + } + else + { + _searchList.Add(new CascaderNode + { + Label = node.Label, + ParentNode = node.ParentNode, + Value = node.Value, + Disabled = node.Disabled, + Level = node.Level + }); + } + } + + if (!recursive) + { + _searchList.ForEach(node => + { + var pathList = new List(); + SetSelectedNodeWithParent(node, ref pathList); + pathList.Reverse(); + node.Label = string.Join(" / ", pathList.Select(x => x.Label)); + }); } } /// - /// 刷新选中的内容 + /// Refresh the selected value /// /// private void RefreshNodeValue(string value) { _selectedNodes.Clear(); - var node = GetNodeByValue(_nodelist, value); SetSelectedNodeWithParent(node, ref _selectedNodes); _renderNodes = _selectedNodes; - - RefreshDisplayValue(); - - OnChange?.Invoke(_selectedNodes, value, _displayText); } /// - /// 设置默认选中 + /// Set the default value /// /// private void SetDefaultValue(string defaultValue) { - if (string.IsNullOrWhiteSpace(defaultValue)) - return; + if (!string.IsNullOrWhiteSpace(defaultValue)) + { + RefreshNodeValue(defaultValue); + SetValue(defaultValue); + } - _selectedNodes.Clear(); - var node = GetNodeByValue(_nodelist, defaultValue); - SetSelectedNodeWithParent(node, ref _selectedNodes); - _renderNodes = _selectedNodes; - SetValue(node?.Value); + _initialized = true; } /// - /// 设置输入框选中值 + /// Set the binding value /// /// private void SetValue(string value) { - RefreshDisplayValue(); + RefreshDisplayText(); if (Value != value) { CurrentValueAsString = value; + + if (_initialized && SelectedNodesChanged.HasDelegate) + { + SelectedNodesChanged.InvokeAsync(_selectedNodes.ToArray()); + } + + OnChange?.Invoke(_selectedNodes, value, _displayText); } } - private void RefreshDisplayValue() + /// + /// rebuild the display text + /// + private void RefreshDisplayText() { _selectedNodes.Sort((x, y) => x.Level.CompareTo(y.Level)); //Level 升序排序 - _displayText = string.Empty; - int count = 0; - foreach (var node in _selectedNodes) - { - if (node == null) continue; - - if (count < _selectedNodes.Count - 1) - _displayText += node.Label + " / "; - else - _displayText += node.Label; - count++; - } + _displayText = string.Join(" / ", _selectedNodes.Where(x => x != null).Select(x => x.Label)); } /// - /// 根据指定值获取节点 + /// Get the node based on the specified value /// /// /// /// - private CascaderNode GetNodeByValue(List list, string value) + private CascaderNode GetNodeByValue(IEnumerable list, string value) { if (list == null) return null; - CascaderNode result = null; foreach (var node in list) { @@ -420,12 +423,14 @@ private CascaderNode GetNodeByValue(List list, string value) if (node.HasChildren) { - var nd = GetNodeByValue(node.Children.ToList(), value); + var nd = GetNodeByValue(node.Children, value); if (nd != null) - result = nd; + { + return nd; + } } } - return result; + return null; } } } diff --git a/components/cascader/CascaderNode.cs b/components/cascader/CascaderNode.cs index 1566bb60b5..685b8c707d 100644 --- a/components/cascader/CascaderNode.cs +++ b/components/cascader/CascaderNode.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; namespace AntDesign { @@ -14,9 +15,9 @@ public class CascaderNode internal CascaderNode ParentNode { get; set; } - internal bool HasChildren { get { return Children?.Count > 0; } } + internal bool HasChildren { get { return Children?.Any() == true; } } - public IReadOnlyCollection Children { get; set; } + public IEnumerable Children { get; set; } } internal enum SelectedTypeEnum diff --git a/components/checkbox/Checkbox.razor b/components/checkbox/Checkbox.razor index fce5028493..349f39c7c9 100644 --- a/components/checkbox/Checkbox.razor +++ b/components/checkbox/Checkbox.razor @@ -1,13 +1,13 @@ @namespace AntDesign -@inherits AntInputComponentBase +@inherits AntInputBoolComponentBase -