Skip to content

Commit 565e669

Browse files
authored
fix(Table): IsDisabled parameter not work in Toolbar on gear mode (#4362)
* fix: 更新单元测试 * refactor: 代码重构 * Revert "fix: 更新单元测试" This reverts commit 9d74006. * fix: 更新 gear 按钮内禁用功能
1 parent 4a8f80a commit 565e669

File tree

3 files changed

+44
-28
lines changed

3 files changed

+44
-28
lines changed

src/BootstrapBlazor/Components/Table/Table.razor.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,14 @@
327327
.btn-gear .dropdown-menu .dropdown-item {
328328
padding: 6px 12px;
329329
display: table-cell;
330-
color: #504d4d;
330+
331+
&:not(.disabled) {
332+
color: #504d4d;
333+
}
334+
335+
&.disabled {
336+
pointer-events: auto;
337+
}
331338
}
332339

333340
.btn-gear .dropdown-menu .dropdown-item:not(:first-child) {

src/BootstrapBlazor/Components/Table/TableToolbar.razor

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
<div class="@ToolbarClassString">
1212
@foreach (var button in _buttons)
1313
{
14-
@if (button is TableToolbarButton<TItem> b && b.IsShow)
14+
@if (button is TableToolbarButton<TItem> { IsShow: true } b)
1515
{
1616
<Button AdditionalAttributes="b.AdditionalAttributes" Size="b.Size"
1717
Color="@b.Color" Icon="@b.Icon" Text="@b.Text" IsAsync="@b.IsAsync"
1818
OnClickWithoutRender="() => OnToolbarButtonClick(b)"
1919
TooltipText="@b.TooltipText" TooltipPlacement="@b.TooltipPlacement" TooltipTrigger="@b.TooltipTrigger"
2020
IsDisabled="GetDisabled(b)"></Button>
2121
}
22-
else if (button is TableToolbarPopConfirmButton<TItem> pb && pb.IsShow)
22+
else if (button is TableToolbarPopConfirmButton<TItem> { IsShow: true } pb)
2323
{
2424
<PopConfirmButton AdditionalAttributes="pb.AdditionalAttributes" CustomClass="@pb.CustomClass"
2525
Color="@pb.Color" Icon="@pb.Icon" Text="@pb.Text" Size="pb.Size" ShowShadow="@pb.ShowShadow"
@@ -31,7 +31,7 @@
3131
CloseButtonText="@pb.CloseButtonText" Content="@pb.Content">
3232
</PopConfirmButton>
3333
}
34-
else if (button is TableToolbarComponent<TItem> cb && cb.IsShow)
34+
else if (button is TableToolbarComponent<TItem> { IsShow: true } cb)
3535
{
3636
<CascadingValue Value="OnGetSelectedRows" IsFixed="true">
3737
@cb.ChildContent
@@ -48,31 +48,36 @@
4848
<div class="dropdown-menu">
4949
@foreach (var button in _buttons)
5050
{
51-
@if (button is TableToolbarButton<TItem> { IsShow: true } b)
51+
@switch (button)
5252
{
53-
<div class="dropdown-item" @onclick="e => OnToolbarButtonClick(b)">
54-
@if (string.IsNullOrEmpty(b.Icon))
55-
{
56-
<span>@b.Text</span>
57-
}
58-
else
59-
{
60-
<i class="@b.Icon"></i>
61-
}
62-
</div>
63-
}
64-
else if (button is TableToolbarPopConfirmButton<TItem> { IsShow: true } pb)
65-
{
66-
<div class="dropdown-item" @onclick="pb.OnConfirm">
67-
@if (string.IsNullOrEmpty(pb.Icon))
68-
{
69-
<span>@pb.Text</span>
70-
}
71-
else
72-
{
73-
<i class="@pb.Icon"></i>
74-
}
75-
</div>
53+
case TableToolbarButton<TItem> { IsShow: true } b:
54+
{
55+
<DynamicElement class="@GetItemClass(b)" TriggerClick="!GetDisabled(b)" OnClick="() => OnToolbarButtonClick(b)">
56+
@if (string.IsNullOrEmpty(b.Icon))
57+
{
58+
<span>@b.Text</span>
59+
}
60+
else
61+
{
62+
<i class="@b.Icon"></i>
63+
}
64+
</DynamicElement>
65+
break;
66+
}
67+
case TableToolbarPopConfirmButton<TItem> { IsShow: true } pb:
68+
{
69+
<DynamicElement class="@GetItemClass(pb)" TriggerClick="!GetDisabled(pb)" OnClick="pb.OnConfirm">
70+
@if (string.IsNullOrEmpty(pb.Icon))
71+
{
72+
<span>@pb.Text</span>
73+
}
74+
else
75+
{
76+
<i class="@pb.Icon"></i>
77+
}
78+
</DynamicElement>
79+
break;
80+
}
7681
}
7782
}
7883
</div>

src/BootstrapBlazor/Components/Table/TableToolbar.razor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public partial class TableToolbar<TItem> : ComponentBase
5050
.AddClass("d-none d-sm-inline-flex", IsAutoCollapsedToolbarButton)
5151
.Build();
5252

53+
private string? GetItemClass(ButtonBase button) => CssBuilder.Default("dropdown-item")
54+
.AddClass("disabled", GetDisabled(button))
55+
.Build();
56+
5357
private async Task OnToolbarButtonClick(TableToolbarButton<TItem> button)
5458
{
5559
_asyncButtonStateCache.TryGetValue(button, out var disabled);

0 commit comments

Comments
 (0)