-
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
Wrong focus on close findbar #1429
Wrong focus on close findbar #1429
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.
We'll need to add tests for this change, as well.
<button | ||
ref={buttonReference} | ||
className="bp-FindBarToggle" | ||
onClick={(): void => onFindBarToggle(buttonReference.current)} |
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.
Can we do the following to avoid the ref?
onClick={({ target }) => onFindBarToggle(target)}
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.
of course
src/lib/viewers/doc/DocBaseViewer.js
Outdated
@@ -410,8 +410,8 @@ class DocBaseViewer extends BaseViewer { | |||
} | |||
|
|||
handleFindBarClose() { | |||
if (this.docEl) { | |||
this.docEl.focus(); // Prevent focus from transferring to the root document element | |||
if (this.findBarToggleElement) { |
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.
We may also want to check that .focus
exists.
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.
ok. Updated
const wrapper = getWrapper({ onFindBarToggle: onToggle }); | ||
|
||
wrapper.simulate('click'); | ||
wrapper.simulate('click', mockedEvent); | ||
|
||
expect(onToggle).toBeCalled(); |
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.
Should we update this to toBeCalledWith
and an explicit assertion?
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.
test updated
src/lib/viewers/doc/DocBaseViewer.js
Outdated
@@ -410,8 +410,8 @@ class DocBaseViewer extends BaseViewer { | |||
} | |||
|
|||
handleFindBarClose() { | |||
if (this.docEl) { | |||
this.docEl.focus(); // Prevent focus from transferring to the root document element | |||
if (this.findBarToggleElement && this.findBarToggleElement.focus) { |
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.
Do we have a test for this logic?
src/lib/viewers/doc/DocBaseViewer.js
Outdated
@@ -1483,7 +1483,8 @@ class DocBaseViewer extends BaseViewer { | |||
this.pinchPage = null; | |||
} | |||
|
|||
toggleFindBar() { | |||
toggleFindBar(elementToFocus) { | |||
this.findBarToggleElement = elementToFocus; |
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 looks like the convention in this file shortens Element
to El
. Should we rename to findBarToggleEl
?
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.
renamed
When the findBar is closed the focus should go back to the find toggle button located on toolbar.