Skip to content

Commit

Permalink
fix: react-mentions inside react-new-window (#531)
Browse files Browse the repository at this point in the history
Allow input to call onChange when inside a new window
  • Loading branch information
ThibautMarechal authored Jan 20, 2022
1 parent 3294221 commit 1cb4c22
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/MentionsInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
mapPlainTextIndex,
readConfigFromChildren,
spliceString,
isIE,
isNumber,
keys,
omit,
Expand Down Expand Up @@ -471,13 +472,15 @@ class MentionsInput extends React.Component {
// Handle input element's change event
handleChange = (ev) => {
isComposing = false
// if we are inside iframe, we need to find activeElement within its contentDocument
const currentDocument =
(document.activeElement && document.activeElement.contentDocument) ||
document
if (currentDocument.activeElement !== ev.target) {
// fix an IE bug (blur from empty input element with placeholder attribute trigger "input" event)
return
if(isIE()){
// if we are inside iframe, we need to find activeElement within its contentDocument
const currentDocument =
(document.activeElement && document.activeElement.contentDocument) ||
document
if (currentDocument.activeElement !== ev.target) {
// fix an IE bug (blur from empty input element with placeholder attribute trigger "input" event)
return
}
}

const value = this.props.value || ''
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { default as spliceString } from './spliceString'
export { default as makeMentionsMarkup } from './makeMentionsMarkup'
export { default as iterateMentionsMarkup } from './iterateMentionsMarkup'
export { default as getSubstringIndex } from './getSubstringIndex'
export { default as isIE } from './isIE'
export { default as isNumber } from './isNumber'
export { default as merge } from './merge'
export { default as omit } from './omit'
Expand Down
3 changes: 3 additions & 0 deletions src/utils/isIE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const isIE = () => !!document.documentMode

export default isIE

1 comment on commit 1cb4c22

@vercel
Copy link

@vercel vercel bot commented on 1cb4c22 Jan 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.