diff --git a/src/app/components/components/chips/chips.component.html b/src/app/components/components/chips/chips.component.html index 452c99e16f..c6de3f54bb 100644 --- a/src/app/components/components/chips/chips.component.html +++ b/src/app/components/components/chips/chips.component.html @@ -11,9 +11,10 @@ [chipRemoval]="chipRemoval" [items]="filteredStrings" [(ngModel)]="stringsModel" - placeholder="Enter autocomplete strings" + placeholder="Type here" [disabled]="disabled" (inputChange)="filterStrings($event)" + [inputPosition]="before ? 'before' : 'after'" requireMatch> @@ -28,8 +29,9 @@ [chipRemoval]="chipRemoval" [items]="filteredStrings" [(ngModel)]="stringsModel" - placeholder="Enter autocomplete strings" + placeholder="Type here" [disabled]="disabled" + [inputPosition]="before ? 'before' : 'after'" (inputChange)="filterStrings($event)" requireMatch> @@ -42,6 +44,7 @@ disabled: boolean = false; chipAddition: boolean = true; chipRemoval: boolean = true; + before: boolean = false; strings: string[] = [ 'stepper', @@ -101,6 +104,12 @@ Chip removal + +
+ + Input Position Before + +
@@ -115,7 +124,7 @@ @@ -138,7 +147,7 @@ @@ -202,7 +211,7 @@ @@ -221,7 +230,7 @@ @@ -279,7 +288,7 @@ Stacked chips and Autocomplete with custom inputs - Autocomplete demo allowing custom inputs and stacked chips + Autocomplete demo allowing custom inputs, 'before' input position and stacked chips @@ -290,6 +299,7 @@ [(ngModel)]="stackedStringsModel" placeholder="Enter any string" (inputChange)="filterStackedStrings($event)" + inputPosition="before" stacked>
{{chip.substring(0, 1).toUpperCase()}}
{{chip}} @@ -307,6 +317,7 @@ [(ngModel)]="stackedStringsModel" placeholder="Enter any string" (inputChange)="filterStackedStrings($event)" + inputPosition="before" stacked> ]]> @@ -395,7 +406,7 @@
Type and select a preset option or press enter:
+
+ class="td-chips-form-field" + [style.width.px]="canAddChip ? null : 0" + [style.height.px]="canAddChip ? null : 0" + [color]="color"> .td-chip-content { @@ -74,6 +80,17 @@ } } } + .td-chips-stacked { + .mat-basic-chip { + margin: 4px 0; + &:first-of-type { + margin: 8px 0 4px; + } + &:last-of-type { + margin: 4px 0 8px; + } + } + } } .mat-form-field-underline { position: relative; diff --git a/src/platform/core/chips/chips.component.spec.ts b/src/platform/core/chips/chips.component.spec.ts index 4aa6bd8a9f..86e8521141 100644 --- a/src/platform/core/chips/chips.component.spec.ts +++ b/src/platform/core/chips/chips.component.spec.ts @@ -44,6 +44,7 @@ describe('Component: Chips', () => { TdChipsBasicTestComponent, TdChipsObjectsRequireMatchTestComponent, TdChipsStackedTestComponent, + TdChipsBeforeAfterTestComponent, TdChipRemovalTestComponent, TdChipsEventsTestComponent, ], @@ -475,6 +476,35 @@ describe('Component: Chips', () => { }); + describe('position usage: ', () => { + let fixture: ComponentFixture; + let input: DebugElement; + let chips: DebugElement; + + beforeEach(() => { + fixture = TestBed.createComponent(TdChipsBeforeAfterTestComponent); + fixture.detectChanges(); + + chips = fixture.debugElement.query(By.directive(TdChipsComponent)); + }); + + it('should rendered input before the list of chips at all times', (done: DoneFn) => { + fixture.detectChanges(); + fixture.whenStable().then(() => { + + expect((chips.query(By.css('.td-chips-wrapper')).nativeElement).classList.contains('td-chips-input-before-position')) + .toBeFalsy(); + fixture.componentInstance.position = 'before'; + fixture.detectChanges(); + fixture.whenStable().then(() => { + expect((chips.query(By.css('.td-chips-wrapper')).nativeElement).classList.contains('td-chips-input-before-position')) + .toBeTruthy(); + done(); + }); + }); + }); + }); + describe('events: ', () => { let fixture: ComponentFixture; let chips: DebugElement; @@ -846,6 +876,26 @@ class TdChipsStackedTestComponent { selectedItems: string[] = this.items.slice(0, 3); } +@Component({ + template: ` + + `, +}) +class TdChipsBeforeAfterTestComponent { + position: string = 'after'; + stacked: boolean = false; + items: string[] = [ + 'steak', + 'pizza', + 'tacos', + 'sandwich', + 'chips', + 'pasta', + 'sushi', + ]; + selectedItems: string[] = this.items.slice(0, 3); +} + @Component({ template: `