progress on click away listener
+import ClickAwayListener from "@material-ui/core/ClickAwayListener";
import MuiDrawer from "@material-ui/core/Drawer";
import IconButton from "@material-ui/core/IconButton";
import ChevronRightIcon from "@material-ui/icons/ChevronRight";
@@ -11,6 +12,17 @@ import { ScholarReaderContext } from "./state";
const PDF_VIEWER_DRAWER_OPEN_CLASS = "drawer-open";
export class Drawer extends React.PureComponent {
+ // Some unfortunate trickery to get around the pitfalls of the click away listener
+ shouldClose = (path: Array<HTMLDivElement>) => {
+ path.forEach( (element: HTMLDivElement) => {
+ console.log(element.className);
+ if (element.className === 'scholar-reader-overlay' || element.className === 'MuiTooltip-tooltip') {
+ return false;
+ }
+ })
+ return true;
+ }
+
componentWillUnmount() {
const { pdfViewer } = this.context;
if (pdfViewer !== undefined && pdfViewer !== null) {
@@ -55,6 +67,11 @@ export class Drawer extends React.PureComponent {
}
return (
+ <ClickAwayListener onClickAway={({ path }) => {
+ if (this.shouldClose(path)) {
+ setDrawerState('closed');
+ }
+ }}>
<MuiDrawer
className="drawer"
variant="persistent"
@@ -77,6 +94,7 @@ export class Drawer extends React.PureComponent {
{drawerState === "show-citations" && <PaperList />}
</div>
</MuiDrawer>
+ </ClickAwayListener>
);
}}
</ScholarReaderContext.Consumer>
