medialize / ally.js

JavaScript library to help modern web applications with accessibility concerns
http://allyjs.io/
MIT License
1.53k stars 83 forks source link

[ally.element.focus] add option to prevent scrolling #138

Closed rodneyrehm closed 7 years ago

rodneyrehm commented 8 years ago

In WICG: Improve element.focus method @aFarkas explains his approach to get around having to use ally.when.focusable:

I'm trying to solve the problem different. Instead of waiting until the element is in viewport. I collect the scroll positions of all ancestors, focus the element and then restore the scroll positions.

This approach is far more efficient than calculating the target element's visible area on each animation frame. For this to work the element has to be focusable right away (which is not the case for ally.when.focusable), therefore this feature can't replace ally.when.focusable completely.

This would be an optional behavior:

ally.element.focus(target, {
  preventScrolling: true,
});

Before we .focus() the element, we collect the parents' .scrollTop and .scrollLeft and restore those values in the focus event handler.