Skip to content

Commit

Permalink
Merge pull request #162 from bsbimalbose/hotfix/IE-paste
Browse files Browse the repository at this point in the history
Hotfix/ie paste
  • Loading branch information
nadbm authored Sep 14, 2019
2 parents 83db48f + b156772 commit 8ddd3ee
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/DataSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default class DataSheet extends PureComponent {
document.removeEventListener('cut', this.handleCut)
document.removeEventListener('copy', this.handleCopy)
document.removeEventListener('paste', this.handlePaste)
document.removeEventListener('keydown', this.handlePaste)
}

componentDidMount () {
Expand Down Expand Up @@ -159,7 +160,13 @@ export default class DataSheet extends PureComponent {

const parse = this.props.parsePaste || defaultParsePaste
const changes = []
const pasteData = parse(e.clipboardData.getData('text/plain'))
let pasteData = []
if (window.clipboardData && window.clipboardData.getData) { // IE
pasteData = parse(window.clipboardData.getData('Text'))
} else if (e.clipboardData && e.clipboardData.getData) {
pasteData = parse(e.clipboardData.getData('text/plain'))
}

// in order of preference
const { data, onCellsChanged, onPaste, onChange } = this.props
if (onCellsChanged) {
Expand Down Expand Up @@ -405,6 +412,17 @@ export default class DataSheet extends PureComponent {
forceEdit: false
})

var ua = window.navigator.userAgent
var isIE = /MSIE|Trident/.test(ua)
// Listen for Ctrl + V in case of IE
if (isIE) {
document.addEventListener('keydown', (e) => {
if ( (e.keyCode === 86 || e.which === 86) && e.ctrlKey){
this.handlePaste(e)
}
});
}

// Keep listening to mouse if user releases the mouse (dragging outside)
document.addEventListener('mouseup', this.onMouseUp)
// Listen for any outside mouse clicks
Expand Down

0 comments on commit 8ddd3ee

Please sign in to comment.