-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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(autocomplete): support for md-optgroup #5604
Merged
+268
−64
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f16c078
feat(autocomplete): support for md-optgroup
crisbeto 1544877
refactor: move duplicated logic into static method
crisbeto 028495e
chore: clean up long lines in docs and add blurb about groups
crisbeto 4deaab9
chore: add option group demo
crisbeto d24822d
chore: test failure
crisbeto 68621b6
fix: presubmit and lint issues
crisbeto 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 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 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 |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
|
||
.mat-form-field { | ||
margin-top: 16px; | ||
min-width: 200px; | ||
max-width: 100%; | ||
} | ||
} | ||
|
||
|
This file contains 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 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 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 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 |
---|---|---|
|
@@ -55,7 +55,8 @@ describe('MdAutocomplete', () => { | |
AutocompleteWithOnPushDelay, | ||
AutocompleteWithNativeInput, | ||
AutocompleteWithoutPanel, | ||
AutocompleteWithFormsAndNonfloatingPlaceholder | ||
AutocompleteWithFormsAndNonfloatingPlaceholder, | ||
AutocompleteWithGroups | ||
], | ||
providers: [ | ||
{provide: OverlayContainer, useFactory: () => { | ||
|
@@ -986,6 +987,79 @@ describe('MdAutocomplete', () => { | |
|
||
}); | ||
|
||
describe('option groups', () => { | ||
let fixture: ComponentFixture<AutocompleteWithGroups>; | ||
let DOWN_ARROW_EVENT: KeyboardEvent; | ||
let UP_ARROW_EVENT: KeyboardEvent; | ||
let container: HTMLElement; | ||
|
||
beforeEach(fakeAsync(() => { | ||
fixture = TestBed.createComponent(AutocompleteWithGroups); | ||
fixture.detectChanges(); | ||
|
||
DOWN_ARROW_EVENT = createKeyboardEvent('keydown', DOWN_ARROW); | ||
UP_ARROW_EVENT = createKeyboardEvent('keydown', UP_ARROW); | ||
|
||
fixture.componentInstance.trigger.openPanel(); | ||
fixture.detectChanges(); | ||
tick(); | ||
fixture.detectChanges(); | ||
container = document.querySelector('.mat-autocomplete-panel') as HTMLElement; | ||
})); | ||
|
||
it('should scroll to active options below the fold', fakeAsync(() => { | ||
fixture.componentInstance.trigger._handleKeydown(DOWN_ARROW_EVENT); | ||
tick(); | ||
fixture.detectChanges(); | ||
expect(container.scrollTop).toBe(0, 'Expected the panel not to scroll.'); | ||
|
||
// Press the down arrow five times. | ||
[1, 2, 3, 4, 5].forEach(() => { | ||
fixture.componentInstance.trigger._handleKeydown(DOWN_ARROW_EVENT); | ||
tick(); | ||
}); | ||
|
||
// <option bottom> - <panel height> + <2x group labels> = 128 | ||
// 288 - 256 + 96 = 128 | ||
expect(container.scrollTop) | ||
.toBe(128, 'Expected panel to reveal the sixth option.'); | ||
})); | ||
|
||
it('should scroll to active options on UP arrow', fakeAsync(() => { | ||
fixture.componentInstance.trigger._handleKeydown(UP_ARROW_EVENT); | ||
tick(); | ||
fixture.detectChanges(); | ||
|
||
// <option bottom> - <panel height> + <3x group label> = 464 | ||
// 576 - 256 + 144 = 464 | ||
expect(container.scrollTop).toBe(464, 'Expected panel to reveal last option.'); | ||
})); | ||
|
||
it('should scroll to active options that are above the panel', fakeAsync(() => { | ||
fixture.componentInstance.trigger._handleKeydown(DOWN_ARROW_EVENT); | ||
tick(); | ||
fixture.detectChanges(); | ||
expect(container.scrollTop).toBe(0, 'Expected panel not to scroll.'); | ||
|
||
// These down arrows will set the 7th option active, below the fold. | ||
[1, 2, 3, 4, 5, 6].forEach(() => { | ||
fixture.componentInstance.trigger._handleKeydown(DOWN_ARROW_EVENT); | ||
tick(); | ||
}); | ||
|
||
// These up arrows will set the 2nd option active | ||
[5, 4, 3, 2, 1].forEach(() => { | ||
fixture.componentInstance.trigger._handleKeydown(UP_ARROW_EVENT); | ||
tick(); | ||
}); | ||
|
||
// Expect to show the top of the 2nd option at the top of the panel. | ||
// It is offset by 48, because there's a group label above it. | ||
expect(container.scrollTop) | ||
.toBe(96, 'Expected panel to scroll up when option is above panel.'); | ||
})); | ||
}); | ||
|
||
describe('aria', () => { | ||
let fixture: ComponentFixture<SimpleAutocomplete>; | ||
let input: HTMLInputElement; | ||
|
@@ -1706,3 +1780,38 @@ class AutocompleteWithoutPanel { | |
class AutocompleteWithFormsAndNonfloatingPlaceholder { | ||
formControl = new FormControl('California'); | ||
} | ||
|
||
|
||
@Component({ | ||
template: ` | ||
<md-input-container> | ||
<input mdInput placeholder="State" [mdAutocomplete]="auto" [(ngModel)]="selectedState"> | ||
</md-input-container> | ||
|
||
<md-autocomplete #auto="mdAutocomplete"> | ||
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. Can you add an autocomplete like this to the autocomplete demo page? |
||
<md-optgroup *ngFor="let group of stateGroups" [label]="group.label"> | ||
<md-option *ngFor="let state of group.states" [value]="state"> | ||
<span>{{ state }}</span> | ||
</md-option> | ||
</md-optgroup> | ||
</md-autocomplete> | ||
` | ||
}) | ||
class AutocompleteWithGroups { | ||
@ViewChild(MdAutocompleteTrigger) trigger: MdAutocompleteTrigger; | ||
selectedState: string; | ||
stateGroups = [ | ||
{ | ||
title: 'One', | ||
states: ['Alabama', 'California', 'Florida', 'Oregon'] | ||
}, | ||
{ | ||
title: 'Two', | ||
states: ['Kansas', 'Massachusetts', 'New York', 'Pennsylvania'] | ||
}, | ||
{ | ||
title: 'Three', | ||
states: ['Tennessee', 'Virginia', 'Wyoming', 'Alaska'] | ||
} | ||
]; | ||
} |
Oops, something went wrong.
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.
Failing presubmit because of TS error for "private name
StateGroup
" and "private nameState
". I think you need to export these interfaces.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.
Also can you fix the lint failure? https://travis-ci.org/angular/material2/jobs/266064783