Skip to content

Commit 3765298

Browse files
authored
Merge pull request #242 from youda97/modal-focus
Add support to focus the first focusable element in a modal
2 parents fca28c2 + 7b01b44 commit 3765298

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/modal/modal.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
transition,
1919
animate
2020
} from "@angular/animations";
21-
import { cycleTabs } from "./../common/tab.service";
21+
import { cycleTabs, getFocusElementList } from "./../common/tab.service";
2222

2323

2424
/**
@@ -167,7 +167,11 @@ export class Modal implements AfterViewInit, OnInit, OnDestroy {
167167
primaryFocusElement.focus();
168168
return;
169169
}
170-
this.modal.nativeElement.focus();
170+
if (getFocusElementList(this.modal.nativeElement).length > 0) {
171+
getFocusElementList(this.modal.nativeElement)[0].focus();
172+
} else {
173+
this.modal.nativeElement.focus();
174+
}
171175
}
172176

173177
/**

0 commit comments

Comments
 (0)