fix(aio): set focus back to search box on "escape"

For improved accessibility, the focus should be sent
back to the input box when we are displaying the
search results and the user hits ESC.

See #16005
This commit is contained in:
Peter Bacon Darwin 2017-05-12 15:04:28 +01:00 committed by Pete Bacon Darwin
parent 98e31290a7
commit ecc356ecea
2 changed files with 10 additions and 0 deletions

View File

@ -504,6 +504,15 @@ describe('AppComponent', () => {
fixture.detectChanges();
expect(searchBox.focus).toHaveBeenCalled();
});
it('should set focus back to the search box when the search results are displayed and the escape key is pressed', () => {
const searchBox: SearchBoxComponent = fixture.debugElement.query(By.directive(SearchBoxComponent)).componentInstance;
spyOn(searchBox, 'focus');
component.showSearchResults = true;
window.document.dispatchEvent(new KeyboardEvent('keyup', { 'key': 'Escape' }));
fixture.detectChanges();
expect(searchBox.focus).toHaveBeenCalled();
});
});
describe('showing search results', () => {

View File

@ -268,6 +268,7 @@ export class AppComponent implements OnInit {
// escape key
if (this.showSearchResults) {
this.hideSearchResults();
this.focusSearchBox();
}
}
}