Keyboard Shortcut For Moving Focus To Form Using Alpine.js
bennadel.com·13h
Flag this post

For the past 15 years (or so), I’ve used the autofocus attribute to move cursor focus to a given form input control upon page load. But, as I’ve become more attune to accessibility (a11y) concerns, I’ve become hesitant about stealing focus and potentially disrupting the feedback provided by assistive technologies. That said, I still really want that ease-of-access for myself. As such, I’ve added a custom Alpine.js directive to Big Sexy Poems that will move focus to the first form input when I press the (f) key.

Using keyboard shortcuts to move focus is a common pattern. Sites, such as GitHub, that provide a global search input, will use the (/) key to move focus to the…

Similar Posts

Loading similar posts...