-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(selection-list): support for ngModel #7456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e918191
to
92d65d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM, a few nits.
} | ||
|
||
/** Returns the values of the selected options. */ | ||
private _getSelectedOptionValues(): string[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider inlining this since it's only used in one place and it's a one-liner?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd personally prefer keeping this as a function. It makes it the code more sorted with the _setOptionsFromValues
method.
src/lib/list/selection-list.ts
Outdated
|
||
values | ||
.map(value => this._getOptionFromValue(value)) | ||
.filter(option => !!option) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: if you want to be fancy, you can .filter(Boolean)
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea.
src/lib/list/selection-list.ts
Outdated
} | ||
|
||
/** Returns the option with the specified value. */ | ||
private _getOptionFromValue(value: string): MatListOption | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call this _getOptionByValue
? Also it's used only in one place so it could be inlined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds better. But I'd still like to keep it as a function. Otherwise it won't be that readable anymore.
src/lib/list/selection-list.ts
Outdated
} | ||
|
||
/** Implemented as part of ControlValueAccessor. */ | ||
registerOnTouched(fn: any): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fn
here and in registerOnChange
is a () => any
AFAIK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we can add types here.
src/lib/list/selection-list.spec.ts
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True
src/lib/list/selection-list.spec.ts
Outdated
.map(optionDebugEl => optionDebugEl.componentInstance); | ||
}); | ||
|
||
it('should update the model if an option got selected', fakeAsync(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, blocked on #7334.
src/lib/list/selection-list.spec.ts
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kara do you have any input on this?
b9654bd
to
6cae628
Compare
Rebased. Waiting for @kara's feedback before re-applying merge-ready. |
6cae628
to
a72026d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Running into some meatadata extractor issue with |
src/lib/list/selection-list.ts
Outdated
|
||
/** The FocusKeyManager which handles focus. */ | ||
_keyManager: FocusKeyManager<MatListOption>; | ||
|
||
/** The option components contained within this selection-list. */ | ||
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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