Skip to content

Commit 1d77dde

Browse files
committed
Add ShowResizeIndicator to enable showing a vertical line across all rows when resizing a column.
1 parent 35f9e1a commit 1d77dde

7 files changed

+64
-9
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1937,13 +1937,18 @@
19371937
This allows the user to resize columns manually. Size changes are not persisted.
19381938
</summary>
19391939
</member>
1940+
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.ShowResizeIndicator">
1941+
<summary>
1942+
Gets or sets whether the grid should show a resize indicator on all column cells when resizing a column.
1943+
</summary>
1944+
</member>
19401945
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.ResizeType">
19411946
<summary>
19421947
To comply with WCAG 2.2, a one-click option should be offered to change column widths. We provide such an option through the
19431948
ColumnOptions UI. This parameter allows you to enable or disable this resize UI.Enable it by setting the type of resize to perform
19441949
Discrete: resize by a 10 pixels at a time
19451950
Exact: resize to the exact width specified (in pixels)
1946-
Note: This does not affect resizing by mouse dragging, just the keyboard driven resize.
1951+
Note: This does not affect resizing by mouse dragging, only applies to keyboard driven resize.
19471952
</summary>
19481953
</member>
19491954
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.ColumnResizeLabels">

examples/Demo/Shared/Pages/DataGrid/Examples/DataGridCustomComparer.razor

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
</FluentRadioGroup>
1919
<FluentSpacer Width="25" />
2020
<FluentCheckbox @bind-Value="@_showActionsMenu" Label="Use menu for column actions" />
21+
<FluentCheckbox @bind-Value="@_showResizeIndicator" Label="Show resize indicator" />
2122
</FluentToolbar>
2223
<div style="height: 400px; overflow-x:auto; display:flex;">
2324
<FluentDataGrid Items="@FilteredItems"
@@ -28,7 +29,8 @@
2829
TGridItem="Country"
2930
OnRowFocus="HandleRowFocus"
3031
GridTemplateColumns="0.2fr 1fr 0.2fr 0.2fr 0.2fr 0.2fr"
31-
ShowHover="true">
32+
ShowHover="true"
33+
ShowResizeIndicator="@_showResizeIndicator">
3234
<TemplateColumn Title="Rank" Sortable="true" SortBy="@rankSort" Align="Align.Center">
3335
<img class="flag" src="_content/FluentUI.Demo.Shared/flags/@(context.Code).svg" alt="Flag of @(context.Code)" />
3436
</TemplateColumn>
@@ -75,6 +77,7 @@
7577
string nameFilter = string.Empty;
7678
DataGridResizeType? _resizeType = null;
7779
bool _showActionsMenu;
80+
bool _showResizeIndicator = true;
7881

7982
GridSort<Country> rankSort = GridSort<Country>
8083
.ByDescending(x => x.Medals.Gold)

examples/Demo/Shared/Pages/DataGrid/Pages/DataGridCustomComparerPage.razor

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
to true, the current row will be highlighted. By default the system will use the designated hover color for this but you can specify an alternative
1919
color by setting the <code>--datagrid-hover-color</code> CSS variable. See the Razor tab for how this is done in this example.
2020
</p>
21-
<p><em>Note: once a value has been selected for the Resize type, it cannot by set to null again. You need to refresh the page to start with a null value again.</em></p>
21+
<p>
22+
The 'Resize type' radio buttons show how to use the <code>ResizeType</code> parameter. This parameter can be used to specify how the columns should be resized. The options are:
23+
<ul>
24+
<li><code>DataGridResizeType.Discrete</code>: the column will be resized to the nearest discrete value (default)</li>
25+
<li><code>DataGridResizeType.Exact</code>: the column will be resized to the exact value</li>
26+
</ul>
27+
<em>Note: once a value has been selected for the Resize type, it cannot be set to null again. You need to refresh the page to start with a null value again.</em>
28+
</p>
29+
<p>
30+
The 'Use menu for column actions' checkbox shows how to use the <code>HeaderCellAsButtonWithMenu</code> parameter. When set to true, the headers are rendered as buttons with an associated menu. When clicked,
31+
the menu options allow for sorting, filtering and/or resizing columns (depending on how the DataGrid and columns have been configured). From an accessibility standpoint this is the preferred way of working with DataGrid headers.
32+
</p>
33+
<p>
34+
The 'Show Resize Indicator' checkbox shows how to use the <code>ShowResizeIndicator</code> parameter. This parameter can be used to show a resize indicator when a column is being resized.
35+
If set to false (default), a resize indicator will not be shown.
36+
</p>
2237
</Description>
2338
</DemoSection>

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,18 @@ public partial class FluentDataGrid<TGridItem> : FluentComponentBase, IHandleEve
114114
[Parameter]
115115
public bool ResizableColumns { get; set; }
116116

117+
/// <summary>
118+
/// Gets or sets whether the grid should show a resize indicator on all column cells when resizing a column.
119+
/// </summary>
120+
[Parameter]
121+
public bool ShowResizeIndicator { get; set; } = false;
122+
117123
/// <summary>
118124
/// To comply with WCAG 2.2, a one-click option should be offered to change column widths. We provide such an option through the
119125
/// ColumnOptions UI. This parameter allows you to enable or disable this resize UI.Enable it by setting the type of resize to perform
120126
/// Discrete: resize by a 10 pixels at a time
121127
/// Exact: resize to the exact width specified (in pixels)
122-
/// Note: This does not affect resizing by mouse dragging, just the keyboard driven resize.
128+
/// Note: This does not affect resizing by mouse dragging, only applies to keyboard driven resize.
123129
/// </summary>
124130
[Parameter]
125131
public DataGridResizeType? ResizeType { get; set; }
@@ -456,7 +462,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
456462
Module ??= await JSRuntime.InvokeAsync<IJSObjectReference>("import", JAVASCRIPT_FILE.FormatCollocatedUrl(LibraryConfiguration));
457463
try
458464
{
459-
_jsEventDisposable = await Module.InvokeAsync<IJSObjectReference>("init", _gridReference, AutoFocus);
465+
_jsEventDisposable = await Module.InvokeAsync<IJSObjectReference>("init", _gridReference, AutoFocus, ShowResizeIndicator);
460466
if (AutoItemsPerPage)
461467
{
462468
await Module.InvokeVoidAsync("dynamicItemsPerPage", _gridReference, DotNetObjectReference.Create(this), (int)RowSize);
@@ -793,7 +799,7 @@ private async Task RefreshDataCoreAsync()
793799

794800
if (!request.CancellationToken.IsCancellationRequested)
795801
{
796-
// ARIA's rowcount is part of the UI, so it should reflect what the human user regards as the number of rows in the table,
802+
// ARIA's row count is part of the UI, so it should reflect what the human user regards as the number of rows in the table,
797803
// not the number of physical <tr> elements. For virtualization this means what's in the entire scrollable range, not just
798804
// the current viewport. In the case where you're also paginating then it means what's conceptually on the current page.
799805
// TODO: This currently assumes we always want to expand the last page to have ItemsPerPage rows, but the experience might

src/Core/Components/DataGrid/FluentDataGrid.razor.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@
9090
background-color: var(--neutral-fill-stealth-rest);
9191
z-index: 2;
9292
}
93+
94+
95+
::deep .indicator > .resize-indicator {
96+
border-inline-end: calc(var(--stroke-width) * 2px) solid var(--neutral-stroke-rest);
97+
transition: border-inline-end 0.2s ease-in-out;
98+
}

src/Core/Components/DataGrid/FluentDataGrid.razor.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
let grids = [];
22
const minWidth = 100;
33

4-
export function init(gridElement, autoFocus) {
4+
export function init(gridElement, autoFocus, showResizeIndicator) {
55
if (gridElement === undefined || gridElement === null) {
66
return;
77
};
88

9-
enableColumnResizing(gridElement);
9+
enableColumnResizing(gridElement, showResizeIndicator);
1010

1111
let start = gridElement.querySelector('td:first-child');
1212

@@ -158,7 +158,7 @@ export function checkColumnPopupPosition(gridElement, selector) {
158158
}
159159
}
160160

161-
export function enableColumnResizing(gridElement) {
161+
export function enableColumnResizing(gridElement, showResizeIndicator) {
162162
const columns = [];
163163
let min = 75;
164164
let headerBeingResized;
@@ -214,6 +214,16 @@ export function enableColumnResizing(gridElement) {
214214
window.removeEventListener('pointerleave', onPointerUp);
215215

216216
headerBeingResized.classList.remove('header-being-resized');
217+
218+
if (showResizeIndicator) {
219+
// Add the resize handle back
220+
headerBeingResized.querySelector('.resize-handle').style.display = 'block';
221+
222+
// Remove the indicator class after resizing
223+
const cells = gridElement.querySelectorAll('.resize-indicator');
224+
cells.forEach(cell => cell.classList.remove('resize-indicator'));
225+
}
226+
217227
headerBeingResized = null;
218228

219229
if (e.target.hasPointerCapture(e.pointerId)) {
@@ -225,6 +235,15 @@ export function enableColumnResizing(gridElement) {
225235
headerBeingResized = target.parentNode;
226236
headerBeingResized.classList.add('header-being-resized');
227237

238+
if (showResizeIndicator) {
239+
// Hide the resize handle while resizing
240+
headerBeingResized.querySelector('.resize-handle').style.display = 'none';
241+
242+
// Add indicator class to all cells in the column being resized
243+
const columnIndex = Array.from(headers).indexOf(headerBeingResized) + 1;
244+
const cells = gridElement.querySelectorAll(`[col-index="${columnIndex}"]`);
245+
cells.forEach(cell => cell.classList.add('resize-indicator'));
246+
}
228247

229248
window.addEventListener('pointermove', onPointerMove);
230249
window.addEventListener('pointerup', onPointerUp);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public partial class FluentDataGridRow<TGridItem> : FluentComponentBase, IHandle
6666
protected string? ClassValue => new CssBuilder(Class)
6767
.AddClass("fluent-data-grid-row")
6868
.AddClass("hover", when: Grid.ShowHover)
69+
.AddClass("indicator", when: Grid.ShowResizeIndicator)
6970
.Build();
7071

7172
protected string? StyleValue => new StyleBuilder(Style)

0 commit comments

Comments
 (0)