-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat: add coercion for string arrays #17523
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
@JanMalch are there any places in Angular Material or CDK where we could use this function? |
Sorry for the late response @jelbourn. It can be used for the autocomplete's |
I think it would be good to do all of those in one PR (with separate commits), since it would validate the usefulness of the function. |
Changes the default separator for coerceStringArray to a single space, to be better suited for the common usages like CSS class inputs. Improve documentation to better describe behaviour and use cases.
With coerceStringArray no empty string key will be added to the classList object. The input can also accept string[] now.
Quick question on the Based on the <mat-datepicker [panelClass]="'first second'">...</mat-datepicker>
<mat-datepicker [panelClass]="['first', 'second']">...</mat-datepicker>
<!-- should the following two work? -->
<mat-datepicker [panelClass]="{'first': true, 'second': true, 'third': false}">...</mat-datepicker>
<mat-datepicker [panelClass]="{'class1 class2 class3' : true}">...</mat-datepicker> |
Seems like a mistake in that comment; it should probably say something like "Supports string and string array values, similar to |
The autocomplete shows a good usage. |
The function now only requires one loop over the array instead of two. Improve documentation by adding parameter description and behaviour for special cases. Minor style improvements.
Add tests for panelClass to check coercion and adding it onto the target element. Fixes minor style issue in datepicker source.
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.
Overall looks good, just a few last comments
Also improves the documentation for coerceStringArray by adding more examples and clarifying its behaviour. Removes an unnecessary !! to check for an empty string.
Applied all proposed changes. |
We generally try to keep commits on master to the changelog level, so this whole PR would just be one. Looks like a few CI tasks are failing on this presently |
All CI tasks pass now. Sorry about the delayed and clumsy commits. |
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
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. |
Adds a utility function to coerce string arrays. This has been very useful for CSS class lists or defining columns for a CDK table.
Handling of
null
andundefined
(and objects) may be up for discussion. Currently they are mapped via string interpolation and not filtered.(If this is not just a "small" feature, I'm happy to open up a new issue.)