Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Commit 1715443

Browse files
CMTegnerwhichsteveyp
authored andcommitted
Prevent autocomplete when clicking a non-focusable input (#68)
This is to prevent autocomplete from happening when clicking a disabled input field. The `ownerDocument` check is paranoid since I couldn't find any documentation as to when support was added to WebKit/Blink. It's in the DOM level 2 spec, so support should be widespread. The alternative to this fix is to explicitly check `input.disabled`. http://quirksmode.org/dom/core/#t136 https://developer.mozilla.org/en-US/docs/Web/API/Node/ownerDocument
1 parent 7626ec0 commit 1715443

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/Autocomplete.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,13 @@ let Autocomplete = React.createClass({
297297
this.setState({ isOpen: true })
298298
},
299299

300+
isInputFocused () {
301+
var el = React.findDOMNode(this.refs.input)
302+
return el.ownerDocument && (el === el.ownerDocument.activeElement)
303+
},
304+
300305
handleInputClick () {
301-
if (this.state.isOpen === false)
306+
if (this.isInputFocused() && this.state.isOpen === false)
302307
this.setState({ isOpen: true })
303308
},
304309

0 commit comments

Comments
 (0)