Skip to content

Commit 457739a

Browse files
authored
Merge branch 'master' into jberes-patch-1
2 parents ab23574 + 8873826 commit 457739a

File tree

4 files changed

+86
-14
lines changed

4 files changed

+86
-14
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,13 @@ All notable changes for each version of this project will be documented in this
154154
- Added functionality for displaying various content into the toast component. It also allows users to access toast styles through its host element.
155155

156156
- `IgxDrag`
157-
- New `igxDragIgnore` directive that allows children of the `igxDrag` element to be interactable and receive mouse events. Dragging cannot be performed from those elements that are ignored.
158-
- New `dragDirection` input that can specify only one direction of dragging or both.
157+
- Added `igxDragIgnore` directive that allows children of the `igxDrag` element to be interactable and receive mouse events. Dragging cannot be performed from those elements that are ignored.
158+
- Added `dragDirection` input that can specify only one direction of dragging or both.
159+
160+
- `IgxChip`
161+
- Added support for tabIndex attribute applied to the main chip element.
162+
- Added `tabIndex` input so it can support change detection as well.
163+
159164

160165
### RTL Support
161166
- `igxSlider` have full right-to-left (RTL) support.

projects/igniteui-angular/src/lib/chips/chip.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div #chipArea class="igx-chip__item"
2-
[attr.tabindex]="chipTabindex"
2+
[attr.tabIndex]="tabIndex"
33
(keydown)="onChipKeyDown($event)"
44
[igxDrag]="{chip: this}"
55
[style.visibility]='hideBaseElement ? "hidden" : "visible"'
@@ -27,7 +27,7 @@
2727
<ng-content select="igx-suffix,[igxSuffix]"></ng-content>
2828

2929
<div class="igx-chip__remove" *ngIf="removable"
30-
tabindex="0"
30+
[attr.tabIndex]="tabIndex"
3131
(keydown)="onRemoveBtnKeyDown($event)"
3232
(pointerdown)="onRemoveMouseDown($event)"
3333
(mousedown)="onRemoveMouseDown($event)"

projects/igniteui-angular/src/lib/chips/chip.component.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ export class IgxChipComponent extends DisplayDensityBase {
9090
@Input()
9191
public id = `igx-chip-${CHIP_ID++}`;
9292

93+
/**
94+
* An @Input property that sets the value of `tabindex` attribute. If not provided it will use the element's tabindex if set.
95+
* @example
96+
* ```html
97+
* <igx-chip [id]="'igx-chip-1'" [tabIndex]="1"></igx-chip>
98+
* ```
99+
*/
100+
@Input()
101+
public set tabIndex(value: number) {
102+
this._tabIndex = value;
103+
}
104+
105+
public get tabIndex() {
106+
if (this._tabIndex !== null) {
107+
return this._tabIndex;
108+
}
109+
return !this.disabled ? 0 : null;
110+
}
111+
93112
/**
94113
* An @Input property that stores data related to the chip.
95114
* @example
@@ -353,6 +372,13 @@ export class IgxChipComponent extends DisplayDensityBase {
353372
@Output()
354373
public onDragEnter = new EventEmitter<IChipEnterDragAreaEventArgs>();
355374

375+
/**
376+
* @hidden
377+
* @internal
378+
*/
379+
@HostBinding('attr.tabIndex')
380+
public hostTabIndex = null;
381+
356382
/**
357383
* @hidden
358384
* @internal
@@ -433,16 +459,13 @@ export class IgxChipComponent extends DisplayDensityBase {
433459
return this.getComponentDensityClass('igx-chip__ghost');
434460
}
435461

436-
public get chipTabindex() {
437-
return !this.disabled ? 0 : '';
438-
}
439-
440462
/**
441463
* @hidden
442464
* @internal
443465
*/
444466
public hideBaseElement = false;
445467

468+
protected _tabIndex = null;
446469
protected _selected = false;
447470
protected _selectedItemClass = 'igx-chip__item--selected';
448471
protected _movedWhileRemoving = false;

projects/igniteui-angular/src/lib/chips/chip.spec.ts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ import { ControlsFunction } from '../test-utils/controls-functions.spec';
2727
<span #label [class]="'igx-chip__text'">{{chip.text}}</span>
2828
<igx-icon igxPrefix fontSet="material">drag_indicator</igx-icon>
2929
</igx-chip>
30+
<igx-chip #chipElem tabIndex="1" [id]="tabChipAttr">
31+
<span #label [class]="'igx-chip__text'">Tab Chip</span>
32+
</igx-chip>
33+
<igx-chip #chipElem tabIndex="2" [disabled]="true" [id]="tabChipDisabled">
34+
<span #label [class]="'igx-chip__text'">Tab Chip</span>
35+
</igx-chip>
36+
<igx-chip #chipElem [tabIndex]="3" [removable]="true" [id]="tabChipInput" >
37+
<span #label [class]="'igx-chip__text'">Tab Chip</span>
38+
</igx-chip>
39+
<igx-chip #chipElem tabIndex="4" [tabIndex]="1" [id]="tabChipBoth">
40+
<span #label [class]="'igx-chip__text'">Tab Chip</span>
41+
</igx-chip>
42+
<igx-chip #chipElem tabIndex="5" [tabIndex]="1" [disabled]="true" [id]="tabChipAll">
43+
<span #label [class]="'igx-chip__text'">Tab Chip</span>
44+
</igx-chip>
3045
</igx-chips-area>
3146
`
3247
})
@@ -114,7 +129,7 @@ describe('IgxChip', () => {
114129

115130
it('should render chip area and chips inside it', () => {
116131
expect(chipArea.length).toEqual(1);
117-
expect(chipArea[0].nativeElement.children.length).toEqual(4);
132+
expect(chipArea[0].nativeElement.children.length).toEqual(9);
118133
expect(chipArea[0].nativeElement.children[0].tagName).toEqual('IGX-CHIP');
119134
});
120135

@@ -169,7 +184,7 @@ describe('IgxChip', () => {
169184
// Assert default css class is applied
170185
const comfortableComponents = fix.debugElement.queryAll(By.css(CHIP_CLASS));
171186

172-
expect(comfortableComponents.length).toEqual(2);
187+
expect(comfortableComponents.length).toEqual(7);
173188
expect(comfortableComponents[0].nativeElement).toBe(firstComponent.nativeElement);
174189
expect(comfortableComponents[1].nativeElement).toBe(secondComponent.nativeElement);
175190
});
@@ -212,6 +227,35 @@ describe('IgxChip', () => {
212227
expect(chipAreaElem.nativeElement.style.backgroundColor).toEqual(chipColor);
213228
expect(firstComponent.componentInstance.color).toEqual(chipColor);
214229
});
230+
231+
it('should apply correct tabIndex to the chip area only when tabIndex is set as property of the chip and chip is disabled', () => {
232+
const firstTabChip = fix.debugElement.queryAll(By.directive(IgxChipComponent))[4];
233+
expect(firstTabChip.nativeElement.getAttribute('tabindex')).toBeFalsy();
234+
expect(firstTabChip.componentInstance.chipArea.nativeElement.getAttribute('tabindex')).toEqual('1');
235+
236+
// Chip is disabled, but attribute tabindex has bigger priority.
237+
const secondTabChip = fix.debugElement.queryAll(By.directive(IgxChipComponent))[5];
238+
expect(secondTabChip.nativeElement.getAttribute('tabindex')).toBeFalsy();
239+
expect(secondTabChip.componentInstance.chipArea.nativeElement.getAttribute('tabindex')).toEqual('2');
240+
});
241+
242+
it('should apply correct tab indexes when tabIndex and removeTabIndex are set as inputs', () => {
243+
const thirdTabChip = fix.debugElement.queryAll(By.directive(IgxChipComponent))[6];
244+
const deleteBtn = ControlsFunction.getChipRemoveButton(thirdTabChip.componentInstance.chipArea.nativeElement);
245+
expect(thirdTabChip.nativeElement.getAttribute('tabindex')).toBeFalsy();
246+
expect(thirdTabChip.componentInstance.chipArea.nativeElement.getAttribute('tabindex')).toEqual('3');
247+
expect(deleteBtn.getAttribute('tabindex')).toEqual('3');
248+
249+
// tabIndex attribute has higher priority than tabIndex.
250+
const fourthTabChip = fix.debugElement.queryAll(By.directive(IgxChipComponent))[7];
251+
expect(fourthTabChip.nativeElement.getAttribute('tabindex')).toBeFalsy();
252+
expect(fourthTabChip.componentInstance.chipArea.nativeElement.getAttribute('tabindex')).toEqual('1');
253+
254+
// tabIndex attribute has higher priority than tabIndex input and chip being disabled.
255+
const fifthTabChip = fix.debugElement.queryAll(By.directive(IgxChipComponent))[8];
256+
expect(fifthTabChip.nativeElement.getAttribute('tabindex')).toBeFalsy();
257+
expect(fifthTabChip.componentInstance.chipArea.nativeElement.getAttribute('tabindex')).toEqual('1');
258+
});
215259
});
216260

217261
describe('Interactions Tests: ', () => {
@@ -241,30 +285,30 @@ describe('IgxChip', () => {
241285
});
242286

243287
it('should delete chip when space button is pressed on delete button', () => {
244-
HelperTestFunctions.verifyChipsCount(fix, 4);
288+
HelperTestFunctions.verifyChipsCount(fix, 9);
245289
const chipElems = fix.debugElement.queryAll(By.directive(IgxChipComponent));
246290
const deleteButtonElement = ControlsFunction.getChipRemoveButton(chipElems[1].nativeElement);
247291
// Removes chip with id City, because country chip is unremovable
248292
UIInteractions.triggerKeyDownEvtUponElem(' ', deleteButtonElement, true);
249293
fix.detectChanges();
250294

251-
HelperTestFunctions.verifyChipsCount(fix, 3);
295+
HelperTestFunctions.verifyChipsCount(fix, 8);
252296

253297
const chipComponentsIds = fix.componentInstance.chipList.map(c => c.id);
254298
expect(chipComponentsIds.length).toEqual(3);
255299
expect(chipComponentsIds).not.toContain('City');
256300
});
257301

258302
it('should delete chip when enter button is pressed on delete button', () => {
259-
HelperTestFunctions.verifyChipsCount(fix, 4);
303+
HelperTestFunctions.verifyChipsCount(fix, 9);
260304

261305
const chipElems = fix.debugElement.queryAll(By.directive(IgxChipComponent));
262306
const deleteButtonElement = ControlsFunction.getChipRemoveButton(chipElems[1].nativeElement);
263307
// Removes chip with id City, because country chip is unremovable
264308
UIInteractions.triggerKeyDownEvtUponElem('Enter', deleteButtonElement, true);
265309
fix.detectChanges();
266310

267-
HelperTestFunctions.verifyChipsCount(fix, 3);
311+
HelperTestFunctions.verifyChipsCount(fix, 8);
268312

269313
const chipComponentsIds = fix.componentInstance.chipList.map(c => c.id);
270314
expect(chipComponentsIds.length).toEqual(3);

0 commit comments

Comments
 (0)