-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
fix(autocomplete): update template when changing autocomplete in trigger #13814
fix(autocomplete): update template when changing autocomplete in trigger #13814
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
I signed it! |
CLAs look good, thanks! |
@@ -569,8 +569,15 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy { | |||
throw getMatAutocompleteMissingPanelError(); | |||
} | |||
|
|||
if (!this._overlayRef) { | |||
if (!this._portal || this._portal.templateRef !== this.autocomplete.template) { |
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.
A cleaner approach to this would be to move the _portal
to MatAutocomplete
and have the trigger just call OverlayRef.attach
.
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.
Do you prefer this (cleaner) approach?
I see you are also going with the current solution of not moving the portal
on this PR:
https://github.com/angular/material2/pull/13819/files#diff-39ddcd24dbc36104e27f79186c93d87aR547
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 would've preferred to move it for the menu as well, but it has a different set of requirements, because the consumer can pass in any object that implements the MatMenuPanel
interface.
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 moved the portal to the mat-autocomplete
. But we still have to detach first in the trigger before attaching a new portal, otherwise it will throw the "already attached" error.
I am also un- and resubscribing to closing actions now when attaching a new portal, so we get the correct option changes events.
fix(autocomplete): removed debug command in test
@@ -596,9 +595,19 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy { | |||
this._overlayRef.updateSize({width: this._getPanelWidth()}); | |||
} | |||
|
|||
if (this._overlayRef && !this._overlayRef.hasAttached()) { | |||
this._overlayRef.attach(this._portal); | |||
if (this._currentPortalAttached !== this.autocomplete._portal) { |
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'm not sure why you'd need to do this. You can just call detach
and then attach
again to set the new portal.
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.
@crisbeto I see your point there, but i am currently working on an issue (appears with and without this check) where a new panel will be created, even if the template has not changed. This especially happens in the tests, thats why a lot of them are failing.
For example take a look at this test: autocomplete.spec.ts#L267.
It is failing because we are creating a new panel on focusin
and later on typeInElement
(_attachOverlay
gets called in multiple times).
So i need to find a way to check if we should detach/reatach (when a new mat-autocomplete
has been set or not.
Maybe you have a good solution/idea for this one? Detach only if the template has changed?
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.
You don't have to do it in _attachPortal
though. Keeping _attachPortal
as it is in master, aside from taking the portal from the panel, and calling detach
when the autocomplete
input changes should do it.
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.
Changed it to a detach in the autocomplete input. Thanks for your help
Adds the yarn-related logs to a gitignore so people don't try to commit them accidentally. See angular#13814.
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.
LGTM, can be marked as merge ready once the last set of feedback is addressed and the yarn-error.log
file is deleted.
fixture.componentInstance.trigger.autocomplete = fixture.componentInstance.autoTow; | ||
fixture.detectChanges(); | ||
|
||
// reopen agian |
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.
agian -> again. Alternately these comments can be removed since they don't contribute much.
Adds the yarn-related logs to a gitignore so people don't try to commit them accidentally. See #13814.
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.
LGTM
Adds the yarn-related logs to a gitignore so people don't try to commit them accidentally. See angular#13814.
Adds the yarn-related logs to a gitignore so people don't try to commit them accidentally. See #13814.
… in trigger" (#14398) * Revert "Revert "fix(autocomplete): auto-highlighted first option not display correctly if the floating label is disabled" (#14396)" This reverts commit aa17fbd. * Revert "fix(drag-drop): error on touch end (#14392)" This reverts commit 53cecbb. * Revert "fix(menu): reduce specificity of icon selector (#14389)" This reverts commit 74e945a. * Revert "fix(drag-drop): throw better error when attaching to non-element node (#14221)" This reverts commit 31f0e6d. * Revert "fix(autocomplete): auto-highlighted first option not display correctly if the floating label is disabled (#13774)" This reverts commit c99c512. * Revert "fix(autocomplete): update template when changing autocomplete in trigger (#13814)" This reverts commit 904a5ea.
This was accidentally merged despite breaking some applications inside Google, so I had to revert it. @thomaspink feel free to open a new PR and we can try to resolve the breakages before merging again |
…ger (#13814) * fix(autocomplete): update template when changing autocomplete in trigger * fix(autocomplet): improved test for changing autocomplete panel fix(autocomplete): removed debug command in test * fix(autocomplete): moved portal from autocomplete-trigger to autocomplete * fix(autocomplete): setting currentPortal in trigger * fix(autocomplete): fixes issue when detaching when panel updates * feat(autocomplete): detaching portal when autocomplete input changes * feat(autocomplete): moved overlay detach to its own method * feat(autocomplete): typo & removed yarn-error.log
… in trigger" (#14398) * Revert "Revert "fix(autocomplete): auto-highlighted first option not display correctly if the floating label is disabled" (#14396)" This reverts commit aa17fbd. * Revert "fix(drag-drop): error on touch end (#14392)" This reverts commit 53cecbb. * Revert "fix(menu): reduce specificity of icon selector (#14389)" This reverts commit 74e945a. * Revert "fix(drag-drop): throw better error when attaching to non-element node (#14221)" This reverts commit 31f0e6d. * Revert "fix(autocomplete): auto-highlighted first option not display correctly if the floating label is disabled (#13774)" This reverts commit c99c512. * Revert "fix(autocomplete): update template when changing autocomplete in trigger (#13814)" This reverts commit 904a5ea.
…ger (angular#13814) * fix(autocomplete): update template when changing autocomplete in trigger * fix(autocomplet): improved test for changing autocomplete panel fix(autocomplete): removed debug command in test * fix(autocomplete): moved portal from autocomplete-trigger to autocomplete * fix(autocomplete): setting currentPortal in trigger * fix(autocomplete): fixes issue when detaching when panel updates * feat(autocomplete): detaching portal when autocomplete input changes * feat(autocomplete): moved overlay detach to its own method * feat(autocomplete): typo & removed yarn-error.log
… in trigger" (angular#14398) * Revert "Revert "fix(autocomplete): auto-highlighted first option not display correctly if the floating label is disabled" (angular#14396)" This reverts commit aa17fbd. * Revert "fix(drag-drop): error on touch end (angular#14392)" This reverts commit 53cecbb. * Revert "fix(menu): reduce specificity of icon selector (angular#14389)" This reverts commit 74e945a. * Revert "fix(drag-drop): throw better error when attaching to non-element node (angular#14221)" This reverts commit 31f0e6d. * Revert "fix(autocomplete): auto-highlighted first option not display correctly if the floating label is disabled (angular#13774)" This reverts commit c99c512. * Revert "fix(autocomplete): update template when changing autocomplete in trigger (angular#13814)" This reverts commit 904a5ea.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
fixes #13812