-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(autocomplete): update template when changing autocomplete in trigger #13814
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
Merged
mmalerba
merged 8 commits into
angular:master
from
thomaspink:fix/dynamically-changing-autocomplete
Dec 4, 2018
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
05e2ca3
fix(autocomplete): update template when changing autocomplete in trigger
thomaspink fd6feb5
fix(autocomplet): improved test for changing autocomplete panel
thomaspink 6454ffc
fix(autocomplete): moved portal from autocomplete-trigger to autocomp…
thomaspink 89391c5
fix(autocomplete): setting currentPortal in trigger
thomaspink 89496d8
fix(autocomplete): fixes issue when detaching when panel updates
thomaspink 1e32f4b
feat(autocomplete): detaching portal when autocomplete input changes
thomaspink 8831fc8
feat(autocomplete): moved overlay detach to its own method
thomaspink 471d2f4
feat(autocomplete): typo & removed yarn-error.log
thomaspink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2221,6 +2221,38 @@ describe('MatAutocomplete', () => { | |
expect(formControl.value).toBe('Cal', 'Expected new value to be propagated to model'); | ||
})); | ||
|
||
it('should work when dynamically changing the autocomplete', () => { | ||
const fixture = createComponent(DynamicallyChangingAutocomplete); | ||
fixture.detectChanges(); | ||
const input = fixture.debugElement.query(By.css('input')).nativeElement; | ||
|
||
dispatchFakeEvent(input, 'focusin'); | ||
fixture.detectChanges(); | ||
|
||
expect(overlayContainerElement.textContent).toContain('First', | ||
`Expected panel to display the option of the first autocomplete.`); | ||
expect(overlayContainerElement.textContent).not.toContain('Second', | ||
`Expected panel to not display the option of the second autocomplete.`); | ||
|
||
// close overlay | ||
dispatchFakeEvent(document, 'click'); | ||
fixture.detectChanges(); | ||
|
||
// Switch to second autocomplete | ||
fixture.componentInstance.trigger.autocomplete = fixture.componentInstance.autoTow; | ||
fixture.detectChanges(); | ||
|
||
// reopen agian | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
dispatchFakeEvent(input, 'focusin'); | ||
fixture.detectChanges(); | ||
|
||
expect(overlayContainerElement.textContent).not.toContain('First', | ||
`Expected panel to not display the option of the first autocomplete.`); | ||
expect(overlayContainerElement.textContent).toContain('Second', | ||
`Expected panel to display the option of the second autocomplete.`); | ||
|
||
}); | ||
|
||
}); | ||
|
||
@Component({ | ||
|
@@ -2607,3 +2639,21 @@ class AutocompleteWithNativeAutocompleteAttribute { | |
}) | ||
class InputWithoutAutocompleteAndDisabled { | ||
} | ||
|
||
@Component({ | ||
template: ` | ||
<input type="number" matInput [matAutocomplete]="autoOne"> | ||
<mat-autocomplete #autoOne> | ||
<mat-option [value]="0">First</mat-option> | ||
</mat-autocomplete> | ||
|
||
<mat-autocomplete #autoTow> | ||
<mat-option [value]="1">Second</mat-option> | ||
</mat-autocomplete> | ||
`, | ||
}) | ||
class DynamicallyChangingAutocomplete { | ||
@ViewChild('autoOne') autoOne: MatAutocomplete; | ||
@ViewChild('autoTow') autoTow: MatAutocomplete; | ||
@ViewChild(MatAutocompleteTrigger) trigger: MatAutocompleteTrigger; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thenattach
again to set the new portal.Uh oh!
There was an error while loading. Please reload this page.
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 ontypeInElement
(_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 callingdetach
when theautocomplete
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