@@ -105,7 +105,6 @@ class UserSettingsElement extends HTMLElement {
105105 <user-settings
106106 data-action =" loading:user-profile#disable" >
107107 </user-settings >
108- <button >
109108</user-profile >
110109```
111110
@@ -191,10 +190,10 @@ We find it very common for developers to return to habits and use `querySelector
191190{{ discouraged }}
192191
193192``` typescript
194- class UserList {
193+ class UserListElement extends HTMLElement {
195194 showAdmins() {
196195 // Just need to get admins here...
197- for (const user of this .querySelector (' [data-is-admin]' )) {
196+ for (const user of this .querySelector (' [data-is-admin]' )) {
198197 user .hidden = false
199198 }
200199 }
@@ -205,11 +204,11 @@ class UserList {
205204
206205``` typescript
207206class UserList {
208- @targets admins! : Element [],
207+ @targets admins! : HTMLElement []
209208
210209 showAdmins() {
211210 // Just need to get admins here...
212- for (const user of this .admins ) {
211+ for (const user of this .admins ) {
213212 user .hidden = false
214213 }
215214 }
@@ -229,7 +228,7 @@ For example let's say we have a list of filter checkboxes and checking the "all"
229228``` typescript
230229@controller
231230class UserFilter {
232- @targets filters! : Element []
231+ @targets filters! : HTMLInputElement []
233232
234233 get allFilter() {
235234 return this .filters .find (el => el .matches (' [data-filter="all"]' ))
@@ -249,18 +248,18 @@ class UserFilter {
249248
250249``` html
251250<user-list >
252- <input type =" checkbox"
251+ <label >< input type =" checkbox"
253252 data-action =" change:user-list.filter"
254253 data-target =" user-list.filters"
255- data-filter =" all" >Show all</button >
256- <input type =" checkbox"
254+ data-filter =" all" >Show all</label >
255+ <label >< input type =" checkbox"
257256 data-action =" change:user-list.filter"
258257 data-target =" user-list.filters"
259- data-filter =" new" >New Users</button >
260- <input type =" checkbox"
258+ data-filter =" new" >New Users</label >
259+ <label >< input type =" checkbox"
261260 data-action =" change:user-list.filter"
262261 data-target =" user-list.filters"
263- data-filter =" admin" >Admins</button >
262+ data-filter =" admin" >Admins</label >
264263 <!-- ... --->
265264</user-filter >
266265```
@@ -272,12 +271,12 @@ While this works well, it could be more easily solved with targets:
272271``` typescript
273272@controller
274273class UserFilter {
275- @targets filters! : Element []
276- @target allFilter! : Element
274+ @targets filters! : HTMLInputElement []
275+ @target allFilter! : HTMLInputElement
277276
278277 filter(event : Event ) {
279278 if (event .target === this .allFilter ) {
280- for (const filter of this .filters ) {
279+ for (const filter of this .filters ) {
281280 if (filter !== this .allFilter ) filter .checked = false
282281 }
283282 }
@@ -289,19 +288,18 @@ class UserFilter {
289288
290289``` html
291290<user-filter >
292- <input type =" checkbox"
291+ <label >< input type =" checkbox"
293292 data-action =" change:user-list.filter"
294293 data-target =" user-list.filters user-list.allFilter"
295- data-filter =" all" >Show all</button >
296- <input type =" checkbox"
294+ data-filter =" all" >Show all</label >
295+ <label >< input type =" checkbox"
297296 data-action =" change:user-list.filter"
298297 data-target =" user-list.filters"
299- data-filter =" new" >New Users</button >
300- <input type =" checkbox"
298+ data-filter =" new" >New Users</label >
299+ <label >< input type =" checkbox"
301300 data-action =" change:user-list.filter"
302301 data-target =" user-list.filters"
303- data-filter =" admin" >Admins</button >
302+ data-filter =" admin" >Admins</label >
304303 <!-- ... --->
305304</user-filter >
306305```
307-
0 commit comments