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

Commit e686dac

Browse files
committed
feat(checkbox): Provision host + input id if not user defined
1 parent 41af1ad commit e686dac

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/lib/checkbox/checkbox.component.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { MdcRipple } from '../ripple/ripple.directive';
2121
import { MDCCheckboxAdapter } from './checkbox-adapter';
2222
import { MDCCheckboxFoundation } from '@material/checkbox';
2323

24-
let nextElId_ = 0;
24+
let nextUniqueId = 0;
2525

2626
export const MD_CHECKBOX_CONTROL_VALUE_ACCESSOR: Provider = {
2727
provide: NG_VALUE_ACCESSOR,
@@ -31,6 +31,9 @@ export const MD_CHECKBOX_CONTROL_VALUE_ACCESSOR: Provider = {
3131

3232
@Component({
3333
selector: 'mdc-checkbox',
34+
host: {
35+
'[id]': 'id',
36+
},
3437
template:
3538
`
3639
<input type="checkbox"
@@ -65,11 +68,11 @@ export const MD_CHECKBOX_CONTROL_VALUE_ACCESSOR: Provider = {
6568
})
6669

6770
export class MdcCheckboxComponent implements AfterViewInit, OnDestroy {
68-
@Input() id: string = `mdc-checkbox-${++nextElId_}`;
69-
@Input() name: string;
70-
get inputId(): string {
71-
return `input-${this.id}`;
72-
}
71+
private _uniqueId: string = `mdc-checkbox-${++nextUniqueId}`;
72+
73+
@Input() id: string = this._uniqueId;
74+
get inputId(): string { return `${this.id || this._uniqueId}-input`; }
75+
@Input() name: string | null = null;
7376
@Input()
7477
get checked() { return this._foundation.isChecked(); }
7578
set checked(value) {

0 commit comments

Comments
 (0)