-
Notifications
You must be signed in to change notification settings - Fork 420
Angular Material: Translate Autocomplete Control Renderer #2535
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
base: master
Are you sure you want to change the base?
Angular Material: Translate Autocomplete Control Renderer #2535
Conversation
✅ Deploy Preview for jsonforms-examples ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Hi @daniel-shuy, You are right, the Angular Material renderer set is the most inconsistent one with the most missing features. Happy to review your contribution(s) ❤️ |
lucas-koehler
left a comment
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.
Hi @daniel-shuy Thanks for the contribution and extending the tests ❤️ . Allowing translation of the values defintely makes sense!
I have two comments inline. Pease have a look.
| displayFn(option: EnumOption): string { | ||
| return option.label; | ||
| } |
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 function signature suggests it always receives an EnumOption, but Angular Material's autocomplete will pass the raw value (string) when displaying the current selection in the input field.
| displayFn(option: EnumOption): string { | |
| return option.label; | |
| } | |
| displayFn(option: EnumOption | string): string { | |
| if (!option) { | |
| return ''; | |
| } | |
| return typeof option === 'string' ? option : option.label; | |
| } |
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.
Several expect(inputElement.value) assertions were removed from the tests. Was this intentional due to the displayFn changes affecting how values are displayed? If so, it would be helpful to add replacement assertions that verify the translated label is displayed correctly in the input field, rather than removing the coverage entirely.
Background
The company I work for (SICPA Product Security) is considering adopting JSON Forms for a project.
Unfortunately the project is written in Angular, and I noticed that the Angular Material renderer set is missing quite a lot of supported features compared to the React/Vue renderer sets.
As such, I have been testing the Angular Material renderer set quite thoroughly, and will be contributing some missing features, especially to the Angular Material renderer set.
Description
The Angular Material renderer set renders enums using the
AutocompleteControlRenderer.Unlike the other renderer sets,
AutocompleteControlRendererdoes not translate the enum values.This PR updates
AutocompleteControlRendererto usemapStateToEnumControlProps(JsonFormsState, OwnPropsOfControl & OwnPropsOfEnum)like the other renderer sets, which translates the enum values as labels, while keeping the original values as the values:jsonforms/packages/core/src/mappers/renderer.ts
Lines 676 to 707 in e642b3d
For backwards compatibility, I've allowed the
options@Input to still take instring[](by typing it asEnumOption[] | string[]), but it will not be translated if astring[]is passed.