diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-03-28 16:04:43 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-03-28 16:04:43 +0100 |
| commit | b94cad3271d8269b5965d0096ce5564abed9ad53 (patch) | |
| tree | 5e152257d0fae8046557433cb8d57ca640cfaaea /scraper/client/common | |
| parent | eb79e2827ad0ca03f410b7beef77bcaffb28daea (diff) | |
better autocomplete
Diffstat (limited to 'scraper/client/common')
| -rw-r--r-- | scraper/client/common/autocomplete.component.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/scraper/client/common/autocomplete.component.js b/scraper/client/common/autocomplete.component.js index a619e2c8..e6c638eb 100644 --- a/scraper/client/common/autocomplete.component.js +++ b/scraper/client/common/autocomplete.component.js @@ -84,7 +84,8 @@ class Autocomplete extends Component { } handleKeyDown(e) { - let id + let name + console.log(e.keyCode) switch (e.keyCode) { case 27: // escape e.preventDefault() @@ -104,10 +105,13 @@ class Autocomplete extends Component { selected: (this.state.selected + 1) % this.state.matches.length }) return false - case 13: // enter - id = this.state.matches[this.state.selected] + case 13: // enter - select from the list + name = this.state.matches[this.state.selected] e.preventDefault() - this.handleSelect(id) + this.handleSelect(name, true) + return false + case 9: // tab - keep the unverified text + this.handleSelect(this.state.q, false) return false default: break @@ -161,9 +165,9 @@ class Autocomplete extends Component { }) } - handleSelect(name) { - console.log('select', name) - if (this.props.onSelect) this.props.onSelect(name) + handleSelect(name, valid) { + console.log('select', name, valid) + if (this.props.onSelect) this.props.onSelect(name, valid) this.setState({ q: name, selected: 0, matches: [] }) } @@ -180,7 +184,7 @@ class Autocomplete extends Component { <div key={i} className={selected === i ? 'selected' : ''} - onClick={() => this.handleSelect(match)} + onClick={() => this.handleSelect(match, true)} onMouseEnter={() => this.setState({ selected: i })} > {label} |
