feat(radio-group): add compareWith property#28452
Conversation
Co-authored-by: Sean Perkins <sean-perkins@users.noreply.github.com>
liamdebeasi
left a comment
There was a problem hiding this comment.
Functionality looks great. My comments are focused around the tests.
core/src/components/radio-group/test/compare-with/radio-group.e2e.ts
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,37 @@ | |||
| type CompareFn = (currentValue: any, compareValue: any) => boolean; | |||
|
|
|||
| export const compareOptions = ( | |||
There was a problem hiding this comment.
Can we add a JSDoc for compareOptions too like we did for isOptionSelected?
liamdebeasi
left a comment
There was a problem hiding this comment.
One naming change, but otherwise looks good. Great job!
Co-authored-by: Liam DeBeasi <liamdebeasi@users.noreply.github.com>
|
@mapsandapps Don't forget to close #18943 too. GitHub doesn't autoclose linked issues when merging into the non-primary branch. |
|
@liamdebeasi thanks for the reminder! |
| if (typeof compareWith === 'function') { | ||
| return compareWith(currentValue, compareValue); | ||
| } else if (typeof compareWith === 'string') { | ||
| return currentValue[compareWith] === compareValue[compareWith]; |
There was a problem hiding this comment.
currentValue can be null with Angular forms, so this throws errors when using the property string variant :(. This is still an issue in the latest 8.6.4 version.
There was a problem hiding this comment.
While I was further using this component, I also see the issue that deselection doesn't work initially. This is because this custom compare isn't applied in the logic to see if a value should be deselected.
There was a problem hiding this comment.
@dietergeerts Can you file an issue and include a reproduction? The team doesn't typically monitor closed PRs.
There was a problem hiding this comment.
Created with reproduction: #30560
Issue number: resolves #18943
What is the current behavior?
Radio Group only allows for a strict equality check between the value and the options.
What is the new behavior?
compareWithwhich can be a function or string.compareWithis a string, the Radio Group will compare the value of that key.compareWithis a function, the Radio Group will use that function to determine the selected option.Does this introduce a breaking change?
Other information
Docs PR is incoming.