Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nimble Angular extends the Angular public API #732

Closed
TrevorKarjanis opened this issue Sep 12, 2022 · 7 comments 路 Fixed by #1655
Closed

Nimble Angular extends the Angular public API #732

TrevorKarjanis opened this issue Sep 12, 2022 · 7 comments 路 Fixed by #1655
Assignees

Comments

@TrevorKarjanis
Copy link
Contributor

TrevorKarjanis commented Sep 12, 2022

馃悰 Bug Report

NimbleSelectControlValueAccessorDirective and NimbleSelectListOptionDirective extend classes from @angular/forms.

Update:
There seem to be many more cases where we extend Angular classes that do not seem to be explicitly marked as extendable/non-final. This is not a comprehensive list:

  • NimbleNumberFieldControlValueAccessorDirective extends NumberValueAccessor, whose API doc does not explicitly say it is not final/can be extended.
  • NimbleRadioControlValueAccessorDirective extends RadioControlValueAccessor, whose API doc does not explicitly say it is not final/can be extended.
  • NimbleToggleButtonControlValueAccessorDirective and NimbleSwitchControlValueAccessorDirective extend CheckboxControlValueAccessor, whose API doc does not explicitly say it is not final/can be extended.
  • NimbleTextFieldControlValueAccessorDirective and NimbleTextAreaControlValueAccessorDirective extend DefaultValueAccessor, whose API doc does not explicitly say it is not final/can be extended.

This is not supported unless explicitly documented.

We explicitly don't consider the following to be our public API surface:

  • constructors of injectable classes (services and directives) - please use DI to obtain instances of these classes
  • extending any of our classes unless the support for this is specifically documented in the API docs

All classes in Angular's public API are final (they should not be extended) unless explicitly stated in the API documentation.
Extending such final classes is not supported, since protected members and internal implementation may change outside of major releases.

馃捇 Repro or Code Sample

See NimbleSelectControlValueAccessorDirective and NimbleSelectListOptionDirective.

馃 Expected Behavior

N/A

馃槸 Current Behavior

N/A

馃拋 Possible Solution

This is just a warning that extending the public API can lead to breakages and isn't recommended. If they are documented as supporting such, this can be closed. My search was not extensive. An alternative might be to use composition. Except for the constructor, NimbleSelectListOptionDirective is probably not a high risk. However, NimbleSelectControlValueAccessorDirective appears to depend on undocumented API.

馃敠 Context

This was investigated as a possible cause to #729. It was not.

馃實 Your Environment

  • Version: @ni/nimble-angular@8.4.10
@TrevorKarjanis TrevorKarjanis added bug Something isn't working triage New issue that needs to be reviewed labels Sep 12, 2022
@TrevorKarjanis TrevorKarjanis changed the title Nimble Angular extends Angular public API Nimble Angular extends the Angular public API Sep 12, 2022
@m-akinc m-akinc removed the triage New issue that needs to be reviewed label Sep 13, 2022
@jattasNI
Copy link
Contributor

One step we could take to move this forward would be to open an issue / discussion / feature request on the Angular repo to explain our use case and request that the classes we extend be added to the public API. Even if it doesn't get prioritized immediately it would be good to have our use cases on their radar.

@TrevorKarjanis
Copy link
Contributor Author

One step we could take to move this forward would be to open an issue / discussion / feature request on the Angular repo to explain our use case and request that the classes we extend be added to the public API. Even if it doesn't get prioritized immediately it would be good to have our use cases on their radar.

Another potential option coming in v14 is utilizing hostDirectives. The idea being, apply an Angular accessor directive with a nimble directive.

@m-akinc
Copy link
Contributor

m-akinc commented Sep 18, 2023

Another potential option coming in v14 is utilizing hostDirectives.

Unfortunately, it looks like that was only added in v15.

@jattasNI
Copy link
Contributor

@m-akinc if that feature would solve our issue then could we switch to that approach when we fix #1079 (hopefully this cycle)?

@m-akinc
Copy link
Contributor

m-akinc commented Sep 19, 2023

@jattasNI It looks like a promising approach to me. I'd imagine we could wait until then to resolve this.

@m-akinc
Copy link
Contributor

m-akinc commented Sep 26, 2023

We cannot use hostDirectives as an alternative to extending SelectControlValueAccessor and NgSelectOption. There is a requirement that any directive specified in hostDirectives must be "standalone", and neither of them are.

Image

@rajsite
Copy link
Member

rajsite commented Sep 26, 2023

We cannot use hostDirectives as an alternative to extending SelectControlValueAccessor and NgSelectOption. There is a requirement that any directive specified in hostDirectives must be "standalone", and neither of them are.

Image

Ah yea, related to the issues in the Default CVA, Angular doesn't want to make the default CVA's standalone either: #1017 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

5 participants