Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
fix syncing between react and DOM urlbar focus/select
Browse files Browse the repository at this point in the history
previously it seems that the urlbar was getting selected
every time the react select state was updated; yet then the
react selected state would be updated to false.

this may fix #5529

Auditors: @bbondy

Test Plan:
follow Alex's test steps in #5529
and check that the first character is not deleted.
  • Loading branch information
diracdeltas committed Nov 12, 2016
1 parent 08bfc40 commit e6cc117
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions js/components/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class UrlBar extends ImmutableComponent {
return this.props.urlbar.get('focused')
}

updateDOMInputFocus (focused) {
if (this.urlInput && focused) {
updateDOMInputFocus () {
if (this.urlInput && this.isFocused()) {
this.focus()
}
}
Expand Down Expand Up @@ -146,7 +146,7 @@ class UrlBar extends ImmutableComponent {
}
// this can't go through appActions for some reason
// or the whole window will reload on the first page request
this.updateDOMInputFocus(false)
this.updateDOMInputFocus()
this.clearSearchEngine()
}
windowActions.setRenderUrlBarSuggestions(false)
Expand Down Expand Up @@ -371,12 +371,16 @@ class UrlBar extends ImmutableComponent {
}
}
}
// Manually sync some react state with DOM state
if (this.isFocused() !== prevProps.urlbar.get('focused')) {
this.updateDOMInputFocus()
}
if (this.isSelected() !== prevProps.urlbar.get('selected')) {
this.select()
windowActions.setUrlBarSelected(false)
const selected = this.isSelected()
if (selected) {
this.select()
}
windowActions.setUrlBarSelected(selected)
}
}

Expand Down

0 comments on commit e6cc117

Please sign in to comment.