Skip to content

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

Merged
andrewseguin merged 1 commit into
angular:masterfrom
devversion:feat/form-field-injection-token
Mar 12, 2020
Merged

andrewseguin merged 1 commit into
angular:masterfrom
devversion:feat/form-field-injection-token

Conversation

@devversion

@devversion devversion commented Mar 10, 2020 •

Copy link
Copy Markdown
Member

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

@crisbeto crisbeto left a comment

Copy link
Copy Markdown
Member

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

@jelbourn jelbourn left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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

6 participants