How to toggle styles to show if a button is selected/not

So after doing some digging around the forum, it seems that there is no official way to trigger an event when an input field is in focus, but I found a workaround here.