File tree 1 file changed +5
-2
lines changed 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ customElements.define('edit-word',
40
40
shadowRoot . appendChild ( span ) ;
41
41
42
42
span . textContent = this . textContent ;
43
+ input . value = this . textContent ;
43
44
44
45
form . appendChild ( input ) ;
45
46
form . style . display = 'none' ;
@@ -54,18 +55,20 @@ customElements.define('edit-word',
54
55
span . style . display = 'none' ;
55
56
form . style . display = 'inline-block' ;
56
57
input . focus ( ) ;
58
+ input . setSelectionRange ( 0 , input . value . length )
57
59
} ) ;
58
60
59
61
form . addEventListener ( 'submit' , e => {
62
+ updateDisplay ( ) ;
60
63
e . preventDefault ( ) ;
61
64
} ) ;
62
- input . addEventListener ( 'change' , updateDisplay ) ;
65
+
66
+ input . addEventListener ( 'blur' , updateDisplay ) ;
63
67
64
68
function updateDisplay ( ) {
65
69
span . style . display = 'inline-block' ;
66
70
form . style . display = 'none' ;
67
71
span . textContent = input . value ;
68
- input . value = '' ;
69
72
input . style . width = span . clientWidth + 'px' ;
70
73
}
71
74
}
You can’t perform that action at this time.
0 commit comments