File

src/tabs/tab-header.directive.ts

Implements

AfterViewInit

Metadata

Index

Properties
Methods
Inputs
Outputs
HostBindings
HostListeners
Accessors

Constructor

constructor(host: ElementRef)
Parameters :
Name Type Optional
host ElementRef No

Inputs

active
Type : boolean
Default value : false

Indicates whether the Tab is active/selected. Determines whether it's TabPanel is rendered.

cacheActive
Type : boolean

Set to 'true' to have pane reference cached and not reloaded on tab switching.

disabled
Type : boolean
Default value : false

Indicates whether or not the Tab item is disabled.

paneReference
Type : Tab

Reference to the corresponsing tab pane.

paneTabIndex
Type : number | null
title
Type : any

Outputs

selected
Type : EventEmitter

Value 'selected' to be emitted after a new Tab is selected.

HostBindings

attr.aria-disabled
Type : boolean
Default value : this.disabled
attr.aria-selected
Type : boolean
Default value : this.active
attr.tabIndex
Type : 0 | -1
attr.type
Type : string
Default value : "button"
class.cds--tabs__nav-item
Type : boolean
Default value : true
class.cds--tabs__nav-item--disabled
Type : boolean
class.cds--tabs__nav-item--selected
Type : boolean
class.cds--tabs__nav-link
Type : boolean
Default value : true

HostListeners

click

Methods

focus
focus()
Returns : void
ngAfterViewInit
ngAfterViewInit()
Returns : void
onClick
onClick()
Decorators :
@HostListener('click')
Returns : void
selectTab
selectTab()
Returns : void

Properties

Protected _cacheActive
Default value : false
ariaDisabled
Default value : this.disabled
Decorators :
@HostBinding('attr.aria-disabled')
ariaSelected
Default value : this.active
Decorators :
@HostBinding('attr.aria-selected')
navItem
Default value : true
Decorators :
@HostBinding('class.cds--tabs__nav-item')
navLink
Default value : true
Decorators :
@HostBinding('class.cds--tabs__nav-link')
type
Type : string
Default value : "button"
Decorators :
@HostBinding('attr.type')

Accessors

tabIndex
gettabIndex()
isSelected
getisSelected()
isDisabled
getisDisabled()
cacheActive
getcacheActive()
setcacheActive(shouldCache: boolean)

Set to 'true' to have pane reference cached and not reloaded on tab switching.

Parameters :
Name Type Optional
shouldCache boolean No
Returns : void
paneTabIndex
setpaneTabIndex(tabIndex: number | null)
Parameters :
Name Type Optional
tabIndex number | null No
Returns : void
import {
	Directive,
	Input,
	ElementRef,
	EventEmitter,
	Output,
	AfterViewInit,
	HostBinding,
	HostListener
} from "@angular/core";

import { Tab } from "./tab.component";

@Directive({
	selector: "[cdsTabHeader], [ibmTabHeader]"
})
export class TabHeader implements AfterViewInit {
	@HostBinding("attr.tabIndex") get tabIndex() {
		return this.active ? 0 : -1;
	}

	@HostBinding("class.cds--tabs__nav-item--selected") get isSelected() {
		return this.active;
	}

	@HostBinding("class.cds--tabs__nav-item--disabled") get isDisabled() {
		return this.disabled;
	}
	/**
	 * Set to 'true' to have pane reference cached and not reloaded on tab switching.
	 */
	@Input() set cacheActive(shouldCache: boolean) {
		this._cacheActive = shouldCache;

		// Updates the pane references associated with the tab header when cache active is changed.
		if (this.paneReference) {
			this.paneReference.cacheActive = this.cacheActive;
		}
	}

	@Input() set paneTabIndex(tabIndex: number | null) {
		if (this.paneReference) {
			this.paneReference.tabIndex = tabIndex;
		}
	}

	get cacheActive() {
		return this._cacheActive;
	}
	/**
	 * Indicates whether the `Tab` is active/selected.
	 * Determines whether it's `TabPanel` is rendered.
	 */
	@Input() active = false;
	/**
	 * Indicates whether or not the `Tab` item is disabled.
	 */
	@Input() disabled = false;

	@HostBinding("attr.type") type = "button";
	@HostBinding("attr.aria-selected") ariaSelected = this.active;
	@HostBinding("attr.aria-disabled") ariaDisabled = this.disabled;
	@HostBinding("class.cds--tabs__nav-item") navItem = true;
	@HostBinding("class.cds--tabs__nav-link") navLink = true;

	/**
	 * Reference to the corresponsing tab pane.
	 */
	@Input() paneReference: Tab;
	@HostBinding("attr.title") @Input() title;

	/**
	 * Value 'selected' to be emitted after a new `Tab` is selected.
	 */

	@Output() selected = new EventEmitter<any>();

	protected _cacheActive = false;

	constructor(private host: ElementRef) {}

	@HostListener("click")
	onClick() {
		this.selectTab();
	}

	ngAfterViewInit() {
		setTimeout(() => {
			this.title = this.title ? this.title : this.host.nativeElement.textContent;
		});
	}

	selectTab() {
		this.focus();
		if (!this.disabled) {
			this.selected.emit();
			this.active = true;
			if (this.paneReference) {
				this.paneReference.active = true;
			}
		}
	}

	focus() {
		this.host.nativeElement.focus();
	}
}

results matching ""

    No results matching ""