Skip to content

Commit

Permalink
Fix: Prevent focus loss in IE when navigating thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press authored May 16, 2019
1 parent b1dacfd commit 685b4b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib/ThumbnailsSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class ThumbnailsSidebar {
}
}

// IE 11 will focus a div when it's parent has a tabindex, so we focus the anchorEl to avoid
// a loss of focus when elements are deleted by the Virtual Scroller.
this.anchorEl.focus();

event.preventDefault();
event.stopImmediatePropagation();
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/__tests__/ThumbnailsSidebar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ describe('ThumbnailsSidebar', () => {
stubs.onThumbnailSelect = sandbox.stub();
stubs.preventDefault = sandbox.stub();
stubs.stopImmediatePropagation = sandbox.stub();
stubs.focus = sandbox.stub();

parentEl = document.createElement('div');
parentEl.dataset.bpPageNum = '3';
Expand All @@ -335,12 +336,14 @@ describe('ThumbnailsSidebar', () => {
};

thumbnailsSidebar.onThumbnailSelect = stubs.onThumbnailSelect;
thumbnailsSidebar.anchorEl.focus = stubs.focus;
});

it('should call the onThumbnailSelect if target is a thumbnail element', () => {
thumbnailsSidebar.thumbnailClickHandler(evt);

expect(stubs.onThumbnailSelect).to.be.calledWith(3);
expect(stubs.focus).to.be.called;
expect(stubs.preventDefault).to.be.called;
expect(stubs.stopImmediatePropagation).to.be.called;
});
Expand All @@ -350,6 +353,7 @@ describe('ThumbnailsSidebar', () => {
thumbnailsSidebar.thumbnailClickHandler(evt);

expect(stubs.onThumbnailSelect).not.to.be.called;
expect(stubs.focus).to.be.called;
expect(stubs.preventDefault).to.be.called;
expect(stubs.stopImmediatePropagation).to.be.called;
});
Expand Down

0 comments on commit 685b4b5

Please sign in to comment.