src/tag/tag-filter.component.ts
selector | cds-tag-filter, ibm-tag-filter |
template |
|
Methods |
Inputs |
Outputs |
HostBindings |
Accessors |
closeButtonLabel | |
Type : string
|
|
Default value : "Clear Filter"
|
|
Defined in src/tag/tag-filter.component.ts:34
|
disabled | |
Type : boolean
|
|
Default value : false
|
|
Defined in src/tag/tag-filter.component.ts:35
|
title | |
Type : string
|
|
Defined in src/tag/tag-filter.component.ts:36
|
class | |
Type : string
|
|
Default value : ""
|
|
Inherited from
Tag
|
|
Defined in
Tag:54
|
size | |
Type : "sm" | "md" | "lg"
|
|
Default value : "md"
|
|
Inherited from
Tag
|
|
Defined in
Tag:52
|
|
Tag render size |
skeleton | |
Type : boolean
|
|
Default value : false
|
|
Inherited from
Tag
|
|
Defined in
Tag:56
|
type | |
Type : TagType
|
|
Default value : "gray"
|
|
Inherited from
Tag
|
|
Defined in
Tag:47
|
|
Type of the tag determines the styling |
click | |
Type : EventEmitter
|
|
Defined in src/tag/tag-filter.component.ts:51
|
|
We need to stop the immedate propagation of click on the close button to prevent undesired effects when used within dialogs. We need to emit a click event on close to allow for clicks to be listened
to on the immediate close button element. |
close | |
Type : EventEmitter
|
|
Defined in src/tag/tag-filter.component.ts:41
|
|
Function for close/delete the tag |
attr.aria-label |
Type : any
|
Defined in src/tag/tag-filter.component.ts:78
|
attr.class |
Type : string
|
Inherited from
Tag
|
Defined in
Tag:70
|
onClick | ||||||
onClick(event: any)
|
||||||
Defined in src/tag/tag-filter.component.ts:53
|
||||||
Parameters :
Returns :
void
|
onClose | ||||||
onClose(event: any)
|
||||||
Defined in src/tag/tag-filter.component.ts:60
|
||||||
Parameters :
Returns :
void
|
attrClass |
getattrClass()
|
Defined in src/tag/tag-filter.component.ts:70
|
Remove |
attrAriaLabel |
getattrAriaLabel()
|
Defined in src/tag/tag-filter.component.ts:78
|
import {
Component,
Output,
EventEmitter,
HostBinding,
Input,
TemplateRef
} from "@angular/core";
import { Tag } from "./tag.component";
@Component({
selector: "cds-tag-filter, ibm-tag-filter",
template: `
<ng-container *ngIf="!skeleton">
<ng-content select="[cdsTagIcon],[ibmTagIcon]"></ng-content>
<span
class="cds--tag__label"
[attr.title]="title ? title : null"
(click)="onClick($event)">
<ng-content></ng-content>
</span>
<button
class="cds--tag__close-icon"
(click)="onClose($event)"
[disabled]="disabled"
[title]="closeButtonLabel">
<span class="cds--visually-hidden">{{closeButtonLabel}}</span>
<svg cdsIcon="close" size="16"></svg>
</button>
</ng-container>
`
})
export class TagFilter extends Tag {
@Input() closeButtonLabel = "Clear Filter";
@Input() disabled = false;
@Input() title: string;
/**
* Function for close/delete the tag
*/
@Output() close = new EventEmitter<any>();
/**
* We need to stop the immedate propagation of click on the close button
* to prevent undesired effects when used within dialogs.
*
* We need to emit a click event on close to allow for clicks to be listened
* to on the immediate close button element. `action` distinguishes between clicks on
* the tag vs. clicks on the close button.
*/
@Output() click = new EventEmitter<{ action: "click" | "close" }>();
onClick(event: any) {
event.stopImmediatePropagation();
if (!this.disabled) {
this.click.emit({ action: "click" });
}
}
onClose(event: any) {
event.stopImmediatePropagation();
this.click.emit({ action: "close" });
this.close.emit();
}
/**
* @todo
* Remove `cds--tag--${this.size}` in v7
*/
@HostBinding("attr.class") get attrClass() {
const disabledClass = this.disabled ? "cds--tag--disabled" : "";
const sizeClass = `cds--tag--${this.size} cds--layout--size-${this.size}`;
const skeletonClass = this.skeleton ? "cds--skeleton" : "";
return `cds--tag cds--tag--filter cds--tag--${this.type} ${disabledClass} ${sizeClass} ${skeletonClass} ${this.class}`;
}
@HostBinding("attr.aria-label") get attrAriaLabel() {
return `${this.title || ""} ${this.closeButtonLabel}`.trim();
}
}