@@ -26,22 +26,17 @@ export class ToDoList extends MobxLitElement {
26
26
27
27
static styles = css `
28
28
${ commonStylesheet }
29
- h2 {
30
- margin:20px;
31
- padding-top:20px;
32
- display: block;
33
- font-size: 1.5em;
34
- margin-inline-start: 20px;
35
- font-weight: bold;
36
- line-height: 1.5em
37
- }
29
+
38
30
.innerList {
39
31
padding: 1px;
40
32
}
41
33
.completed {
42
34
text-decoration-line: line-through;
43
35
color: #777;
44
36
}
37
+ .feedback {
38
+ margin-left:20px;
39
+ }
45
40
ul {
46
41
list-style-type: none;
47
42
}
@@ -111,18 +106,22 @@ export class ToDoList extends MobxLitElement {
111
106
</ ul >
112
107
</ div >
113
108
`
114
- const caughtUpMessage = html ` < p > You're all caught up!</ p > `
109
+ const caughtUpMessage = html ` < p class =" feedback " > You're all caught up!</ p > `
115
110
const renderPlaceholder =
116
111
items . length > 0 ? renderTodoList : caughtUpMessage
117
112
const outputHeader = html `< h2 > To Do</ h2 > `
113
+
118
114
// Main output of the component:
119
115
return html `
120
116
< div class ="container taskContainer ">
121
- ${ outputHeader } ${ this . _feedback } ${ renderPlaceholder }
117
+ ${ outputHeader }
118
+ < p class ="feedback "> ${ this . _feedback } </ p >
119
+
120
+ ${ renderPlaceholder }
122
121
123
122
< div class ="inputContainer ">
124
123
< input id ="newitem " class ="input-task " aria-label ="New item " />
125
- < button @click =${ this . addToDo } > Add</ button >
124
+ < button id =" btnAddTodo " @click =${ this . addToDo } > Add</ button >
126
125
</ div >
127
126
< br />
128
127
@@ -132,6 +131,8 @@ export class ToDoList extends MobxLitElement {
132
131
`
133
132
}
134
133
134
+
135
+
135
136
toggleCompleted ( item : Task ) {
136
137
item . completed = ! item . completed
137
138
this . requestUpdate ( )
@@ -190,3 +191,18 @@ export class ToDoList extends MobxLitElement {
190
191
}
191
192
}
192
193
}
194
+
195
+ // Get the input field
196
+ var input = document . getElementById ( "newitem" ) ;
197
+
198
+ // Execute a function when the user presses a key on the keyboard
199
+ input ?. addEventListener ( "keypress" , function ( event ) {
200
+ // If the user presses the "Enter" key on the keyboard
201
+ if ( event . key === "Enter" ) {
202
+ // Cancel the default action, if needed
203
+ event . preventDefault ( ) ;
204
+ // Trigger the button element with a click
205
+ console . log ( "okay!" )
206
+ document . getElementById ( "btnAddTodo" ) ?. click ( ) ;
207
+ }
208
+ } ) ;
0 commit comments