@@ -16,7 +16,7 @@ import {MdInputModule} from '../input/index';
1616import { Dir , LayoutDirection } from '../core/rtl/dir' ;
1717import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
1818import { Subscription } from 'rxjs/Subscription' ;
19- import { ENTER , DOWN_ARROW , SPACE , UP_ARROW } from '../core/keyboard/keycodes' ;
19+ import { ENTER , DOWN_ARROW , SPACE , UP_ARROW , HOME , END } from '../core/keyboard/keycodes' ;
2020import { MdOption } from '../core/option/option' ;
2121import { ViewportRuler } from '../core/overlay/position/viewport-ruler' ;
2222import { FakeViewportRuler } from '../core/overlay/position/fake-viewport-ruler' ;
@@ -747,6 +747,36 @@ describe('MdAutocomplete', () => {
747747 expect ( scrollContainer . scrollTop ) . toEqual ( 272 , `Expected panel to reveal last option.` ) ;
748748 } ) ) ;
749749
750+ it ( 'should scroll the active option into view when pressing END' , fakeAsync ( ( ) => {
751+ tick ( ) ;
752+ const scrollContainer =
753+ document . querySelector ( '.cdk-overlay-pane .mat-autocomplete-panel' ) ;
754+
755+ const END_EVENT = new MockKeyboardEvent ( END ) as KeyboardEvent ;
756+ fixture . componentInstance . trigger . _handleKeydown ( END_EVENT ) ;
757+ tick ( ) ;
758+ fixture . detectChanges ( ) ;
759+
760+ // Expect option bottom minus the panel height (528 - 256 = 272)
761+ expect ( scrollContainer . scrollTop ) . toEqual ( 272 , 'Expected panel to reveal the last option.' ) ;
762+ } ) ) ;
763+
764+ it ( 'should scroll the active option into view when pressing HOME' , fakeAsync ( ( ) => {
765+ tick ( ) ;
766+ const scrollContainer =
767+ document . querySelector ( '.cdk-overlay-pane .mat-autocomplete-panel' ) ;
768+
769+ scrollContainer . scrollTop = 100 ;
770+ fixture . detectChanges ( ) ;
771+
772+ const HOME_EVENT = new MockKeyboardEvent ( HOME ) as KeyboardEvent ;
773+ fixture . componentInstance . trigger . _handleKeydown ( HOME_EVENT ) ;
774+ tick ( ) ;
775+ fixture . detectChanges ( ) ;
776+
777+ expect ( scrollContainer . scrollTop ) . toEqual ( 0 , 'Expected panel to reveal the first option.' ) ;
778+ } ) ) ;
779+
750780 } ) ;
751781
752782 describe ( 'aria' , ( ) => {
0 commit comments