Skip to content

Commit

Permalink
Blazor column placeholder (#1967)
Browse files Browse the repository at this point in the history
# Pull Request

## 🀨 Rationale

Adds Blazor support for column placeholders, which is part of #1538.

## πŸ‘©β€πŸ’» Implementation

Add `Placeholder` to the 5 columns that support that property.

## πŸ§ͺ Testing

Added unit tests

## βœ… Checklist

<!--- Review the list and put an x in the boxes that apply or ~~strike
through~~ around items that don't (along with an explanation). -->

- [ ] I have updated the project documentation to reflect my changes or
determined no changes are needed.
  • Loading branch information
mollykreis authored Mar 28, 2024
1 parent 36130d3 commit 446055c
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Add support for column placeholders",
"packageName": "@ni/nimble-blazor",
"email": "20542556+mollykreis@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<nimble-table-column-anchor
label-field-name="@LabelFieldName"
href-field-name="@HrefFieldName"
placeholder="@Placeholder"
appearance="@Appearance.ToAttributeValue()"
underline-hidden="@UnderlineHidden"
hreflang="@HrefLang"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public partial class NimbleTableColumnAnchor : NimbleTableColumn, IFractionalWid
[DisallowNull]
public string HrefFieldName { get; set; } = null!;

/// <summary>
/// The placeholder text to display when the label and href are both null for a record.
/// </summary>
[Parameter]
public string? Placeholder { get; set; }

/// <summary>
/// The appearance of the anchor.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<nimble-table-column-date-text
column-id="@ColumnId"
field-name="@FieldName"
placeholder="@Placeholder"
action-menu-slot="@ActionMenuSlot"
action-menu-label="@ActionMenuLabel"
column-hidden="@ColumnHidden"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public partial class NimbleTableColumnDateText : NimbleTableColumn, IFractionalW
[DisallowNull]
public string FieldName { get; set; } = null!;

/// <summary>
/// The placeholder text to display when the field value is null for a record.
/// </summary>
[Parameter]
public string? Placeholder { get; set; }

/// <summary>
/// The fractional/proportional width to use for this column
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<nimble-table-column-duration-text
column-id="@ColumnId"
field-name="@FieldName"
placeholder="@Placeholder"
action-menu-slot="@ActionMenuSlot"
action-menu-label="@ActionMenuLabel"
column-hidden="@ColumnHidden"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public partial class NimbleTableColumnDurationText : NimbleTableColumn, IFractio
[DisallowNull]
public string FieldName { get; set; } = null!;

/// <summary>
/// The placeholder text to display when the field value is null for a record.
/// </summary>
[Parameter]
public string? Placeholder { get; set; }

/// <summary>
/// The fractional/proportional width to use for this column
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<nimble-table-column-number-text
column-id="@ColumnId"
field-name="@FieldName"
placeholder="@Placeholder"
action-menu-slot="@ActionMenuSlot"
action-menu-label="@ActionMenuLabel"
column-hidden="@ColumnHidden"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public partial class NimbleTableColumnNumberText : NimbleTableColumn, IFractiona
[DisallowNull]
public string FieldName { get; set; } = null!;

/// <summary>
/// The placeholder text to display when the field value is null for a record.
/// </summary>
[Parameter]
public string? Placeholder { get; set; }

/// <summary>
/// The fractional/proportional width to use for this column
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<nimble-table-column-text
column-id="@ColumnId"
field-name="@FieldName"
placeholder="@Placeholder"
action-menu-slot="@ActionMenuSlot"
action-menu-label="@ActionMenuLabel"
column-hidden="@ColumnHidden"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public partial class NimbleTableColumnText : NimbleTableColumn, IFractionalWidth
[DisallowNull]
public string FieldName { get; set; } = null!;

/// <summary>
/// The placeholder text to display when the field value is null for a record.
/// </summary>
[Parameter]
public string? Placeholder { get; set; }

/// <summary>
/// The fractional/proportional width to use for this column
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public void NimbleTableColumnAnchor_WithAppearanceAttribute_HasTableMarkup()
Assert.Contains(expectedMarkup, tableColumn.Markup);
}

[Fact]
public void NimbleTableColumnAnchor_WithPlaceholderAttribute_HasTableMarkup()
{
var table = RenderWithPropertySet(x => x.Placeholder, "Custom placeholder");

var expectedMarkup = @"placeholder=""Custom placeholder""";
Assert.Contains(expectedMarkup, table.Markup);
}

[Fact]
public void NimbleTableColumnAnchor_WithUnderlineHiddenAttribute_HasTableMarkup()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public void NimbleTableColumnDateText_WithFieldNameAttribute_HasTableMarkup()
Assert.Contains(expectedMarkup, table.Markup);
}

[Fact]
public void NimbleTableColumnDateText_WithPlaceholderAttribute_HasTableMarkup()
{
var table = RenderWithPropertySet(x => x.Placeholder, "Custom placeholder");

var expectedMarkup = @"placeholder=""Custom placeholder""";
Assert.Contains(expectedMarkup, table.Markup);
}

[Theory]
[InlineData(DateTextFormat.Default, "<nimble-table-column-date-text((?!format).)*>")]
[InlineData(DateTextFormat.Custom, @"format=""custom""")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public void NimbleTableColumnDurationText_WithFieldNameAttribute_HasTableMarkup(
Assert.Contains(expectedMarkup, table.Markup);
}

[Fact]
public void NimbleTableColumnDurationText_WithPlaceholderAttribute_HasTableMarkup()
{
var table = RenderWithPropertySet(x => x.Placeholder, "Custom placeholder");

var expectedMarkup = @"placeholder=""Custom placeholder""";
Assert.Contains(expectedMarkup, table.Markup);
}

private IRenderedComponent<NimbleTableColumnDurationText> RenderWithPropertySet<TProperty>(Expression<Func<NimbleTableColumnDurationText, TProperty>> propertyGetter, TProperty propertyValue)
{
var context = new TestContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public void NimbleTableColumnNumberText_WithFieldNameAttribute_HasTableMarkup()
Assert.Contains(expectedMarkup, table.Markup);
}

[Fact]
public void NimbleTableColumnNumberText_WithPlaceholderAttribute_HasTableMarkup()
{
var table = RenderWithPropertySet(x => x.Placeholder, "Custom placeholder");

var expectedMarkup = @"placeholder=""Custom placeholder""";
Assert.Contains(expectedMarkup, table.Markup);
}

[Fact]
public void NimbleTableColumnNumberText_WithDecimalDigitsAttribute_HasTableMarkup()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public void NimbleTableColumnText_WithFieldNameAttribute_HasTableMarkup()
Assert.Contains(expectedMarkup, table.Markup);
}

[Fact]
public void NimbleTableColumnText_WithPlaceholderAttribute_HasTableMarkup()
{
var table = RenderWithPropertySet(x => x.Placeholder, "Custom placeholder");

var expectedMarkup = @"placeholder=""Custom placeholder""";
Assert.Contains(expectedMarkup, table.Markup);
}

private IRenderedComponent<NimbleTableColumnText> RenderWithPropertySet<TProperty>(Expression<Func<NimbleTableColumnText, TProperty>> propertyGetter, TProperty propertyValue)
{
var context = new TestContext();
Expand Down

0 comments on commit 446055c

Please sign in to comment.