Skip to content

Commit

Permalink
Attach mouseUp event handler properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Joozty committed Sep 29, 2019
1 parent f5efbac commit 85029df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
21 changes: 7 additions & 14 deletions src/components/pdf-highlighter/PDFHighlighter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ class PDFHighlighter extends React.Component {
selectedText: '',
}

componentDidMount() {
window.addEventListener('mouseup', this.onAfterSelection.bind(this))
}

componentWillUnmount() {
window.removeEventListener('mouseup', this.onAfterSelection)
onUpdateContextMenu = partialUpdate => {
this.setState(state => ({
...state,
...partialUpdate,
}))
}

onAfterSelection() {
handleOnMouseUp() {
const {
state: {
pdfDocument: { pdfViewer },
Expand Down Expand Up @@ -83,13 +82,6 @@ class PDFHighlighter extends React.Component {
})
}

onUpdateContextMenu = partialUpdate => {
this.setState(state => ({
...state,
...partialUpdate,
}))
}

render() {
const {
contextRoot,
Expand All @@ -102,6 +94,7 @@ class PDFHighlighter extends React.Component {

const children = cloneElement(this.props.children, {
...this.props,
handleOnMouseUp: this.handleOnMouseUp.bind(this),
})

const contextMenu =
Expand Down
18 changes: 11 additions & 7 deletions src/components/pdf-viewer/PDFViewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class PDFViewer extends React.PureComponent {
// when particular PDF page is not rendered
render() {
const { toolbarEnabled, metadataContainerWidth } = this.state
const { pdfMetadata, pdfEventBus } = this.props
const { pdfMetadata, pdfEventBus, handleOnMouseUp } = this.props
const { Metadata, pdfViewer } = this

return (
Expand All @@ -111,12 +111,16 @@ class PDFViewer extends React.PureComponent {
}}
>
{metadataContainerWidth && <Metadata pdfMetadata={pdfMetadata} />}
<div
ref={node => {
this.viewerNode = node
}}
className="pdfViewer"
/>
<div role="dialog">
<div
role="presentation"
ref={node => {
this.viewerNode = node
}}
className="pdfViewer"
onMouseUp={handleOnMouseUp}
/>
</div>
<PDFRecommender containerWidth={metadataContainerWidth} />
{toolbarEnabled && (
<PDFToolbar pdfViewer={pdfViewer} pdfEventBus={pdfEventBus} />
Expand Down

0 comments on commit 85029df

Please sign in to comment.