1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Fix to work inputting by IME on search

This commit is contained in:
asmsuechan
2017-10-11 00:13:44 +09:00
parent 6a3062709c
commit b4f5913a80

View File

@@ -18,7 +18,10 @@ class TopBar extends React.Component {
this.state = { this.state = {
search: '', search: '',
searchOptions: [], searchOptions: [],
isSearching: false isSearching: false,
isAlphabet: false,
isIME: false,
isConfirmTranslation: false
} }
this.focusSearchHandler = () => { this.focusSearchHandler = () => {
@@ -34,12 +37,53 @@ class TopBar extends React.Component {
ee.off('top:focus-search', this.focusSearchHandler) ee.off('top:focus-search', this.focusSearchHandler)
} }
handleSearchChange (e) { handleKeyDown (e) {
// reset states
this.setState({
isAlphabet: false,
isIME: false
})
if (e.keyCode <= 90) {
this.setState({
isAlphabet: true,
isIME: false
})
} else if (e.keyCode === 229) {
this.setState({
isIME: true
})
}
}
handleKeyUp (e) {
if (this.state.isIME && e.keyCode === 13) {
this.setState({
isConfirmTranslation: true
})
let { router } = this.context let { router } = this.context
router.push('/searched') router.push('/searched')
this.setState({ this.setState({
search: this.refs.searchInput.value search: this.refs.searchInput.value
}) })
} else {
this.setState({
isConfirmTranslation: false
})
}
}
handleSearchChange (e) {
if (this.state.isAlphabet || this.state.isConfirmTranslation) {
let { router } = this.context
router.push('/searched')
} else {
e.preventDefault()
}
this.setState({
search: this.refs.searchInput.value
})
} }
handleSearchFocus (e) { handleSearchFocus (e) {
@@ -93,6 +137,8 @@ class TopBar extends React.Component {
ref='searchInput' ref='searchInput'
value={this.state.search} value={this.state.search}
onChange={(e) => this.handleSearchChange(e)} onChange={(e) => this.handleSearchChange(e)}
onKeyDown={(e) => this.handleKeyDown(e)}
onKeyUp={(e) => this.handleKeyUp(e)}
placeholder='Search' placeholder='Search'
type='text' type='text'
className='searchInput' className='searchInput'