Skip to content

TodayIDid - 2023-04-07

Posted on:April 8, 2023 at 08:00 AM

#TID:

A feature I worked on today was the “Main focus” feature. The Momentum app has an input field underneath the question, “What is your main focus for today?” Once you fill out the text input field (e.g. “Finally finish this Momentum clone coding!”) and hit enter, the prompting question and the input field disappears, and a checkbox with that said task is rendered instead.

Honestly, it’s not too difficult a task, but I honestly was initially at a loss as to how to develop this feature. Something that helped me immensely was to take that said feature and break it down even more:

Breakdown of this “Main Focus” prompt/rendering feature:

I was quite happy with how I was able to break down this simple feature into even more manageable chunks. Thanks to this, I quickly realized that my eventListener’s first requirement — “a) the focus is on the input (rather than focused on another element)” — is easily resolved by simply adding the eventlistener directly on the <input> element. That way, even if I press the enter key on another element, the eventListener does not fire.

While creating the eventListener, I was trying to think of which event-type the eventListener should listen to. Now, I am still on my journey of mastering event-types and eventlisteners — the most I’ve used thus far is the click event — so I went ahead to MDN and searched for different event types… And voila, I remembered that I need to be listening to the keydown event and ONLY having the callback function fire if the event.key === 'Enter' AND if the input.value.length > 0 to make sure the eventListener doesn’t call the callback if the enter was pressed with a blank input. :-)

You can witness my joy of getting my #TID accomplished through this short video snippet.

Next Steps

Affirmation of the day:

Looking things up on MDN does NOT make me a non-developer. I’m a better developer because of my research & reference skills.