-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(viewer): Add focus trap for fullscreen #1439
feat(viewer): Add focus trap for fullscreen #1439
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM apart from some super minor comments, just needs tests.
} else { | ||
this.focusLastElement(); | ||
} | ||
event.stopPropagation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to stop propagation of the tab keydown event here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like if we're controlling the focus because of the tab key we should stop propagation. This is also how it's done in box-ui-elements
@@ -534,6 +540,28 @@ describe('lib/viewers/BaseViewer', () => { | |||
expect(base.disableAnnotationControls).toBeCalled(); | |||
expect(base.processAnnotationModeChange).toBeCalledWith(AnnotationMode.NONE); | |||
}); | |||
|
|||
test('should enable the focus trap', () => { | |||
jest.spyOn(FocusTrap.prototype, 'constructor'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little unusual to spy on the prototype. Can we instead make sure that base.focusTrap
is defined, then use jest.spyOn(base.focusTrap, 'enable')
? That way we're testing the instance rather than the prototype.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't prefer spying the prototype but I went this route because I wanted to test the case where we actually create the FocusTrap vs reuse it. I went with the approach you suggested below when reusing the existing focus trap
Adds
FocusTrap
class which takes an element and allows you toenable
ordisable
focus trapping.This class is used for when Preview enters fullscreen to constrain tab navigation to within the visible previewed content. This can also be applied to the print modal.
TODO: