-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(material/button-toggle): improve signal forms support #31964
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: main
Are you sure you want to change the base?
Conversation
Adds support for using the `name` from signal formsm and adds tests to verify state synchronization via the `[control]` directive
get name(): string { | ||
return this._name; | ||
// When using signal forms, prefer the signal forms name. | ||
return this._signalFormsControl?.state().name() ?? this._name; |
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.
Users could just manually do this right?
<mat-button-toggle-group [control]="field" [name]="field().name()">
Is this just about the convenience? Are we not going to have to repeat this for every custom control using ControlValueAccessor
?
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, in order for Angular Material to be able to support the full control directive magic for inputs beyond the ones supported in CVA, they would either need to migrate to signal based inputs so they can support the FormUiControl
interface (this is difficult for libraries that have a lot of users), or they need to manually integrate with the additional properties they care about using this pattern.
This PR is intended as an example for the kind of changes we would probably make across the library, and we can discuss how worth it or not that is before going ahead with it
get name(): string { | ||
return this._name; | ||
// When using signal forms, prefer the signal forms name. | ||
return this._signalFormsControl?.state().name() ?? this._name; |
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 think [name] should take precedence, and only use signalFormsName if it's not set?
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.
Once the Control
directive is properly type checked it shouldn't even be possible to set [control]
and [name]
inputs at the same time
private _selectionModel: SelectionModel<MatButtonToggle>; | ||
|
||
private _cachedSignalFormsControl: Control<unknown> | null; | ||
private get _signalFormsControl() { |
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.
should we create an injectFormControl helper for a more fluent API?
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.
There's no existing precedent for that, that I know of... so I would say probably no
Adds support for using the
name
from signal forms and adds tests to verify state synchronization via the[control]
directive