Skip to content

Commit

Permalink
fix(modal): focus stays trapped with Shift+Tab
Browse files Browse the repository at this point in the history
Closes #2807
Fixes #2718
  • Loading branch information
maxokorokov committed Oct 18, 2018
1 parent ce7e626 commit 67651be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
24 changes: 11 additions & 13 deletions e2e-app/e2e/src/modal/modal-focus.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,15 @@ describe('Modal', () => {
await expectFocused(page.getModalDismissButton(), 'Modal dismiss button should be focused');
});

// TODO: this is broken, must be fixed
// it('should keep focus trap inside the modal when clicking on content and navigating away (Shift + Tab)', async() =>
// {
// const modal = await page.openModal('template');
//
// // click on the header
// await page.getModalHeader().click();
// await expectFocused(modal, 'Modal window should be focused');
//
// // re-focus
// await sendKey(Key.SHIFT, Key.TAB);
// await expectFocused(page.getModalCloseButton(), 'Modal close button should be focused');
// });
it('should keep focus trap inside the modal when clicking on content and navigating away (Shift + Tab)', async() => {
const modal = await page.openModal('template');

// click on the header
await page.getModalHeader().click();
await expectFocused(modal, 'Modal window should be focused');

// re-focus
await sendKey(Key.SHIFT, Key.TAB);
await expectFocused(page.getModalCloseButton(), 'Modal close button should be focused');
});
});
2 changes: 1 addition & 1 deletion src/util/focus-trap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const ngbFocusTrap = (element: HTMLElement, stopFocusTrap$: Observable<an
.subscribe(([tabEvent, focusedElement]) => {
const[first, last] = getFocusableBoundaryElements(element);

if (focusedElement === first && tabEvent.shiftKey) {
if ((focusedElement === first || focusedElement === element) && tabEvent.shiftKey) {
last.focus();
tabEvent.preventDefault();
}
Expand Down

0 comments on commit 67651be

Please sign in to comment.