mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Also support using spacebar to open/close menu
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<div class="nav-item dropdown expandable-navbar-section"
|
<div class="nav-item dropdown expandable-navbar-section"
|
||||||
*ngVar="(active | async) as isActive"
|
*ngVar="(active | async) as isActive"
|
||||||
(keyup.enter)="isActive ? deactivateSection($event) : activateSection($event)"
|
(keyup.enter)="isActive ? deactivateSection($event) : activateSection($event)"
|
||||||
|
(keyup.space)="isActive ? deactivateSection($event) : activateSection($event)"
|
||||||
(mouseenter)="activateSection($event)"
|
(mouseenter)="activateSection($event)"
|
||||||
(mouseleave)="deactivateSection($event)">
|
(mouseleave)="deactivateSection($event)">
|
||||||
<a href="#" class="nav-link dropdown-toggle" routerLinkActive="active"
|
<a href="#" class="nav-link dropdown-toggle" routerLinkActive="active"
|
||||||
|
@@ -113,6 +113,42 @@ describe('ExpandableNavbarSectionComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when spacebar is pressed on section header (while inactive)', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(menuService, 'activateSection');
|
||||||
|
// Make sure section is 'inactive'. Requires calling ngOnInit() to update component 'active' property.
|
||||||
|
spyOn(menuService, 'isSectionActive').and.returnValue(observableOf(false));
|
||||||
|
component.ngOnInit();
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const sidebarToggler = fixture.debugElement.query(By.css('div.nav-item.dropdown'));
|
||||||
|
// dispatch the (keyup.space) action used in our component HTML
|
||||||
|
sidebarToggler.nativeElement.dispatchEvent(new KeyboardEvent('keyup', { key: ' ' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call activateSection on the menuService', () => {
|
||||||
|
expect(menuService.activateSection).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when spacebar is pressed on section header (while active)', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(menuService, 'deactivateSection');
|
||||||
|
// Make sure section is 'active'. Requires calling ngOnInit() to update component 'active' property.
|
||||||
|
spyOn(menuService, 'isSectionActive').and.returnValue(observableOf(true));
|
||||||
|
component.ngOnInit();
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const sidebarToggler = fixture.debugElement.query(By.css('div.nav-item.dropdown'));
|
||||||
|
// dispatch the (keyup.space) action used in our component HTML
|
||||||
|
sidebarToggler.nativeElement.dispatchEvent(new KeyboardEvent('keyup', { key: ' ' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call deactivateSection on the menuService', () => {
|
||||||
|
expect(menuService.deactivateSection).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when a click occurs on the section header', () => {
|
describe('when a click occurs on the section header', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(menuService, 'toggleActiveSection');
|
spyOn(menuService, 'toggleActiveSection');
|
||||||
|
Reference in New Issue
Block a user