Alpine.js Focus Plugin | Laravel News


Caleb Porzio released a new focus plugin for Apline.js, which allows you to manage focus on a page:

What’s neat about this plugin is that it allows you to trap focus within an element via the x-trap directive. Here’s a demo:

The focus plugin also supports nesting dialogs, which tracks newly trapped elements and tracks the previously focused element. When the element is no longer trapped, it restores focus to where it was initially, allowing for intuitive nested tabbing:

Nested focus example

Other features include arrow focus navigation between elements and an advanced focus API to help control focus on a granular level. Check out the official Focus Alpine.js documentation if you’d like to learn more.

Source link

Leave a reply

Please enter your comment!
Please enter your name here