Skip to content

Commit

Permalink
Clearable select integration for Angular/Blazor (#2124)
Browse files Browse the repository at this point in the history
# Pull Request

## 🤨 Rationale

- #1951
  • Loading branch information
atmgrifter00 authored May 21, 2024
1 parent 63403fc commit 89e3bc8
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Adding clearable API for Select.",
"packageName": "@ni/nimble-angular",
"email": "26874831+atmgrifter00@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Adding Clearable API for Select",
"packageName": "@ni/nimble-blazor",
"email": "26874831+atmgrifter00@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ export class NimbleSelectDirective {
this.renderer.setProperty(this.elementRef.nativeElement, 'filterMode', value);
}

public get clearable(): boolean {
return this.elementRef.nativeElement.clearable;
}

@Input() public set clearable(value: BooleanValueOrAttribute) {
this.renderer.setProperty(this.elementRef.nativeElement, 'clearable', toBooleanProperty(value));
}

public get disabled(): boolean {
return this.elementRef.nativeElement.disabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ describe('Nimble select', () => {
expect(nativeElement.filterMode).toBe(FilterMode.none);
});

it('has expected defaults for clearable', () => {
expect(directive.clearable).toBe(false);
expect(nativeElement.clearable).toBe(false);
});

it('has expected defaults for errorText', () => {
expect(directive.errorText).toBeUndefined();
expect(nativeElement.errorText).toBeUndefined();
Expand Down Expand Up @@ -86,6 +91,7 @@ describe('Nimble select', () => {
disabled
appearance="${DropdownAppearance.block}"
filter-mode="${FilterMode.standard}"
clearable
error-text="error text"
error-visible
>
Expand Down Expand Up @@ -127,6 +133,11 @@ describe('Nimble select', () => {
expect(nativeElement.filterMode).toBe(FilterMode.standard);
});

it('will use template string values for clearable', () => {
expect(directive.clearable).toBeTrue();
expect(nativeElement.clearable).toBeTrue();
});

it('will use template string values for errorText', () => {
expect(directive.errorText).toBe('error text');
expect(nativeElement.errorText).toBe('error text');
Expand All @@ -145,6 +156,7 @@ describe('Nimble select', () => {
[disabled] = "disabled"
[appearance]="appearance"
[filter-mode]="filterMode"
[clearable]="clearable"
[error-text]="errorText"
[error-visible]="errorVisible"
>
Expand All @@ -157,6 +169,7 @@ describe('Nimble select', () => {
public disabled = false;
public appearance: DropdownAppearance = DropdownAppearance.block;
public filterMode: FilterMode = FilterMode.standard;
public clearable = false;
public errorText = 'initial value';
public errorVisible = false;
}
Expand Down Expand Up @@ -209,6 +222,17 @@ describe('Nimble select', () => {
expect(nativeElement.filterMode).toBe(FilterMode.none);
});

it('can be configured with property binding for clearable', () => {
expect(directive.clearable).toBeFalse();
expect(nativeElement.clearable).toBeFalse();

fixture.componentInstance.clearable = true;
fixture.detectChanges();

expect(directive.clearable).toBeTrue();
expect(nativeElement.clearable).toBeTrue();
});

it('can be configured with property binding for errorText', () => {
expect(directive.errorText).toBe('initial value');
expect(nativeElement.errorText).toBe('initial value');
Expand Down Expand Up @@ -239,6 +263,7 @@ describe('Nimble select', () => {
[attr.disabled]="disabled"
[attr.appearance]="appearance"
[attr.filter-mode]="filterMode"
[attr.clearable]="clearable"
[attr.error-text]="errorText"
[attr.error-visible]="errorVisible"
>
Expand All @@ -251,6 +276,7 @@ describe('Nimble select', () => {
public disabled: BooleanValueOrAttribute = null;
public appearance: DropdownAppearance = DropdownAppearance.block;
public filterMode: FilterMode;
public clearable: BooleanValueOrAttribute = null;
public errorText = 'initial value';
public errorVisible: BooleanValueOrAttribute = null;
}
Expand Down Expand Up @@ -303,6 +329,17 @@ describe('Nimble select', () => {
expect(nativeElement.filterMode).toBe(FilterMode.standard);
});

it('can be configured with attribute binding for clearable', () => {
expect(directive.clearable).toBeFalse();
expect(nativeElement.clearable).toBeFalse();

fixture.componentInstance.clearable = '';
fixture.detectChanges();

expect(directive.clearable).toBeTrue();
expect(nativeElement.clearable).toBeTrue();
});

it('can be configured with attribute binding for errorText', () => {
expect(directive.errorText).toBe('initial value');
expect(nativeElement.errorText).toBe('initial value');
Expand Down
3 changes: 2 additions & 1 deletion packages/blazor-workspace/CodeAnalysisDictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<Word>args</Word>
<Word>blazor</Word>
<Word>bool</Word>
<Word>combobox</Word>
<Word>clearable</Word>
<Word>combobox</Word>
<Word>dropdown</Word>
<Word>enum</Word>
<Word>frameless</Word>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
</div>
<div class="sub-container">
<div class="container-label">Select</div>
<NimbleSelect Appearance="DropdownAppearance.Underline" FilterMode="FilterMode.Standard">
<NimbleSelect Appearance="DropdownAppearance.Underline" FilterMode="FilterMode.Standard" Clearable="true">
<NimbleListOption>Option 1</NimbleListOption>
<NimbleListOption>Option 2</NimbleListOption>
<NimbleListOption>Option 3</NimbleListOption>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
position="@Position.ToAttributeValue()"
appearance="@Appearance.ToAttributeValue()"
filter-mode="@FilterMode.ToAttributeValue()"
clearable="@Clearable"
error-text="@ErrorText"
error-visible="@ErrorVisible"
@attributes="AdditionalAttributes">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public partial class NimbleSelect : NimbleInputBase<string?>
[Parameter]
public FilterMode? FilterMode { get; set; }

/// <summary>
/// Gets or sets whether the select can be cleared.
/// </summary>
[Parameter]
public bool? Clearable { get; set; }

/// <summary>
/// Gets or sets the select error text
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public void Select_FilterModeNoneIsSet()
Assert.DoesNotContain("filter-mode", select.Markup);
}

[Fact]
public void SelectClearable_AttributeIsSet()
{
var select = RenderWithPropertySet(x => x.Clearable, true);

Assert.Contains("clearable", select.Markup);
}

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

0 comments on commit 89e3bc8

Please sign in to comment.