Skip to content

Commit 7b17a3c

Browse files
committed
fix(tabs): addressing suggestions #5471
1 parent 7380eb6 commit 7b17a3c

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

projects/igniteui-angular/src/lib/tabs/tab-item.component.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export class IgxTabItemComponent extends IgxTabItemBase {
8080

8181
private _nativeTabItem: ElementRef;
8282
private _changesCount = 0; // changes and updates accordingly applied to the tab.
83+
private _isSelected = false;
8384
private _disabled = false;
8485

8586
constructor(private _tabs: IgxTabsBase, private _element: ElementRef) {
@@ -263,6 +264,14 @@ export class IgxTabItemComponent extends IgxTabItemBase {
263264
return -1;
264265
}
265266

267+
/**
268+
* @hidden
269+
*/
270+
public setSelectedInternal(newValue: boolean) {
271+
this._isSelected = newValue;
272+
this.tabindex = newValue ? 0 : -1;
273+
}
274+
266275
private onKeyDown(isLeftArrow: boolean, index = null): void {
267276
const tabsArray = this._tabs.tabs.toArray();
268277
if (index === null) {

projects/igniteui-angular/src/lib/tabs/tabs-group.component.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export class IgxTabsGroupComponent extends IgxTabsGroupBase implements AfterCont
7575
protected tabTemplate: IgxTabItemTemplateDirective;
7676

7777
private _tabTemplate: TemplateRef<any>;
78+
private _isSelected = false;
7879

7980
constructor(private _tabs: IgxTabsBase, private _element: ElementRef) {
8081
super();
@@ -161,12 +162,6 @@ export class IgxTabsGroupComponent extends IgxTabsGroupBase implements AfterCont
161162
public ngAfterViewChecked() {
162163
this._element.nativeElement.setAttribute('aria-labelledby', `igx-tab-item-${this.index}`);
163164
this._element.nativeElement.setAttribute('id', `igx-tabs__group-${this.index}`);
164-
165-
if (this.isSelected) {
166-
const tabItem = this.relatedTab.nativeTabItem.nativeElement;
167-
this._tabs.transformContentAnimation(this.relatedTab, 0);
168-
this._tabs.transformIndicatorAnimation(tabItem);
169-
}
170165
}
171166

172167
/**
@@ -179,12 +174,18 @@ export class IgxTabsGroupComponent extends IgxTabsGroupBase implements AfterCont
179174
* this.tab.select();
180175
*}
181176
*```
182-
* @param focusDelay A number representing the expected delay.
183177
*/
184178
public select(): void {
185179
if (!this.disabled && !this.isSelected) {
186180
this._tabs.performSelectionChange(this.relatedTab);
187181
}
188182
}
189183

184+
/**
185+
* @hidden
186+
*/
187+
public setSelectedInternal(newValue: boolean) {
188+
this._isSelected = newValue;
189+
}
190+
190191
}

projects/igniteui-angular/src/lib/tabs/tabs.common.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ export abstract class IgxTabsBase {
2323
/** @hidden */
2424
export abstract class IgxTabItemBase {
2525
nativeTabItem: ElementRef;
26-
_isSelected = false;
27-
tabindex;
28-
select(focusDelay?: number): void {}
2926
get index(): number { return 0; }
27+
select(): void {}
28+
setSelectedInternal(newValue: boolean) {}
3029
}
3130

3231
/** @hidden */
3332
export abstract class IgxTabsGroupBase {
34-
_isSelected = false;
35-
select(focusDelay?: number): void {}
33+
select(): void {}
34+
setSelectedInternal(newValue: boolean) {}
3635
}

projects/igniteui-angular/src/lib/tabs/tabs.component.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,31 +370,30 @@ export class IgxTabsComponent implements IgxTabsBase, AfterViewInit, OnDestroy {
370370
if (newTab) {
371371
this.performSelection(newTab);
372372
} else {
373-
// if there is no new selected tab hide the visibility indicator
373+
// if there is no new selected tab hide the selection indicator
374374
this.hideIndicator();
375375
}
376376
}
377377

378378
private performDeselection(oldTab: IgxTabItemBase): void {
379-
oldTab._isSelected = false;
379+
oldTab.setSelectedInternal(false);
380380
const oldTabRelatedGroup = this.groups.toArray()[oldTab.index];
381381
if (oldTabRelatedGroup) {
382-
oldTabRelatedGroup._isSelected = false;
382+
oldTabRelatedGroup.setSelectedInternal(false);
383383
}
384384
this._selectedIndex = -1;
385385
this.onTabItemDeselected.emit({ tab: oldTab, group: oldTabRelatedGroup });
386386
}
387387

388388
private performSelection(newTab: IgxTabItemBase): void {
389-
newTab._isSelected = true;
390-
newTab.tabindex = 0;
389+
newTab.setSelectedInternal(true);
391390
this._selectedIndex = newTab.index;
392391

393392
let newTabRelatedGroup = null;
394393
if (!this.hasContentTabs && this.groups) {
395394
newTabRelatedGroup = this.groups.toArray()[newTab.index];
396395
if (newTabRelatedGroup) {
397-
newTabRelatedGroup._isSelected = true;
396+
newTabRelatedGroup.setSelectedInternal(true);
398397
}
399398
}
400399

0 commit comments

Comments
 (0)