Skip to content

Commit

Permalink
Improve accessibility (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfactotum authored Nov 15, 2023
1 parent 690b1e4 commit 5c25354
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# TodoMVC in less than 100 lines of vanilla JavaScript
# TodoMVC in ~100 lines of vanilla JavaScript

Or: How I Learned to Stop Worrying and Love the DOM

Expand Down Expand Up @@ -119,7 +119,7 @@ What are some other advantages of storing data in the DOM? For one, remember tha
## The result
To experiment with this approach, I made a [TodoMVC](https://todomvc.com) implementation. It contains only 98 lines of code in vanilla JavaScript, which is 1kb minified and gzipped.
To experiment with this approach, I made a [TodoMVC](https://todomvc.com) implementation. It contains only 101 lines of code in vanilla JavaScript, which is 1kb minified and gzipped.
But I'm cheating a little with that number. Because some bits aren't implemented with JavaScript at all. For example, filtering items by completion state is done using just CSS:
Expand Down
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ <h1>todos</h1>
<input type="text" placeholder="What needs to be done?" autofocus>
<div id="toggle-all" role="checkbox" aria-checked="false" tabindex="0" title="Mark all as complete" hidden><div aria-hidden="true" style="font-size: 22px; transform: rotate(90deg)"></div></div>
</form>
<div id="todos"></div>
<div id="todos" role="list"></div>
<form id="footer" hidden>
<div style="flex: 1 1 0" id="count"></div>
<div id="filters">
Expand Down Expand Up @@ -228,9 +228,12 @@ <h1>todos</h1>
#root = this.attachShadow({ mode: 'closed' })
constructor() {
super()
this.attachInternals().role = 'listitem'
const template = document.querySelector('#todo-item-template')
this.#root.append(template.content.cloneNode(true))

this.#root.querySelector('#checkbox').addEventListener('keydown', e =>
e.key === ' ' ? (e.preventDefault(), e.target.click()) : null)
this.#root.querySelector('#checkbox').addEventListener('click', () => {
if (this.hasAttribute('completed')) this.removeAttribute('completed')
else this.setAttribute('completed', '')
Expand Down

0 comments on commit 5c25354

Please sign in to comment.