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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(form-field): use injection token for providing form-field #18777

Merged

Conversation

devversion
Copy link
Member

@devversion devversion commented Mar 10, 2020

Implementers of custom form-field controls often want to inject the
parent MatFormField optionally. This currently has negative impact
as the whole MatFormField class w/ Angular metadata is brought in
due to the class being used as injector token. This can be avoided by
using a separate thin injection token called MAT_FORM_FIELD.

We use this now in MatSelect, MatAutocompleteTrigger and MatChipList. These
don't necessarily require a form-field, so it's a significant bundle size improvement
for such standalone controls w/o form-field.

Another benefit is that the MDC-based form-field no longer needs to re-provide the
standard MatFormField w/ the downside of bringing in a lot of unnecessary code.

@devversion devversion added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: minor This PR is targeted for the next minor release labels Mar 10, 2020
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Mar 10, 2020
Implementers of custom form-field controls often want to inject the
parent `MatFormField` optionally. This currently has negative impact
as the whole `MatFormField` class w/ Angular metadata is brought in
due to the class being used as injector token. This can be avoided by
using a separate thin injection token called `MAT_FORM_FIELD`.

We use this now in `MatSelect`, `MatAutocompleteTrigger` and `MatChipList`. These
don't necessarily require a form-field, so it's a significant bundle size improvement.

Another benefit is that the MDC-based form-field no longer needs to re-provide the
standard `MatFormField` w/ the downside of bringing in a lot of unnecessary code.
@devversion devversion force-pushed the feat/form-field-injection-token branch from 977d68d to cb05102 Compare March 10, 2020 15:15
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crisbeto crisbeto added lgtm action: merge The PR is ready for merge by the caretaker labels Mar 10, 2020
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we will need to potentially do this for other injectables as well (and for optional ContentChildren)

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants