Skip to content

Commit 9f4d2f5

Browse files
committedOct 24, 2018
Improved edit-word demo
1 parent 31f6163 commit 9f4d2f5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

‎edit-word/main.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ customElements.define('edit-word',
4040
shadowRoot.appendChild(span);
4141

4242
span.textContent = this.textContent;
43+
input.value = this.textContent;
4344

4445
form.appendChild(input);
4546
form.style.display = 'none';
@@ -54,18 +55,20 @@ customElements.define('edit-word',
5455
span.style.display = 'none';
5556
form.style.display = 'inline-block';
5657
input.focus();
58+
input.setSelectionRange(0, input.value.length)
5759
});
5860

5961
form.addEventListener('submit', e => {
62+
updateDisplay();
6063
e.preventDefault();
6164
});
62-
input.addEventListener('change', updateDisplay);
65+
66+
input.addEventListener('blur', updateDisplay);
6367

6468
function updateDisplay() {
6569
span.style.display = 'inline-block';
6670
form.style.display = 'none';
6771
span.textContent = input.value;
68-
input.value = '';
6972
input.style.width = span.clientWidth + 'px';
7073
}
7174
}

0 commit comments

Comments
 (0)