Skip to content
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

Merged
merged 10 commits into from
Sep 20, 2021
9 changes: 7 additions & 2 deletions src/lib/viewers/controls/findbar/FindBarToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import IconSearch24 from '../icons/IconSearch24';
import './FindBarToggle.scss';

export type Props = {
onFindBarToggle?: () => void;
onFindBarToggle?: (buttonElement: EventTarget | null) => void;
};

export default function FindBarToggle({ onFindBarToggle }: Props): JSX.Element | null {
Expand All @@ -12,7 +12,12 @@ export default function FindBarToggle({ onFindBarToggle }: Props): JSX.Element |
}

return (
<button className="bp-FindBarToggle" onClick={onFindBarToggle} title={__('toggle_findbar')} type="button">
<button
className="bp-FindBarToggle"
onClick={({ target }): void => onFindBarToggle(target)}
title={__('toggle_findbar')}
type="button"
>
<IconSearch24 />
</button>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ describe('FindBarToggle', () => {
describe('event handlers', () => {
test('should forward the click from the button', () => {
const onToggle = jest.fn();
const mockedEvent = { target: document.createElement('button') };
const wrapper = getWrapper({ onFindBarToggle: onToggle });

wrapper.simulate('click');
wrapper.simulate('click', mockedEvent);

expect(onToggle).toBeCalled();
expect(onToggle).toBeCalledWith(mockedEvent.target);
});
});

Expand Down
7 changes: 4 additions & 3 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.findBarToggleEl && this.findBarToggleEl.focus) {
this.findBarToggleEl.focus();
}
}

Expand Down Expand Up @@ -1483,7 +1483,8 @@ class DocBaseViewer extends BaseViewer {
this.pinchPage = null;
}

toggleFindBar() {
toggleFindBar(findBarToggleEl) {
this.findBarToggleEl = findBarToggleEl;
this.findBar.toggle();
}

Expand Down