Browse Source

added focus on keypress

master
fraz 2 years ago
parent
commit
6da163ee77
1 changed files with 4 additions and 3 deletions
  1. +4
    -3
      src/Components/Inputs.js

+ 4
- 3
src/Components/Inputs.js View File

@@ -12,6 +12,7 @@ class Inputs extends React.Component{
this.setSelected = this.setSelected.bind(this)
this.keyPressHandler = this.keyPressHandler.bind(this)
this.clickSuggestion = this.clickSuggestion.bind(this)
this.divElement = {}
}

changeHandler = (e) => {
@@ -33,13 +34,13 @@ class Inputs extends React.Component{
e.preventDefault()
this.setState({
selectedSuggestion: i > 0 ? i - 1 : i
})
}, () => () => this.divElement[this.state.selectedSuggestion].focus())
return
case 'ArrowDown':
e.preventDefault()
this.setState({
selectedSuggestion: i < maxlim ? i + 1 : i
})
}, () => this.divElement[this.state.selectedSuggestion].focus())
return
default:
return undefined
@@ -93,7 +94,7 @@ class Inputs extends React.Component{
if(i === this.state.selectedSuggestion)
highlighted = "highlighted"
display.push(
<div className={"autocomplete-suggestion "+ highlighted} key={suggestion} suggestion={suggestion} onClick={this.clickSuggestion} onKeyPress={this.suggestionPress} tabIndex={0} id={"suggestion-"+i+1} role="option">{suggestion}</div>
<div className={"autocomplete-suggestion "+ highlighted} onKeyDown={this.keyPressHandler} ref={ divElement => this.divElement[i] = divElement} key={suggestion} suggestion={suggestion} onClick={this.clickSuggestion} onKeyPress={this.suggestionPress} tabIndex={0} id={"suggestion-"+i+1} role="option">{suggestion}</div>
)
})
return display


Loading…
Cancel
Save