Skip to content
Permalink
Browse files

fix(ui): fix input and textarea focus issue

fix #1987
  • Loading branch information...
korhaliv committed Apr 16, 2019
1 parent a678706 commit a5798d479b04ee762d113d67a8525a31fdf89d4b
Showing with 11 additions and 22 deletions.
  1. +6 −11 renderer/components/UI/Input.js
  2. +5 −11 renderer/components/UI/TextArea.js
@@ -239,12 +239,10 @@ class Input extends React.Component {
field={field}
fieldState={fieldState}
onBlur={e => {
setTouched()
// Make the state aware that the element is now focused.
const newHasFocus = document.activeElement === this.inputRef.current
if (hasFocus !== newHasFocus) {
this.setState({ hasFocus: newHasFocus })
}
// set touched to true to enforce validity highlight
setTouched(true)
// Make the state aware that the element is no longer focused.
this.setState({ hasFocus: false })
if (onBlur) {
onBlur(e)
}
@@ -256,11 +254,8 @@ class Input extends React.Component {
}
}}
onFocus={e => {
// Make the state aware that the element is no longer focused.
const newHasFocus = document.activeElement === this.inputRef.current
if (hasFocus !== newHasFocus) {
this.setState({ hasFocus: newHasFocus })
}
// Make the state aware that the element is now focused.
this.setState({ hasFocus: true })
if (onFocus) {
onFocus(e)
}
@@ -201,12 +201,9 @@ class TextArea extends React.PureComponent {
field={field}
fieldState={fieldState}
onBlur={e => {
setTouched()
// Make the state aware that the element is now focused.
const newHasFocus = document.activeElement === this.inputRef.current
if (hasFocus !== newHasFocus) {
this.setState({ hasFocus: newHasFocus })
}
setTouched(true)
// Make the state aware that the element is no longer focused.
this.setState({ hasFocus: false })
if (onBlur) {
onBlur(e)
}
@@ -218,11 +215,8 @@ class TextArea extends React.PureComponent {
}
}}
onFocus={e => {
// Make the state aware that the element is no longer focused.
const newHasFocus = document.activeElement === this.inputRef.current
if (hasFocus !== newHasFocus) {
this.setState({ hasFocus: newHasFocus })
}
// Make the state aware that the element is now focused.
this.setState({ hasFocus: true })
if (onFocus) {
onFocus(e)
}

0 comments on commit a5798d4

Please sign in to comment.
You can’t perform that action at this time.