Commit f69f3803 authored by Robert Knight's avatar Robert Knight

Fix clicking on PDF closing sidebar when side-by-side is active

Fix a regression introduced in b52f00e0 where clicking in a PDF
when side-by-side is active would cause the sidebar to close instead of
remaining open. That PR made `PdfSidebar` no longer inherit (indirectly)
from Guest but did not update the references to the `closeSidebarOnDocumentClick`
property of the Guest.
parent 3771ff0e
...@@ -51,7 +51,7 @@ export default class PdfSidebar extends Sidebar { ...@@ -51,7 +51,7 @@ export default class PdfSidebar extends Sidebar {
*/ */
activateSideBySide(width) { activateSideBySide(width) {
this.sideBySideActive = true; this.sideBySideActive = true;
this.closeSidebarOnDocumentClick = false; this.guest.closeSidebarOnDocumentClick = false;
this.pdfContainer.style.width = width + 'px'; this.pdfContainer.style.width = width + 'px';
this.pdfContainer.classList.add('hypothesis-side-by-side'); this.pdfContainer.classList.add('hypothesis-side-by-side');
} }
...@@ -62,7 +62,7 @@ export default class PdfSidebar extends Sidebar { ...@@ -62,7 +62,7 @@ export default class PdfSidebar extends Sidebar {
*/ */
deactivateSideBySide() { deactivateSideBySide() {
this.sideBySideActive = false; this.sideBySideActive = false;
this.closeSidebarOnDocumentClick = true; this.guest.closeSidebarOnDocumentClick = true;
this.pdfContainer.style.width = 'auto'; this.pdfContainer.style.width = 'auto';
this.pdfContainer.classList.remove('hypothesis-side-by-side'); this.pdfContainer.classList.remove('hypothesis-side-by-side');
} }
......
...@@ -4,7 +4,7 @@ import Delegator from '../delegator'; ...@@ -4,7 +4,7 @@ import Delegator from '../delegator';
import { mockBaseClass } from '../../test-util/mock-base'; import { mockBaseClass } from '../../test-util/mock-base';
class FakeSidebar extends Delegator { class FakeSidebar extends Delegator {
constructor(element, config, guest) { constructor(element, guest, config) {
super(element, config); super(element, config);
this.guest = guest; this.guest = guest;
} }
...@@ -17,12 +17,12 @@ class FakeSidebar extends Delegator { ...@@ -17,12 +17,12 @@ class FakeSidebar extends Delegator {
describe('PdfSidebar', () => { describe('PdfSidebar', () => {
const sandbox = sinon.createSandbox(); const sandbox = sinon.createSandbox();
let fakeGuest;
let fakePDFViewerApplication; let fakePDFViewerApplication;
let fakePDFContainer; let fakePDFContainer;
let fakePDFViewerUpdate; let fakePDFViewerUpdate;
const createPdfSidebar = config => { const createPdfSidebar = config => {
const fakeGuest = {};
const element = document.createElement('div'); const element = document.createElement('div');
return new PdfSidebar(element, fakeGuest, config); return new PdfSidebar(element, fakeGuest, config);
}; };
...@@ -46,6 +46,10 @@ describe('PdfSidebar', () => { ...@@ -46,6 +46,10 @@ describe('PdfSidebar', () => {
// Can't stub an undefined property in a sandbox // Can't stub an undefined property in a sandbox
window.PDFViewerApplication = fakePDFViewerApplication; window.PDFViewerApplication = fakePDFViewerApplication;
fakeGuest = {
closeSidebarOnDocumentClick: true,
};
unmockSidebar = mockBaseClass(PdfSidebar, FakeSidebar); unmockSidebar = mockBaseClass(PdfSidebar, FakeSidebar);
}); });
...@@ -90,6 +94,18 @@ describe('PdfSidebar', () => { ...@@ -90,6 +94,18 @@ describe('PdfSidebar', () => {
assert.equal(fakePDFContainer.style.width, 1300 - 428 + 'px'); assert.equal(fakePDFContainer.style.width, 1300 - 428 + 'px');
}); });
it('disables closing sidebar on document click when side-by-side is active', () => {
const sidebar = createPdfSidebar();
sidebar.activateSideBySide();
assert.isFalse(fakeGuest.closeSidebarOnDocumentClick);
});
it('enables closing sidebar on document click when side-by-side is inactive', () => {
const sidebar = createPdfSidebar();
sidebar.deactivateSideBySide();
assert.isTrue(fakeGuest.closeSidebarOnDocumentClick);
});
it('does not activate side-by-side mode if there is not enough room', () => { it('does not activate side-by-side mode if there is not enough room', () => {
sandbox.stub(window, 'innerWidth').value(800); sandbox.stub(window, 'innerWidth').value(800);
const sidebar = createPdfSidebar(); const sidebar = createPdfSidebar();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment