Skip to content

Commit a69c6fe

Browse files
committed
Clear the selection after transitions to avoid the child being selected due to multiple clicks.
1 parent 058551a commit a69c6fe

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/ReactCSSTransitionReplace.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import React from 'react'
88
import ReactDOM from 'react-dom'
99
import PropTypes from 'prop-types'
10-
import raf from 'dom-helpers/util/requestAnimationFrame'
1110
import chain from 'chain-function'
1211
import warning from 'warning'
1312

13+
import raf from 'dom-helpers/util/requestAnimationFrame'
14+
import { clearSelection } from './utils/dom-helpers'
15+
1416
import ReactCSSTransitionGroupChild from 'react-transition-group/CSSTransitionGroupChild'
1517
import { transitionTimeout } from 'react-transition-group/utils/PropTypes'
1618
import { nameShape } from './utils/PropTypes'
@@ -127,6 +129,11 @@ export default class ReactCSSTransitionReplace extends React.Component {
127129
const keysToLeave = this.keysToLeave
128130
this.keysToLeave = []
129131
keysToLeave.forEach(this.performLeave)
132+
133+
// When the enter completes and the component switches to relative positioning the
134+
// child often gets selected after multiple clicks (at least in Chrome). To compensate
135+
// the current selection is cleared whenever the component updates.
136+
clearSelection()
130137
}
131138

132139
performAppear(key) {

src/utils/dom-helpers.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* global document, window */
2+
3+
export function clearSelection() {
4+
if (document.selection) {
5+
document.selection.empty()
6+
} else if (window.getSelection) {
7+
window.getSelection().removeAllRanges()
8+
}
9+
}

0 commit comments

Comments
 (0)