Allows closing dropdown with Escape key (#11489)

Implements the ability to close the dropdown list by pressing the Escape key.

This enhances the user experience by providing a keyboard shortcut to dismiss the dropdown, improving accessibility and efficiency.
This commit is contained in:
Michaela
2026-01-02 11:04:18 +01:00
committed by GitHub
parent 0fbb53da39
commit 4113eeb2ab
2 changed files with 21 additions and 0 deletions
@@ -24,6 +24,8 @@
[multiple]="field.hasMultipleValues"
[disabled]="field.readOnly"
[required]="field.required"
#select
(keydown.escape)="select.close()"
>
<adf-select-filter-input *ngIf="showInputFilter" (change)="filter$.next($event)" />
@@ -187,6 +187,25 @@ describe('DropdownCloudWidgetComponent', () => {
expect(formCloudService.getRestWidgetData).not.toHaveBeenCalled();
});
it('should close dropdown when Escape key is pressed', async () => {
const dropdown = await loader.getHarness(MatSelectHarness.with({ selector: '.adf-select' }));
await dropdown.open();
const filterInput = fixture.debugElement.query(By.css('.adf-select'));
filterInput.nativeElement.focus();
filterInput.nativeElement.dispatchEvent(
new KeyboardEvent('keydown', {
key: 'Escape',
code: 'Escape',
bubbles: true
})
);
fixture.detectChanges();
expect(await dropdown.isOpen()).toBeFalse();
});
describe('should load data from restUrl when form is NOT readonly', () => {
beforeEach(() => {
spyOn(formCloudService, 'getRestWidgetData').and.returnValue(of([]));