Elkfox/Focus

Autofocus classes

Closed this issue · 5 comments

In the original Reinforced popup system, we added an autofocus helper class into the JS to attach autofocus events to inputs in forms inside popups. It would be great if we could integrate this into the new Popups.js

The code went something like this:

  $('.popup-link').on('click', function(event) {
    ... other stuff here
    setTimeout(function(){
      $(popupId + ' .Autofocus').focus();
    }, 300);
  });

I'll add it to the wishlist

Cam commented

+∞

This is now added with [data-auto-focus] by default but can also be defined to something else when creating the new popup:

var loginPopup = new Focus('#accountPopup', { autoFocusSelector: '[name="customer[email]"]'})

In this scenario the field with the name of customer[email] would be auto focused.

Cam commented

Brilliant. You're on fire! 🔥