Skip to content

Commit e94df57

Browse files
committed
fix(dropdown): don't focus the button on load
1 parent 3b90e48 commit e94df57

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/dropdown/dropdown.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
229229
this.propagateChange(this.view.getSelected());
230230
} else {
231231
this.closeMenu();
232-
this.dropdownButton.nativeElement.focus();
233232
if (event.item && event.item.selected) {
234233
if (this.value) {
235234
this.propagateChange(event.item[this.value]);
@@ -487,10 +486,15 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
487486
* Collapsing the dropdown menu and removing unnecessary `EventListeners`.
488487
*/
489488
closeMenu() {
489+
// return early if the menu is already closed
490+
if (this.menuIsClosed) { return; }
490491
this.menuIsClosed = true;
491492
this.onClose.emit();
492493
this.close.emit();
493494

495+
// focus the trigger button when we close ...
496+
this.dropdownButton.nativeElement.focus();
497+
494498
// remove the conditional once this api is settled and part of abstract-dropdown-view.class
495499
if (this.view["disableScroll"]) {
496500
this.view["disableScroll"]();

src/dropdown/dropdown.stories.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ storiesOf("Dropdown", module)
1717
.add("Basic", () => ({
1818
template: `
1919
<div style="width: 300px">
20+
<input type="text"/>
2021
<ibm-dropdown
2122
[theme]="theme"
2223
placeholder="Select"

0 commit comments

Comments
 (0)