Repository navigation
feat(selection-list): support for ngModel - #7456
Conversation
e918191 to
92d65d8
Compare
| } | ||
|
|
||
| /** Returns the values of the selected options. */ | ||
| private _getSelectedOptionValues(): string[] { |
There was a problem hiding this comment.
Consider inlining this since it's only used in one place and it's a one-liner?
There was a problem hiding this comment.
I'd personally prefer keeping this as a function. It makes it the code more sorted with the _setOptionsFromValues method.
|
|
||
| values | ||
| .map(value => this._getOptionFromValue(value)) | ||
| .filter(option => !!option) |
There was a problem hiding this comment.
Optional: if you want to be fancy, you can .filter(Boolean) here.
| } | ||
|
|
||
| /** Returns the option with the specified value. */ | ||
| private _getOptionFromValue(value: string): MatListOption | undefined { |
There was a problem hiding this comment.
Call this _getOptionByValue? Also it's used only in one place so it could be inlined.
There was a problem hiding this comment.
Sounds better. But I'd still like to keep it as a function. Otherwise it won't be that readable anymore.
| } | ||
|
|
||
| /** Implemented as part of ControlValueAccessor. */ | ||
| registerOnTouched(fn: any): void { |
There was a problem hiding this comment.
The fn here and in registerOnChange is a () => any AFAIK.
There was a problem hiding this comment.
Yeah we can add types here.
| fixture.componentInstance.formControl.setValue(['opt2', 'opt3']); | ||
| fixture.detectChanges(); | ||
|
|
||
| expect(listOptions[1].selected).toBe(true, 'Expected option to be selected.'); |
There was a problem hiding this comment.
The two Expected option to be selected. are super useful since they're right after each other. Consider changing them to something like Expected second option to be selected. and Expected third option to be selected.?
| .map(optionDebugEl => optionDebugEl.componentInstance); | ||
| }); | ||
|
|
||
| it('should update the model if an option got selected', fakeAsync(() => { |
There was a problem hiding this comment.
Switch the name here to "should update the model if an option got selected programmatically? Otherwise it's very close to should update the model if an option got clicked`.
| fixture.componentInstance.formControl.setValue(['opt2', 'opt3']); | ||
| fixture.detectChanges(); | ||
|
|
||
| expect(listOptions[1].selected).toBe(true, 'Expected first option to be selected.'); |
There was a problem hiding this comment.
These are wrong now. This is looking for the second option and the next one is looking for the third.
|
No longer blocked but needs a rebase. |
1cc3f87 to
b9654bd
Compare
| // available options. Also it can happen that the ControlValueAccessor has an initial value | ||
| // that should be used instead. Deferring the value change report to the next tick ensures | ||
| // that the form control value is not being overwritten. | ||
| Promise.resolve(() => this.selected && this.selectionList._reportValueChange()); |
b9654bd to
6cae628
Compare
|
Rebased. Waiting for @kara's feedback before re-applying merge-ready. |
6cae628 to
a72026d
Compare
|
Running into some meatadata extractor issue with |
| @ContentChildren(MatListOption) options: QueryList<MatListOption>; | ||
|
|
||
| /** Emits a change event whenever the selected state of an option changes. */ | ||
| @Output() change: EventEmitter<MatSelectionListChange> = |
There was a problem hiding this comment.
This actually needs to be selectionChange rather than change
Looks like it got inadvertently renamed in this PR.
There was a problem hiding this comment.
I intentionally named it change to be consistent with the other form elements supporting the ControlValueAccessor. I can switch it to selectionChange or also add a deprecated selectionChange output.
There was a problem hiding this comment.
Let's go with selectionChange since that's what the mat-select now uses
a72026d to
006d8ac
Compare
|
@josephperrott @jelbourn Renamed the Also re-added the Please have another look. |
|
Setting back to merge-ready. @tinayuangao if this fails on presubmit, can you help @devversion resolve any issues so that this can land for RC3? |
* Adds support for NgModel to the selection-list. Fixes angular#6896
006d8ac to
ce51421
Compare
|
demo app/docs need to be updated to show usage of ngModel with selection-list |
|
is there any update for the documentation planed? |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fixes #6896