-
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 1 commit
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.selected = 1; | ||
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,19 @@ class AutocompleteWithNativeAutocompleteAttribute { | |
}) | ||
class InputWithoutAutocompleteAndDisabled { | ||
} | ||
|
||
@Component({ | ||
template: ` | ||
<input type="number" matInput [matAutocomplete]="selected ? auto1 : auto0"> | ||
<mat-autocomplete #auto0="matAutocomplete"> | ||
<mat-option [value]="0">First</mat-option> | ||
</mat-autocomplete> | ||
|
||
<mat-autocomplete #auto1="matAutocomplete"> | ||
<mat-option [value]="1">Second</mat-option> | ||
</mat-autocomplete> | ||
`, | ||
}) | ||
class DynamicallyChangingAutocomplete { | ||
selected = 0; | ||
thomaspink marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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.
A cleaner approach to this would be to move the
_portal
toMatAutocomplete
and have the trigger just callOverlayRef.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.