Skip to content

Instantly share code, notes, and snippets.

@thanapongp
Created October 23, 2019 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thanapongp/c02042e02a6669819bf3bcb4c81530b2 to your computer and use it in GitHub Desktop.
Save thanapongp/c02042e02a6669819bf3bcb4c81530b2 to your computer and use it in GitHub Desktop.
Fixed editItem method
addNewItem(itemName) {
//...
item.getElementsByClassName('edit-button')[0].addEventListener('click', () => this.editItem(item));
}
editItem(item) {
const oldItemName = item.getElementsByClassName('item-name')[0].innerHTML.trim();
const editInput = htmlToElement(`
<input type="text" value="${oldItemName}" placeholder="Enter new item name" class="bg-gray-800 px-4 py-2 rounded block w-full text-gray-200 font-light">
`);
editInput.addEventListener('keyup', e => {
if (e.keyCode === 13) {
this.performEdit(item, editInput)
}
});
const itemNameEl = item.getElementsByClassName('item-name')[0];
const editButtonEl = item.getElementsByClassName('edit-button')[0];
insertElementAfter(editInput, itemNameEl);
itemNameEl.classList.add('hidden');
editButtonEl.classList.add('hidden');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment