Angularjs - Focus Management

254 views Asked by At

For an application which is close to be developed completely, requirement is to make focus management.

  1. The popup opened should focus on the first HTML element
  2. On successful login, the focus should point to navigation links.
  3. On every route or page load, the focus could be defined in a generic way if possible.

Any ideas people for getting the above three requirements done for the application.

For 1st one, i can do manually the auto-focus attribute for the form or html element to keep focus on it or any other generic way for achieving it? Also, about the other two points?

Thanks in advance

1

There are 1 answers

0
michelem On

You could start with this directive and apply it when needed, if I understood what you need:

  .directive('autofocus', function() {
     return {
       restrict: 'A',
       link: function($scope, element) {
         element[0].focus();
       }
  };

HTML:

<input type="text" name="test" autofocus>