src/tiles/selection-tile.component.ts
AfterViewInit
selector | cds-selection-tile, ibm-selection-tile |
template |
|
Properties |
Methods |
Inputs |
Outputs |
HostListeners |
Accessors |
constructor(i18n: I18n)
|
||||||
Defined in src/tiles/selection-tile.component.ts:109
|
||||||
Parameters :
|
disabled | |
Type : boolean
|
|
Default value : false
|
|
Defined in src/tiles/selection-tile.component.ts:92
|
|
Set to |
id | |
Type : string
|
|
Default value : `tile-${SelectionTile.tileCount}`
|
|
Defined in src/tiles/selection-tile.component.ts:62
|
|
The unique id for the input. |
selected | |
Type : boolean
|
|
Defined in src/tiles/selection-tile.component.ts:68
|
|
Updating the state of the input to match the state of the parameter passed in.
Set to |
theme | |
Type : "light" | "dark"
|
|
Default value : "dark"
|
|
Defined in src/tiles/selection-tile.component.ts:57
|
value | |
Type : string
|
|
Defined in src/tiles/selection-tile.component.ts:83
|
|
The value for the tile. Returned via |
change | |
Type : EventEmitter<Event>
|
|
Defined in src/tiles/selection-tile.component.ts:87
|
|
Internal event used to notify the containing |
keydown |
Arguments : '$event'
|
keydown(event)
|
Defined in src/tiles/selection-tile.component.ts:124
|
keyboardInput | ||||
keyboardInput(event)
|
||||
Decorators :
@HostListener('keydown', ['$event'])
|
||||
Defined in src/tiles/selection-tile.component.ts:124
|
||||
Parameters :
Returns :
void
|
ngAfterViewInit |
ngAfterViewInit()
|
Defined in src/tiles/selection-tile.component.ts:115
|
Returns :
void
|
onChange | ||||
onChange(event)
|
||||
Defined in src/tiles/selection-tile.component.ts:131
|
||||
Parameters :
Returns :
void
|
Protected _selected |
Type : null
|
Default value : null
|
Defined in src/tiles/selection-tile.component.ts:109
|
Public i18n |
Type : I18n
|
Defined in src/tiles/selection-tile.component.ts:111
|
input |
Decorators :
@ViewChild('input', {static: true})
|
Defined in src/tiles/selection-tile.component.ts:105
|
multiple |
Default value : true
|
Defined in src/tiles/selection-tile.component.ts:102
|
Defines whether or not the |
name |
Type : string
|
Default value : "tile-group-unbound"
|
Defined in src/tiles/selection-tile.component.ts:97
|
Set by the containing |
Static tileCount |
Type : number
|
Default value : 0
|
Defined in src/tiles/selection-tile.component.ts:51
|
selected | ||||||
getselected()
|
||||||
Defined in src/tiles/selection-tile.component.ts:77
|
||||||
setselected(value: boolean)
|
||||||
Defined in src/tiles/selection-tile.component.ts:68
|
||||||
Updating the state of the input to match the state of the parameter passed in.
Set to
Parameters :
Returns :
void
|
import {
Component,
Input,
Output,
EventEmitter,
ViewChild,
HostListener,
AfterViewInit
} from "@angular/core";
import { I18n } from "carbon-components-angular/i18n";
@Component({
selector: "cds-selection-tile, ibm-selection-tile",
template: `
<input
#input
[attr.tabindex]="disabled ? null : 0"
class="cds--tile-input"
[id]="id"
[disabled]="disabled"
[type]="(multiple ? 'checkbox': 'radio')"
[value]="value"
[name]="name"
(change)="onChange($event)"/>
<label
class="cds--tile cds--tile--selectable"
[for]="id"
[ngClass]="{
'cds--tile--is-selected' : selected,
'cds--tile--light': theme === 'light',
'cds--tile--disabled' : disabled
}"
[attr.aria-label]="i18n.get('TILES.TILE') | async">
<div class="cds--tile__checkmark"
[class.cds--tile__checkmark--persistent]="multiple">
<svg *ngIf="!selected; else selectedIcon"
[cdsIcon]="multiple ? 'checkbox' : 'checkmark'"
size="16">
</svg>
<ng-template #selectedIcon>
<svg [cdsIcon]="multiple ? 'checkbox--checked--filled' : 'checkmark--filled'" size="16"></svg>
</ng-template>
</div>
<div class="cds--tile-content">
<ng-content></ng-content>
</div>
</label>
`
})
export class SelectionTile implements AfterViewInit {
static tileCount = 0;
/**
* @deprecated since v5 - Use `cdsLayer` directive instead
* Set to `"light"` to apply the light style
*/
@Input() theme: "light" | "dark" = "dark";
/**
* The unique id for the input.
*/
@Input() id = `tile-${SelectionTile.tileCount}`;
/**
* Updating the state of the input to match the state of the parameter passed in.
* Set to `true` if this tile should be selected.
*/
@Input() set selected(value: boolean) {
// If an initial selected value is set before input exists, we save
// the value and check again when input exists in `AfterViewInit`.
this._selected = value ? true : null;
if (this.input) {
this.input.nativeElement.checked = this._selected;
}
}
get selected() {
return this.input ? this.input.nativeElement.checked : false;
}
/**
* The value for the tile. Returned via `ngModel` or `selected` event on the containing `TileGroup`.
*/
@Input() value: string;
/**
* Internal event used to notify the containing `TileGroup` of changes.
*/
@Output() change: EventEmitter<Event> = new EventEmitter();
/**
* Set to `true` to disable the selection tile.
*/
@Input() disabled = false;
/**
* Set by the containing `TileGroup`. Used for the `name` property on the input.
*/
name = "tile-group-unbound";
/**
* Defines whether or not the `SelectionTile` supports selecting multiple tiles as opposed to single
* tile selection.
*/
multiple = true; // Set to true because of the way tile group sets it up.
// If it is first undefined then set to true, the type will change from radio to checkbox and deselects the inputs.
@ViewChild("input", { static: true }) input;
// If an initial selected value is set before input exists, we save
// the value and check again when input exists in `AfterViewInit`.
protected _selected = null;
constructor(public i18n: I18n) {
SelectionTile.tileCount++;
}
ngAfterViewInit() {
if (this.input) {
setTimeout(() => {
this.input.nativeElement.checked = this._selected;
});
}
}
@HostListener("keydown", ["$event"])
keyboardInput(event) {
if (event.key === "Enter" || event.key === "Spacebar" || event.key === " ") {
this.selected = !this.selected;
this.change.emit(event);
}
}
onChange(event) {
this.change.emit(event);
}
}