Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit e4b11fb

Browse files
authored
feat(chips): Add choice property to mdc-chip-set (#744)
Choice chips are a variant of chips that allow single selection from a set of chip options. Closes #743
1 parent 5cb8127 commit e4b11fb

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/demo-app/components/chips-demo/chips-demo.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ <h3>Chips</h3>
102102
</mdc-chip-set>
103103
</div>
104104
</div>
105+
<div class="demo-content">
106+
<h3>Choice Chips</h3>
107+
<div class="demo-content--row">
108+
<mdc-chip-set [choice]="true">
109+
<mdc-chip>
110+
<mdc-chip-text>Get Directions</mdc-chip-text>
111+
</mdc-chip>
112+
<mdc-chip>
113+
<mdc-chip-text>Get Weather</mdc-chip-text>
114+
</mdc-chip>
115+
<mdc-chip>
116+
<mdc-chip-text>Add to Calendar</mdc-chip-text>
117+
</mdc-chip>
118+
</mdc-chip-set>
119+
</div>
120+
</div>
105121
<div class="demo-content">
106122
<h3>Entry Chips</h3>
107123
<div class="demo-content--row">

src/lib/chips/chip-set.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ElementRef,
77
EventEmitter,
88
HostBinding,
9+
Input,
910
OnDestroy,
1011
OnInit,
1112
QueryList,
@@ -15,6 +16,8 @@ import {
1516
import { Subscription } from 'rxjs/Subscription';
1617
import { startWith } from 'rxjs/operators/startWith';
1718

19+
import { toBoolean, EventRegistry } from '@angular-mdc/web/common';
20+
1821
import { MdcChip } from './chip';
1922
import { MDCChipSetAdapter } from '@material/chips/chip-set/adapter';
2023
import { MDCChipSetFoundation } from '@material/chips';
@@ -36,9 +39,23 @@ export class MdcChipSetChange {
3639
encapsulation: ViewEncapsulation.None,
3740
changeDetection: ChangeDetectionStrategy.OnPush,
3841
preserveWhitespaces: false,
42+
providers: [EventRegistry]
3943
})
4044
export class MdcChipSet implements AfterContentInit, OnInit, OnDestroy {
45+
/**
46+
* Indicates that the chips in the set are choice chips, which allow a single selection from a set of options.
47+
*/
48+
@Input()
49+
get choice(): boolean { return this._choice; }
50+
set choice(value: boolean) {
51+
this._choice = toBoolean(value);
52+
}
53+
protected _choice: boolean = false;
54+
4155
@HostBinding('class.mdc-chip-set') isHostClass = true;
56+
@HostBinding('class.mdc-chip-set--choice') get classChoice(): string {
57+
return this._choice ? 'mdc-chip-set--choice' : '';
58+
}
4259
@ContentChildren(MdcChip) chips: QueryList<MdcChip>;
4360

4461
/** Subscription to changes in the chip list. */
@@ -48,6 +65,10 @@ export class MdcChipSet implements AfterContentInit, OnInit, OnDestroy {
4865
hasClass: (className: string) => {
4966
return this._getHostElement().classList.contains(className);
5067
},
68+
registerInteractionHandler: (evtType: string, handler: EventListener) =>
69+
this._registry.listen(evtType, handler, this._getHostElement()),
70+
deregisterInteractionHandler: (evtType: string, handler: EventListener) =>
71+
this._registry.unlisten(evtType, handler),
5172
};
5273

5374
private _foundation: {
@@ -57,7 +78,8 @@ export class MdcChipSet implements AfterContentInit, OnInit, OnDestroy {
5778

5879
constructor(
5980
private _renderer: Renderer2,
60-
public elementRef: ElementRef) { }
81+
public elementRef: ElementRef,
82+
private _registry: EventRegistry) { }
6183

6284
ngAfterContentInit(): void {
6385
// When the list changes, re-subscribe

0 commit comments

Comments
 (0)