Skip to content

Instantly share code, notes, and snippets.

View surajitbasak109's full-sized avatar
💭
Working from Office

Surajit Basak surajitbasak109

💭
Working from Office
View GitHub Profile
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: [] });
}
hanldeKeydown(evt) {
// ... more code ...
if (evt.keyCode === 8) {
this.setState({ item: { name: "", code: "", rate: "", unit: "" } });
}
}
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: [] });
}
}
<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>;
{searchItems.length > 0 && (
<SearchItemsList
searchItems={searchItems}
cursor={cursor} />
)}
<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"
/>
constructor(props) {
super(props);
this.state = {
item: {
//...more code...
},
cursor: 0,
// ...more code...
};
// ...more code...
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
constructor(props) {
super(props);
this.state = {
item: {
// ... more code ...
},
cursor: 0,
// ... more code ...
};
// ... more code ...
<label htmlFor="autocomplete">Item Name</label>
<input
type="text"
id="autocomplete"
onChange={this.autocomplete}
onKeyUp={this.hanldeKeyup}
value={name}
className="custom-input form-control"
/>