This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hanldeKeydown(evt) { | |
// ... more code ... | |
} | |
selectItem(id) { | |
const { searchItems } = this.state; | |
let selectedItem = searchItems.find(item => item.code === id); | |
const { code, name, unit, rate } = selectedItem; | |
this.setState({ item: { code, name, unit, rate }, searchItems: [] }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hanldeKeydown(evt) { | |
// ... more code ... | |
if (evt.keyCode === 8) { | |
this.setState({ item: { name: "", code: "", rate: "", unit: "" } }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hanldeKeydown(evt) { | |
const { cursor, searchItems } = this.state; | |
// ... more code ... | |
if (evt.keyCode === 13) { | |
let currentItem = searchItems[cursor]; | |
if (currentItem !== undefined) { | |
const { name, code, rate, unit } = currentItem; | |
this.setState({ item: { name, code, rate, unit }, searchItems: [] }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul className="list-group"> | |
{searchItems.map((item, idx) => ( | |
<li | |
className={cursor === idx ? "active list-group-item" : "list-group-item"} | |
key={idx} | |
> | |
{item.name} | |
</li> | |
))} | |
</ul>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{searchItems.length > 0 && ( | |
<SearchItemsList | |
searchItems={searchItems} | |
cursor={cursor} /> | |
)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<label htmlFor="autocomplete">Item Name</label> | |
<input | |
type="text" | |
id="autocomplete" | |
onChange={this.autocomplete} | |
onKeyUp={this.hanldeKeyup} | |
onKeyDown={this.hanldeKeydown} | |
value={name} | |
className="custom-input form-control" | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constructor(props) { | |
super(props); | |
this.state = { | |
item: { | |
//...more code... | |
}, | |
cursor: 0, | |
// ...more code... | |
}; | |
// ...more code... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hanldeKeyup(evt) { | |
//...more code... | |
} | |
hanldeKeydown(evt) { | |
const { cursor, searchItems } = this.state; | |
// arrow up/down button should select next/previous list element | |
if (evt.keyCode === 38 && cursor > 0) { | |
this.setState(prevState => ({ | |
cursor: prevState.cursor - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constructor(props) { | |
super(props); | |
this.state = { | |
item: { | |
// ... more code ... | |
}, | |
cursor: 0, | |
// ... more code ... | |
}; | |
// ... more code ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<label htmlFor="autocomplete">Item Name</label> | |
<input | |
type="text" | |
id="autocomplete" | |
onChange={this.autocomplete} | |
onKeyUp={this.hanldeKeyup} | |
value={name} | |
className="custom-input form-control" | |
/> |