Skip to content

Commit 5331ff6

Browse files
authored
Merge pull request DSpace#2330 from doana/dynamic-scrollable-dropdown-accessibility
Add the ability to expand / collapse via keyboard
2 parents 661b4ae + 275b057 commit 5331ff6

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(blur)="onBlur($event)"
2424
(click)="$event.stopPropagation(); openDropdown(sdRef);"
2525
(focus)="onFocus($event)"
26-
(keypress)="$event.preventDefault()">
26+
(keydown)="selectOnKeyDown($event, sdRef)">
2727
</div>
2828

2929
<div ngbDropdownMenu

src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
9898
}
9999
}
100100

101+
/**
102+
* KeyDown handler to allow toggling the dropdown via keyboard
103+
* @param event KeyboardEvent
104+
* @param sdRef The reference of the NgbDropdown.
105+
*/
106+
selectOnKeyDown(event: KeyboardEvent, sdRef: NgbDropdown) {
107+
const keyName = event.key;
108+
109+
if (keyName === ' ' || keyName === 'Enter') {
110+
event.preventDefault();
111+
event.stopPropagation();
112+
sdRef.toggle();
113+
} else if (keyName === 'ArrowDown' || keyName === 'ArrowUp') {
114+
this.openDropdown(sdRef);
115+
}
116+
}
117+
101118
/**
102119
* Loads any new entries
103120
*/

0 commit comments

Comments
 (0)