Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions elements/pfe-dropdown/pfe-dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class PfeDropdown extends LitElement {
case 'Escape':
event.preventDefault();
event.stopPropagation();
this.focus();
this._focus();
await this.updateComplete;
this.close();
break;
Expand Down Expand Up @@ -341,7 +341,7 @@ export class PfeDropdown extends LitElement {
// return focus back to button
this.close();
await this.updateComplete;
this.focus();
this._focus();
} else {
item.click();
}
Expand All @@ -352,6 +352,11 @@ export class PfeDropdown extends LitElement {
return item.shadowRoot?.querySelector(`.pfe-dropdown-item__container`) ?? null;
}

// move focus to the button
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// move focus to the button
/** Move focus back to the button after closing the dropdown */

private _focus():void {
this.shadowRoot?.querySelector<HTMLButtonElement>('#pfe-dropdown-toggle')?.focus();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.shadowRoot?.querySelector<HTMLButtonElement>('#pfe-dropdown-toggle')?.focus();
this.button?.focus();

}

/**
* Add dropdown items dynamically
* @example adding a single option
Expand Down
4 changes: 2 additions & 2 deletions elements/pfe-dropdown/test/pfe-dropdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('<pfe-dropdown>', function() {
let menu: HTMLElement | null | undefined;
beforeEach(async function() {
menu = element.shadowRoot?.querySelector('#pfe-dropdown-menu');
element.focus();
await sendKeys({ press: 'Tab' });
await element.updateComplete;
});

Expand Down Expand Up @@ -218,7 +218,7 @@ describe('<pfe-dropdown>', function() {
await element.updateComplete;
});

it(`Enter should exit open dialog and move to the dropdown.`, async function() {
it(`Enter should exit open dialog and move focus to the dropdown.`, async function() {
await sendKeys({ press: 'ArrowUp' });
await sendKeys({ press: 'Enter' });
await element.updateComplete;
Expand Down