@@ -16,7 +16,7 @@ import {MdInputModule} from '../input/index';
16
16
import { Dir , LayoutDirection } from '../core/rtl/dir' ;
17
17
import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
18
18
import { 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' ;
20
20
import { MdOption } from '../core/option/option' ;
21
21
import { ViewportRuler } from '../core/overlay/position/viewport-ruler' ;
22
22
import { FakeViewportRuler } from '../core/overlay/position/fake-viewport-ruler' ;
@@ -747,6 +747,36 @@ describe('MdAutocomplete', () => {
747
747
expect ( scrollContainer . scrollTop ) . toEqual ( 272 , `Expected panel to reveal last option.` ) ;
748
748
} ) ) ;
749
749
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
+
750
780
} ) ;
751
781
752
782
describe ( 'aria' , ( ) => {
0 commit comments