src/tabs/base-tab-header.component.ts
There are two ways to create a tab, this class is a collection of features & metadata required by both.
Properties |
|
Methods |
Inputs |
HostBindings |
Accessors |
constructor(elementRef: ElementRef, changeDetectorRef: ChangeDetectorRef, eventService: EventService, renderer: Renderer2)
|
|||||||||||||||
Defined in src/tabs/base-tab-header.component.ts:84
|
|||||||||||||||
Parameters :
|
ariaLabel | |
Type : string
|
|
Defined in src/tabs/base-tab-header.component.ts:33
|
|
Sets the aria label on the nav element. |
ariaLabelledby | |
Type : string
|
|
Defined in src/tabs/base-tab-header.component.ts:37
|
|
Sets the aria labelledby on the nav element. |
cacheActive | |
Type : boolean
|
|
Default value : false
|
|
Defined in src/tabs/base-tab-header.component.ts:25
|
|
Set to 'true' to have |
contentAfter | |
Type : TemplateRef<any>
|
|
Defined in src/tabs/base-tab-header.component.ts:40
|
contentBefore | |
Type : TemplateRef<any>
|
|
Defined in src/tabs/base-tab-header.component.ts:39
|
followFocus | |
Type : boolean
|
|
Defined in src/tabs/base-tab-header.component.ts:29
|
|
Set to 'true' to have tabs automatically activated and have their content displayed when they receive focus. |
theme | |
Type : "dark" | "light"
|
|
Default value : "dark"
|
|
Defined in src/tabs/base-tab-header.component.ts:43
|
type | |
Type : "line" | "contained"
|
|
Default value : "line"
|
|
Defined in src/tabs/base-tab-header.component.ts:42
|
class.cds--tabs |
Type : boolean
|
Default value : true
|
Defined in src/tabs/base-tab-header.component.ts:45
|
class.cds--tabs--contained |
Type : boolean
|
Defined in src/tabs/base-tab-header.component.ts:46
|
class.cds--tabs--light |
Type : boolean
|
Defined in src/tabs/base-tab-header.component.ts:49
|
handleOverflowNavClick |
handleOverflowNavClick(direction: number, numOftabs: number)
|
Defined in src/tabs/base-tab-header.component.ts:97
|
Returns :
void
|
handleOverflowNavMouseDown | ||||||
handleOverflowNavMouseDown(direction: number)
|
||||||
Defined in src/tabs/base-tab-header.component.ts:109
|
||||||
Parameters :
Returns :
void
|
handleOverflowNavMouseUp |
handleOverflowNavMouseUp()
|
Defined in src/tabs/base-tab-header.component.ts:134
|
Clear intervals/Timeout & reset scroll behavior
Returns :
void
|
handleScroll |
handleScroll()
|
Defined in src/tabs/base-tab-header.component.ts:93
|
Returns :
void
|
Readonly clickMultiplier |
Type : number
|
Default value : 1.5
|
Defined in src/tabs/base-tab-header.component.ts:65
|
currentSelectedTab |
Type : number
|
Defined in src/tabs/base-tab-header.component.ts:61
|
Controls the manual focusing done by tabbing through headings. |
headerContainer |
Decorators :
@ViewChild('tabList', {static: true})
|
Defined in src/tabs/base-tab-header.component.ts:56
|
Gets the Unordered List element that holds the |
Protected longPressInterval |
Type : null
|
Default value : null
|
Defined in src/tabs/base-tab-header.component.ts:67
|
Readonly longPressMultiplier |
Type : number
|
Default value : 3
|
Defined in src/tabs/base-tab-header.component.ts:64
|
Readonly OVERFLOW_BUTTON_OFFSET |
Type : number
|
Default value : 44
|
Defined in src/tabs/base-tab-header.component.ts:63
|
tabsClass |
Default value : true
|
Decorators :
@HostBinding('class.cds--tabs')
|
Defined in src/tabs/base-tab-header.component.ts:45
|
Protected tickInterval |
Type : null
|
Default value : null
|
Defined in src/tabs/base-tab-header.component.ts:68
|
containedClass |
getcontainedClass()
|
Defined in src/tabs/base-tab-header.component.ts:46
|
themeClass |
getthemeClass()
|
Defined in src/tabs/base-tab-header.component.ts:49
|
hasHorizontalOverflow |
gethasHorizontalOverflow()
|
Defined in src/tabs/base-tab-header.component.ts:70
|
leftOverflowNavButtonHidden |
getleftOverflowNavButtonHidden()
|
Defined in src/tabs/base-tab-header.component.ts:75
|
rightOverflowNavButtonHidden |
getrightOverflowNavButtonHidden()
|
Defined in src/tabs/base-tab-header.component.ts:80
|
import {
Component,
Input,
ViewChild,
ElementRef,
TemplateRef,
ChangeDetectorRef,
HostBinding,
Renderer2
} from "@angular/core";
import { EventService } from "carbon-components-angular/utils";
/**
* There are two ways to create a tab, this class is a collection of features
* & metadata required by both.
*/
@Component({
template: ""
})
export class BaseTabHeader {
/**
* Set to 'true' to have `Tab` items cached and not reloaded on tab switching.
* Duplicate from `n-tabs` to support standalone headers
*/
@Input() cacheActive = false;
/**
* Set to 'true' to have tabs automatically activated and have their content displayed when they receive focus.
*/
@Input() followFocus: boolean;
/**
* Sets the aria label on the nav element.
*/
@Input() ariaLabel: string;
/**
* Sets the aria labelledby on the nav element.
*/
@Input() ariaLabelledby: string;
@Input() contentBefore: TemplateRef<any>;
@Input() contentAfter: TemplateRef<any>;
@Input() type: "line" | "contained" = "line";
@Input() theme: "dark" | "light" = "dark";
@HostBinding("class.cds--tabs") tabsClass = true;
@HostBinding("class.cds--tabs--contained") get containedClass() {
return this.type === "contained";
}
@HostBinding("class.cds--tabs--light") get themeClass() {
return this.theme === "light";
}
/**
* Gets the Unordered List element that holds the `Tab` headings from the view DOM.
*/
@ViewChild("tabList", { static: true }) headerContainer;
/**
* Controls the manual focusing done by tabbing through headings.
*/
currentSelectedTab: number;
// width of the overflow buttons
readonly OVERFLOW_BUTTON_OFFSET = 44;
readonly longPressMultiplier = 3;
readonly clickMultiplier = 1.5;
protected longPressInterval = null;
protected tickInterval = null;
get hasHorizontalOverflow() {
const tabList = this.headerContainer.nativeElement;
return tabList.scrollWidth > tabList.clientWidth;
}
get leftOverflowNavButtonHidden() {
const tabList = this.headerContainer.nativeElement;
return !this.hasHorizontalOverflow || !tabList.scrollLeft;
}
get rightOverflowNavButtonHidden() {
const tabList = this.headerContainer.nativeElement;
return !this.hasHorizontalOverflow ||
(tabList.scrollLeft + tabList.clientWidth) === tabList.scrollWidth;
}
constructor(
protected elementRef: ElementRef,
protected changeDetectorRef: ChangeDetectorRef,
protected eventService: EventService,
protected renderer: Renderer2
) { }
handleScroll() {
this.changeDetectorRef.markForCheck();
}
handleOverflowNavClick(direction: number, numOftabs = 0) {
const tabList = this.headerContainer.nativeElement;
const { clientWidth, scrollLeft, scrollWidth } = tabList;
if (direction > 0) {
tabList.scrollLeft = Math.min(scrollLeft + (scrollWidth / numOftabs) * this.clickMultiplier,
scrollWidth - clientWidth);
} else if (direction < 0) {
tabList.scrollLeft = Math.max(scrollLeft - (scrollWidth / numOftabs) * this.clickMultiplier, 0);
}
}
handleOverflowNavMouseDown(direction: number) {
const tabList = this.headerContainer.nativeElement;
this.longPressInterval = setTimeout(() => {
// Manually overriding scroll behvior to `auto` to make animation work correctly
this.renderer.setStyle(tabList, "scroll-behavior", "auto");
this.tickInterval = setInterval(() => {
tabList.scrollLeft += (direction * this.longPressMultiplier);
// clear interval if scroll reaches left or right edge
if (this.leftOverflowNavButtonHidden || this.rightOverflowNavButtonHidden) {
return () => {
clearInterval(this.tickInterval);
this.handleOverflowNavMouseUp();
};
}
});
return () => clearInterval(this.longPressInterval);
}, 500);
}
/**
* Clear intervals/Timeout & reset scroll behavior
*/
handleOverflowNavMouseUp() {
clearInterval(this.tickInterval);
clearTimeout(this.longPressInterval);
// Reset scroll behavior
this.renderer.setStyle(this.headerContainer.nativeElement, "scroll-behavior", "smooth");
}
}