Skip to content

Commit

Permalink
Angular and Blazor label provider changes for scrollable tabs. (#2447)
Browse files Browse the repository at this point in the history
# Pull Request

## 🀨 Rationale

- #1509

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

Standard boiler-plate implementation for exposing label provider
attributes to Angular/Blazor.

## πŸ§ͺ Testing

Typical boiler-plate 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
Jonathan Meyer authored Oct 24, 2024
1 parent 6c1979e commit 868a8a6
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Angular and Blazor label provider changes for scrollable tabs.",
"packageName": "@ni/nimble-angular",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Angular and Blazor label provider changes for scrollable tabs.",
"packageName": "@ni/nimble-blazor",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ export class NimbleLabelProviderCoreWithDefaultsDirective {
this.elementRef.nativeElement.filterSearch = $localize`:Nimble select - search items|:Search`;
this.elementRef.nativeElement.filterNoResults = $localize`:Nimble select - no items|:No items found`;
this.elementRef.nativeElement.loading = $localize`:Nimble loading - loading|:Loading…`;
this.elementRef.nativeElement.scrollBackward = $localize`:Nimble scroll backward|:Scroll backward`;
this.elementRef.nativeElement.scrollForward = $localize`:Nimble scroll forward|:Scroll forward`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,20 @@ export class NimbleLabelProviderCoreDirective {
@Input('loading') public set loading(value: string | undefined) {
this.renderer.setProperty(this.elementRef.nativeElement, 'loading', value);
}

public get scrollBackward(): string | undefined {
return this.elementRef.nativeElement.scrollBackward;
}

@Input('scrollBackward') public set scrollBackward(value: string | undefined) {
this.renderer.setProperty(this.elementRef.nativeElement, 'scrollBackward', value);
}

public get scrollForward(): string | undefined {
return this.elementRef.nativeElement.scrollForward;
}

@Input('scrollForward') public set scrollForward(value: string | undefined) {
this.renderer.setProperty(this.elementRef.nativeElement, 'scrollForward', value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ describe('Nimble LabelProviderCore withDefaults directive', () => {
[computeMsgId('Information', 'Nimble popup icon - information')]: 'Translated information',
[computeMsgId('Search', 'Nimble select - search items')]: 'Translated search',
[computeMsgId('No items found', 'Nimble select - no items')]: 'Translated no items found',
[computeMsgId('Loading…', 'Nimble loading - loading')]: 'Translated loading'
[computeMsgId('Loading…', 'Nimble loading - loading')]: 'Translated loading',
[computeMsgId('Scroll backward', 'Nimble scroll backward')]: 'Translated scroll backward',
[computeMsgId('Scroll forward', 'Nimble scroll forward')]: 'Translated scroll forward'
});
const fixture = TestBed.createComponent(TestHostComponent);
const testHostComponent = fixture.componentInstance;
Expand All @@ -54,5 +56,7 @@ describe('Nimble LabelProviderCore withDefaults directive', () => {
expect(labelProvider.filterSearch).toBe('Translated search');
expect(labelProvider.filterNoResults).toBe('Translated no items found');
expect(labelProvider.loading).toBe('Translated loading');
expect(labelProvider.scrollBackward).toBe('Translated scroll backward');
expect(labelProvider.scrollForward).toBe('Translated scroll forward');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ describe('Nimble Label Provider Core', () => {
const label6 = 'String 6';
const label7 = 'String 7';
const label8 = 'String 8';
const label9 = 'String 9';
const label10 = 'String 10';
const label11 = 'String `11';

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -88,6 +91,21 @@ describe('Nimble Label Provider Core', () => {
expect(directive.filterNoResults).toBeUndefined();
expect(nativeElement.filterNoResults).toBeUndefined();
});

it('has expected defaults for loading', () => {
expect(directive.loading).toBeUndefined();
expect(nativeElement.loading).toBeUndefined();
});

it('has expected defaults for scrollBackward', () => {
expect(directive.scrollBackward).toBeUndefined();
expect(nativeElement.scrollBackward).toBeUndefined();
});

it('has expected defaults for scrollForward', () => {
expect(directive.scrollForward).toBeUndefined();
expect(nativeElement.scrollForward).toBeUndefined();
});
});

describe('with template string values', () => {
Expand All @@ -102,6 +120,9 @@ describe('Nimble Label Provider Core', () => {
popup-icon-information="${label6}"
filter-search="${label7}"
filter-no-results="${label8}"
loading="${label9}"
scroll-backward="${label10}"
scroll-forward="${label11}"
>
</nimble-label-provider-core>
`
Expand Down Expand Up @@ -165,6 +186,21 @@ describe('Nimble Label Provider Core', () => {
expect(directive.filterNoResults).toBe(label8);
expect(nativeElement.filterNoResults).toBe(label8);
});

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

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

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

describe('with property bound values', () => {
Expand All @@ -179,6 +215,9 @@ describe('Nimble Label Provider Core', () => {
[popupIconInformation]="popupIconInformation"
[filterSearch]="filterSearch"
[filterNoResults]="filterNoResults"
[loading]="loading"
[scrollBackward]="scrollBackward"
[scrollForward]="scrollForward"
>
</nimble-label-provider-core>
`
Expand All @@ -194,6 +233,9 @@ describe('Nimble Label Provider Core', () => {
public popupIconInformation = label1;
public filterSearch = label1;
public filterNoResults = label1;
public loading = label1;
public scrollBackward = label1;
public scrollForward = label1;
}

let fixture: ComponentFixture<TestHostComponent>;
Expand Down Expand Up @@ -298,6 +340,39 @@ describe('Nimble Label Provider Core', () => {
expect(directive.filterNoResults).toBe(label2);
expect(nativeElement.filterNoResults).toBe(label2);
});

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

fixture.componentInstance.loading = label2;
fixture.detectChanges();

expect(directive.loading).toBe(label2);
expect(nativeElement.loading).toBe(label2);
});

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

fixture.componentInstance.scrollBackward = label2;
fixture.detectChanges();

expect(directive.scrollBackward).toBe(label2);
expect(nativeElement.scrollBackward).toBe(label2);
});

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

fixture.componentInstance.scrollForward = label2;
fixture.detectChanges();

expect(directive.scrollForward).toBe(label2);
expect(nativeElement.scrollForward).toBe(label2);
});
});

describe('with attribute bound values', () => {
Expand All @@ -312,6 +387,9 @@ describe('Nimble Label Provider Core', () => {
[attr.popup-icon-information]="popupIconInformation"
[attr.filter-search]="filterSearch"
[attr.filter-no-results]="filterNoResults"
[attr.loading]="loading"
[attr.scroll-backward]="scrollBackward"
[attr.scroll-forward]="scrollForward"
>
</nimble-label-provider-core>
`
Expand All @@ -327,6 +405,9 @@ describe('Nimble Label Provider Core', () => {
public popupIconInformation = label1;
public filterSearch = label1;
public filterNoResults = label1;
public loading = label1;
public scrollBackward = label1;
public scrollForward = label1;
}

let fixture: ComponentFixture<TestHostComponent>;
Expand Down Expand Up @@ -431,5 +512,38 @@ describe('Nimble Label Provider Core', () => {
expect(directive.filterNoResults).toBe(label2);
expect(nativeElement.filterNoResults).toBe(label2);
});

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

fixture.componentInstance.loading = label2;
fixture.detectChanges();

expect(directive.loading).toBe(label2);
expect(nativeElement.loading).toBe(label2);
});

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

fixture.componentInstance.scrollBackward = label2;
fixture.detectChanges();

expect(directive.scrollBackward).toBe(label2);
expect(nativeElement.scrollBackward).toBe(label2);
});

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

fixture.componentInstance.scrollForward = label2;
fixture.detectChanges();

expect(directive.scrollForward).toBe(label2);
expect(nativeElement.scrollForward).toBe(label2);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
filter-search="@FilterSearch"
filter-no-results="@FilterNoResults"
loading="@Loading"
scroll-forward="@ScrollForward"
scroll-backward="@ScrollBackward"
@attributes="AdditionalAttributes">
</nimble-label-provider-core>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public partial class NimbleLabelProviderCore : ComponentBase
[Parameter]
public string? Loading { get; set; }

[Parameter]
public string? ScrollBackward { get; set; }

[Parameter]
public string? ScrollForward { get; set; }

/// <summary>
/// Gets or sets a collection of additional attributes that will be applied to the created element.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public void NimbleLabelProviderCore_SupportsAdditionalAttributes()
[InlineData(nameof(NimbleLabelProviderCore.FilterSearch))]
[InlineData(nameof(NimbleLabelProviderCore.FilterNoResults))]
[InlineData(nameof(NimbleLabelProviderCore.Loading))]
[InlineData(nameof(NimbleLabelProviderCore.ScrollBackward))]
[InlineData(nameof(NimbleLabelProviderCore.ScrollForward))]
public void NimbleLabelProviderCore_LabelIsSet(string propertyName)
{
var labelValue = propertyName + "UpdatedValue";
Expand Down

0 comments on commit 868a8a6

Please sign in to comment.