Skip to content

Commit 6d997e9

Browse files
authored
[DataGrid] Do not use 'display: flex' on table header cells (#3760)
* When not using `HeaderCellAsButtonWithMenu`, don't use display:flex on the header cell. Instead add a specific div in rendering the header content * Tests: update verified files
1 parent 2174b8b commit 6d997e9

12 files changed

+140
-134
lines changed

examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5246,13 +5246,13 @@
52465246
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentInputFile.MaximumFileSize">
52475247
<summary>
52485248
Gets or sets the maximum size of a file to be uploaded (in bytes).
5249-
Default value is 10 MB.
5249+
Default value is 10 MiB.
52505250
</summary>
52515251
</member>
52525252
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentInputFile.BufferSize">
52535253
<summary>
52545254
Gets or sets the sze of buffer to read bytes from uploaded file (in bytes).
5255-
Default value is 10 KB.
5255+
Default value is 10 KiB.
52565256
</summary>
52575257
</member>
52585258
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentInputFile.Accept">

src/Core/Components/DataGrid/Columns/ColumnBase.razor

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{
1818
string? tooltip = Tooltip ? (HeaderTooltip ?? Title) : null;
1919

20-
<FluentKeyCode Only="new[] { KeyCode.Ctrl, KeyCode.Enter }" OnKeyDown="HandleKeyDown" class="keycapture" style="width: 100%;" StopPropagation="true" @oncontextmenu="@(() => Grid.RemoveSortByColumnAsync(this))">
20+
<FluentKeyCode Only="new[] { KeyCode.Ctrl, KeyCode.Enter }" OnKeyDown="HandleKeyDown" class="keycapture" style="width: 100%;" StopPropagation="true" @oncontextmenu="@(() => Grid.RemoveSortByColumnAsync(this))">
2121

2222
@if (AnyColumnActionEnabled)
2323
{
@@ -96,74 +96,76 @@
9696
{
9797
wdelta = "56px";
9898
}
99-
100-
@if (Align == Align.Start || Align == Align.Center)
101-
{
102-
@if (Grid.ResizeType is not null)
99+
<div style="display: flex;">
100+
@if (Align == Align.Start || Align == Align.Center)
103101
{
104-
@OptionsButton()
105-
}
106-
else
107-
{
108-
@if (ColumnOptions is not null)
102+
@if (Grid.ResizeType is not null)
109103
{
110-
@FilterButton()
104+
@OptionsButton()
105+
}
106+
else
107+
{
108+
@if (ColumnOptions is not null)
109+
{
110+
@FilterButton()
111+
}
111112
}
112113
}
113-
}
114114

115-
@if (Sortable.HasValue ? Sortable.Value : IsSortableByDefault())
116-
{
117-
<FluentKeyCode Only="new [] { KeyCode.Ctrl, KeyCode.Enter}" OnKeyDown="HandleKeyDown" class="keycapture" style="width: 100%;" StopPropagation="true" @oncontextmenu="@(() => Grid.RemoveSortByColumnAsync(this))">
118-
<FluentButton Appearance="Appearance.Stealth" Class="col-sort-button" Style="@($"width: calc(100% - {wdelta});")" @onclick="@(() => Grid.SortByColumnAsync(this))" aria-label="@tooltip" title="@tooltip">
115+
@if (Sortable.HasValue ? Sortable.Value : IsSortableByDefault())
116+
{
117+
<FluentKeyCode Only="new[] { KeyCode.Ctrl, KeyCode.Enter }" OnKeyDown="HandleKeyDown" class="keycapture" style="width: 100%;" StopPropagation="true" @oncontextmenu="@(() => Grid.RemoveSortByColumnAsync(this))">
118+
<FluentButton Appearance="Appearance.Stealth" Class="col-sort-button" Style="@($"width: calc(100% - {wdelta});")" @onclick="@(() => Grid.SortByColumnAsync(this))" aria-label="@tooltip" title="@tooltip">
119119
<div class="col-title-text" title="@tooltip">@Title</div>
120120

121-
@if (Grid.SortByAscending.HasValue && IsActiveSortColumn)
122-
{
123-
if (Grid.SortByAscending == true)
121+
@if (Grid.SortByAscending.HasValue && IsActiveSortColumn)
124122
{
125-
<FluentIcon Value="@(new CoreIcons.Regular.Size20.ArrowSortUp())" Slot="end" Style="opacity: 0.5;" />
123+
if (Grid.SortByAscending == true)
124+
{
125+
<FluentIcon Value="@(new CoreIcons.Regular.Size20.ArrowSortUp())" Slot="end" Style="opacity: 0.5;" />
126+
}
127+
else
128+
{
129+
<FluentIcon Value="@(new CoreIcons.Regular.Size20.ArrowSortDown())" Slot="end" Style="opacity: 0.5;" />
130+
}
126131
}
127-
else
132+
@if (ColumnOptions is not null && Filtered.GetValueOrDefault() && Grid.ResizeType is not null)
128133
{
129-
<FluentIcon Value="@(new CoreIcons.Regular.Size20.ArrowSortDown())" Slot="end" Style="opacity: 0.5;" />
134+
<FluentIcon Value="@(new CoreIcons.Regular.Size20.Filter())" Slot="end" Style="opacity: 0.5;" />
130135
}
131-
}
132-
@if (ColumnOptions is not null && Filtered.GetValueOrDefault() && Grid.ResizeType is not null)
133-
{
134-
<FluentIcon Value="@(new CoreIcons.Regular.Size20.Filter())" Slot="end" Style="opacity: 0.5;" />
135-
}
136136
</FluentButton>
137-
</FluentKeyCode>
138-
}
139-
else
140-
{
141-
<div class="col-title" style="@($"width: calc(100% - {wdelta});")">
142-
<div class="col-title-text" title="@tooltip" >@Title
143-
@if (ColumnOptions is not null && Filtered.GetValueOrDefault() && Grid.ResizeType.HasValue )
144-
{
145-
<span style="padding: 0 5px;">
146-
<FluentIcon Value="@(new CoreIcons.Regular.Size20.Filter())" Slot="end" Style="opacity: 0.5;" />
147-
</span>
148-
}
149-
</div>
150-
</div>
151-
}
152-
153-
@if (Align == Align.End)
154-
{
155-
@if (Grid.ResizeType is not null)
156-
{
157-
@OptionsButton()
137+
</FluentKeyCode>
158138
}
159139
else
160140
{
161-
@if (ColumnOptions is not null)
141+
<div class="col-title" style="@($"width: calc(100% - {wdelta});")">
142+
<div class="col-title-text" title="@tooltip">
143+
@Title
144+
@if (ColumnOptions is not null && Filtered.GetValueOrDefault() && Grid.ResizeType.HasValue)
145+
{
146+
<span style="padding: 0 5px;">
147+
<FluentIcon Value="@(new CoreIcons.Regular.Size20.Filter())" Slot="end" Style="opacity: 0.5;" />
148+
</span>
149+
}
150+
</div>
151+
</div>
152+
}
153+
154+
@if (Align == Align.End)
155+
{
156+
@if (Grid.ResizeType is not null)
162157
{
163-
@FilterButton()
158+
@OptionsButton()
159+
}
160+
else
161+
{
162+
@if (ColumnOptions is not null)
163+
{
164+
@FilterButton()
165+
}
164166
}
165167
}
166-
}
168+
</div>
167169

168170
}
169171
}
@@ -181,23 +183,23 @@
181183
{
182184
return
183185
@<FluentButton Appearance="Appearance.Stealth" class="col-options-button" @onclick="@(() => Grid.ShowColumnOptionsAsync(this))" aria-label="Filter this column">
184-
<FluentIcon Value="@(new CoreIcons.Regular.Size20.ChevronDown())" Color="Color.Neutral" Width="20px" Style="opacity: 0.5;" />
185-
</FluentButton>;
186+
<FluentIcon Value="@(new CoreIcons.Regular.Size20.ChevronDown())" Color="Color.Neutral" Width="20px" Style="opacity: 0.5;" />
187+
</FluentButton>;
186188
}
187189

188190
private RenderFragment FilterButton()
189191
{
190192
return
191193
@<FluentButton Appearance="Appearance.Stealth" class="col-options-button" @onclick="@(() => Grid.ShowColumnOptionsAsync(this))" aria-label="Filter this column">
192-
@if (Filtered.GetValueOrDefault())
193-
{
194+
@if (Filtered.GetValueOrDefault())
195+
{
194196
<FluentIcon Value="@(new CoreIcons.Regular.Size20.FilterDismiss())" />
195-
}
196-
else
197-
{
197+
}
198+
else
199+
{
198200
<FluentIcon Value="@(new CoreIcons.Regular.Size20.Filter())" />
199-
}
201+
}
200202

201-
</FluentButton>;
203+
</FluentButton>;
202204
}
203205
}

src/Core/Components/DataGrid/FluentDataGridCell.razor.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public partial class FluentDataGridCell<TGridItem> : FluentComponentBase
7979
.AddStyle("height", $"{(int)Grid.RowSize}px", () => !Grid.EffectiveLoadingValue && !Grid.Virtualize && !Grid.MultiLine && (Grid.Items is not null || Grid.ItemsProvider is not null))
8080
.AddStyle("height", "100%", Grid.MultiLine)
8181
.AddStyle("min-height", "44px", Owner.RowType != DataGridRowType.Default)
82-
.AddStyle("display", "flex", ShouldHaveDisplayFlex())
8382
.AddStyle("z-index", ZIndex.DataGridHeaderPopup.ToString(), CellType == DataGridCellType.ColumnHeader && Grid._columns.Count > 0)
8483
.AddStyle(Owner.Style)
8584
.Build();
@@ -126,25 +125,4 @@ internal async Task HandleOnCellKeyDownAsync(KeyboardEventArgs e)
126125

127126
public void Dispose() => Owner.Unregister(this);
128127

129-
private bool ShouldHaveDisplayFlex()
130-
{
131-
132-
var isHeaderCell = CellType == DataGridCellType.ColumnHeader;
133-
134-
if (!isHeaderCell)
135-
{
136-
return false;
137-
}
138-
139-
var isButtonWithMenu = Grid.HeaderCellAsButtonWithMenu;
140-
var isResizable = Grid.ResizableColumns;
141-
var isNotResizableWithOptions = !Grid.ResizableColumns && Column?.ColumnOptions is not null;
142-
var isSelectColumn = Column?.GetType() == typeof(SelectColumn<TGridItem>);
143-
//var isColumnNull = Column is null;
144-
var isSortable = (Column?.Sortable.HasValue ?? false) && Column?.Sortable.Value == true;
145-
var isSortByNull = Column?.SortBy is null;
146-
var isColumnsCountGreaterThanZero = Grid._columns.Count > 0;
147-
148-
return isHeaderCell && !isButtonWithMenu && (isResizable || isNotResizableWithOptions) && !isSelectColumn && isColumnsCountGreaterThanZero && (!isSortable || isSortByNull);
149-
}
150128
}

tests/Core/DataGrid/DataGridSortByTests.DataGridSortByTests_SortByColumnIndex_Ascending.verified.razor.html

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
<thead b-ppmhrkw1mj="">
44
<tr class="fluent-data-grid-row" data-row-index="0" role="row" row-type="header" blazor:onkeydown="3" blazor:onclick="4" blazor:ondblclick="5" blazor:onfocus="6" b-upi3f9mbnn="">
55
<th col-index="1" class="column-header col-justify-start col-sort-asc" style="grid-column: 1; height: 32px; min-height: 44px; z-index: 5;" blazor:oncontextmenu:preventdefault="" blazor:onkeydown="27" blazor:onclick="28" blazor:onfocus="29" scope="col" aria-sort="ascending" b-w6qdxfylwy="">
6-
<span class="keycapture" style="width: 100%;" blazor:oncontextmenu="57" blazor:elementreference="">
7-
<fluent-button class="col-sort-button" style="width: calc(100% - 20px);" type="button" appearance="stealth" blazor:onclick="58" b-x1200685t0="" blazor:elementreference="">
8-
<div class="col-title-text" b-pxhtqoo8qd="">Item1</div>
9-
<svg slot="end" style="width: 20px; fill: var(--accent-fill-rest); opacity: 0.5;" focusable="false" viewBox="0 0 20 20" aria-hidden="true" blazor:onkeydown="59" blazor:onclick="60">
10-
<path d="M9 4.71 6.35 7.35a.5.5 0 1 1-.7-.7L9.1 3.18a.5.5 0 0 1 .74-.03h.01l3.5 3.5a.5.5 0 1 1-.71.7L10 4.71V16.5a.5.5 0 0 1-1 0V4.71Z"></path>
11-
</svg>
12-
</fluent-button>
13-
</span>
6+
<div style="display: flex;" b-pxhtqoo8qd="">
7+
<span class="keycapture" style="width: 100%;" blazor:oncontextmenu="57" blazor:elementreference="">
8+
<fluent-button class="col-sort-button" style="width: calc(100% - 20px);" type="button" appearance="stealth" blazor:onclick="58" b-x1200685t0="" blazor:elementreference="">
9+
<div class="col-title-text" b-pxhtqoo8qd="">Item1</div>
10+
<svg slot="end" style="width: 20px; fill: var(--accent-fill-rest); opacity: 0.5;" focusable="false" viewBox="0 0 20 20" aria-hidden="true" blazor:onkeydown="59" blazor:onclick="60">
11+
<path d="M9 4.71 6.35 7.35a.5.5 0 1 1-.7-.7L9.1 3.18a.5.5 0 0 1 .74-.03h.01l3.5 3.5a.5.5 0 1 1-.71.7L10 4.71V16.5a.5.5 0 0 1-1 0V4.71Z"></path>
12+
</svg>
13+
</fluent-button>
14+
</span>
15+
</div>
1416
</th>
1517
<th col-index="2" class="column-header col-justify-start" style="grid-column: 2; height: 32px; min-height: 44px; z-index: 5;" blazor:oncontextmenu:preventdefault="" blazor:onkeydown="30" blazor:onclick="31" blazor:onfocus="32" scope="col" aria-sort="none" b-w6qdxfylwy="">
16-
<div class="col-title" style="width: calc(100% - 20px);" b-pxhtqoo8qd="">
17-
<div class="col-title-text" b-pxhtqoo8qd="">Item2</div>
18+
<div style="display: flex;" b-pxhtqoo8qd="">
19+
<div class="col-title" style="width: calc(100% - 20px);" b-pxhtqoo8qd="">
20+
<div class="col-title-text" b-pxhtqoo8qd="">Item2</div>
21+
</div>
1822
</div>
1923
</th>
2024
</tr>

tests/Core/DataGrid/DataGridSortByTests.DataGridSortByTests_SortByColumnIndex_Descending.verified.razor.html

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
<thead b-ppmhrkw1mj="">
44
<tr class="fluent-data-grid-row" data-row-index="0" role="row" row-type="header" blazor:onkeydown="3" blazor:onclick="4" blazor:ondblclick="5" blazor:onfocus="6" b-upi3f9mbnn="">
55
<th col-index="1" class="column-header col-justify-start col-sort-desc" style="grid-column: 1; height: 32px; min-height: 44px; z-index: 5;" blazor:oncontextmenu:preventdefault="" blazor:onkeydown="27" blazor:onclick="28" blazor:onfocus="29" scope="col" aria-sort="descending" b-w6qdxfylwy="">
6-
<span class="keycapture" style="width: 100%;" blazor:oncontextmenu="57" blazor:elementreference="">
7-
<fluent-button class="col-sort-button" style="width: calc(100% - 20px);" type="button" appearance="stealth" blazor:onclick="58" b-x1200685t0="" blazor:elementreference="">
8-
<div class="col-title-text" b-pxhtqoo8qd="">Item1</div>
9-
<svg slot="end" style="width: 20px; fill: var(--accent-fill-rest); opacity: 0.5;" focusable="false" viewBox="0 0 20 20" aria-hidden="true" blazor:onkeydown="59" blazor:onclick="60">
10-
<path d="m10 15.29 2.65-2.64a.5.5 0 0 1 .7.7L9.9 16.82a.5.5 0 0 1-.74.03h-.01l-3.5-3.5a.5.5 0 1 1 .71-.7L9 15.29V3.5a.5.5 0 0 1 1 0v11.79Z"></path>
11-
</svg>
12-
</fluent-button>
13-
</span>
6+
<div style="display: flex;" b-pxhtqoo8qd="">
7+
<span class="keycapture" style="width: 100%;" blazor:oncontextmenu="57" blazor:elementreference="">
8+
<fluent-button class="col-sort-button" style="width: calc(100% - 20px);" type="button" appearance="stealth" blazor:onclick="58" b-x1200685t0="" blazor:elementreference="">
9+
<div class="col-title-text" b-pxhtqoo8qd="">Item1</div>
10+
<svg slot="end" style="width: 20px; fill: var(--accent-fill-rest); opacity: 0.5;" focusable="false" viewBox="0 0 20 20" aria-hidden="true" blazor:onkeydown="59" blazor:onclick="60">
11+
<path d="m10 15.29 2.65-2.64a.5.5 0 0 1 .7.7L9.9 16.82a.5.5 0 0 1-.74.03h-.01l-3.5-3.5a.5.5 0 1 1 .71-.7L9 15.29V3.5a.5.5 0 0 1 1 0v11.79Z"></path>
12+
</svg>
13+
</fluent-button>
14+
</span>
15+
</div>
1416
</th>
1517
<th col-index="2" class="column-header col-justify-start" style="grid-column: 2; height: 32px; min-height: 44px; z-index: 5;" blazor:oncontextmenu:preventdefault="" blazor:onkeydown="30" blazor:onclick="31" blazor:onfocus="32" scope="col" aria-sort="none" b-w6qdxfylwy="">
16-
<div class="col-title" style="width: calc(100% - 20px);" b-pxhtqoo8qd="">
17-
<div class="col-title-text" b-pxhtqoo8qd="">Item2</div>
18+
<div style="display: flex;" b-pxhtqoo8qd="">
19+
<div class="col-title" style="width: calc(100% - 20px);" b-pxhtqoo8qd="">
20+
<div class="col-title-text" b-pxhtqoo8qd="">Item2</div>
21+
</div>
1822
</div>
1923
</th>
2024
</tr>

tests/Core/DataGrid/DataGridSortByTests.DataGridSortByTests_SortByColumnTitle_Ascending.verified.razor.html

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
<thead b-ppmhrkw1mj="">
44
<tr class="fluent-data-grid-row" data-row-index="0" role="row" row-type="header" blazor:onkeydown="3" blazor:onclick="4" blazor:ondblclick="5" blazor:onfocus="6" b-upi3f9mbnn="">
55
<th col-index="1" class="column-header col-justify-start col-sort-asc" style="grid-column: 1; height: 32px; min-height: 44px; z-index: 5;" blazor:oncontextmenu:preventdefault="" blazor:onkeydown="27" blazor:onclick="28" blazor:onfocus="29" scope="col" aria-sort="ascending" b-w6qdxfylwy="">
6-
<span class="keycapture" style="width: 100%;" blazor:oncontextmenu="57" blazor:elementreference="">
7-
<fluent-button class="col-sort-button" style="width: calc(100% - 20px);" type="button" appearance="stealth" blazor:onclick="58" b-x1200685t0="" blazor:elementreference="">
8-
<div class="col-title-text" b-pxhtqoo8qd="">Item1</div>
9-
<svg slot="end" style="width: 20px; fill: var(--accent-fill-rest); opacity: 0.5;" focusable="false" viewBox="0 0 20 20" aria-hidden="true" blazor:onkeydown="59" blazor:onclick="60">
10-
<path d="M9 4.71 6.35 7.35a.5.5 0 1 1-.7-.7L9.1 3.18a.5.5 0 0 1 .74-.03h.01l3.5 3.5a.5.5 0 1 1-.71.7L10 4.71V16.5a.5.5 0 0 1-1 0V4.71Z"></path>
11-
</svg>
12-
</fluent-button>
13-
</span>
6+
<div style="display: flex;" b-pxhtqoo8qd="">
7+
<span class="keycapture" style="width: 100%;" blazor:oncontextmenu="57" blazor:elementreference="">
8+
<fluent-button class="col-sort-button" style="width: calc(100% - 20px);" type="button" appearance="stealth" blazor:onclick="58" b-x1200685t0="" blazor:elementreference="">
9+
<div class="col-title-text" b-pxhtqoo8qd="">Item1</div>
10+
<svg slot="end" style="width: 20px; fill: var(--accent-fill-rest); opacity: 0.5;" focusable="false" viewBox="0 0 20 20" aria-hidden="true" blazor:onkeydown="59" blazor:onclick="60">
11+
<path d="M9 4.71 6.35 7.35a.5.5 0 1 1-.7-.7L9.1 3.18a.5.5 0 0 1 .74-.03h.01l3.5 3.5a.5.5 0 1 1-.71.7L10 4.71V16.5a.5.5 0 0 1-1 0V4.71Z"></path>
12+
</svg>
13+
</fluent-button>
14+
</span>
15+
</div>
1416
</th>
1517
<th col-index="2" class="column-header col-justify-start" style="grid-column: 2; height: 32px; min-height: 44px; z-index: 5;" blazor:oncontextmenu:preventdefault="" blazor:onkeydown="30" blazor:onclick="31" blazor:onfocus="32" scope="col" aria-sort="none" b-w6qdxfylwy="">
16-
<div class="col-title" style="width: calc(100% - 20px);" b-pxhtqoo8qd="">
17-
<div class="col-title-text" b-pxhtqoo8qd="">Item2</div>
18+
<div style="display: flex;" b-pxhtqoo8qd="">
19+
<div class="col-title" style="width: calc(100% - 20px);" b-pxhtqoo8qd="">
20+
<div class="col-title-text" b-pxhtqoo8qd="">Item2</div>
21+
</div>
1822
</div>
1923
</th>
2024
</tr>

0 commit comments

Comments
 (0)