File

src/tag/tag-filter.component.ts

Extends

Tag

Metadata

Index

Methods
Inputs
Outputs
HostBindings
Accessors

Inputs

closeButtonLabel
Type : string
Default value : "Clear Filter"
disabled
Type : boolean
Default value : false
title
Type : string
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

Outputs

click
Type : EventEmitter

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.

close
Type : EventEmitter

Function for close/delete the tag

HostBindings

attr.aria-label
Type : any
attr.class
Type : string
Inherited from Tag
Defined in Tag:70

Methods

onClick
onClick(event: any)
Parameters :
Name Type Optional
event any No
Returns : void
onClose
onClose(event: any)
Parameters :
Name Type Optional
event any No
Returns : void

Accessors

attrClass
getattrClass()

Remove cds--tag--${this.size} in v7

attrAriaLabel
getattrAriaLabel()
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();
	}
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""