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:
parent
98e31290a7
commit
ecc356ecea
|
@ -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', () => {
|
||||
|
|
|
@ -268,6 +268,7 @@ export class AppComponent implements OnInit {
|
|||
// escape key
|
||||
if (this.showSearchResults) {
|
||||
this.hideSearchResults();
|
||||
this.focusSearchBox();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue