0

can we open the dropdown when it focus using tab keyword .I want to open the drop down while using tab navigation .

Example if I am in input field (focus to input field ) then if I press tab focus goes to button then drop down , here I want to open the drop down here is my code http://codepen.io/anon/pen/RGKKrd?editors=1010

angular.module('app',[ ]).directive('abc',function(){
  return {
        restrict: 'EA',
        link: function (scope, element ,attr) {
            element.on('keydown', function (evt) {
                if (evt.which ===9) {
                   // evt.preventDefault();
                }
            });
        }
  }
})
1
  • I think it might be helpful.. Link Commented Sep 22, 2016 at 10:46

2 Answers 2

1

You cannot programmatically open a select

See here and here

If you are looking for a workaround here is something I have made. Navigate to the select box with tab key and select your option. The select will stay open as long as it is in focus. It closes on focusout

Here is the directive

angular.module('app',[ ]).directive('abc',function(){
  return {
        restrict: 'EA',
        link: function (scope, element ,attr) {

            element.on('keyup', function (evt) {
                if (evt.which ===9) {
                  var length = element.find("option").length;
                  element.attr("size",length);
                  //element.attr("size",0);
                }
            });

            element.on('keydown', function (evt) {
                if (evt.which ===9) {
                  var length = element.find("option").length;
                  element.attr("size",0);
                  //element.attr("size",0);
                }
            });

        }
  }
})

Not the best solution, but close to what you are looking for.

Sign up to request clarification or add additional context in comments.

Comments

0

You Can not do it, But there is some work around kind of code you can go with. You can change your Js code like this.

  angular.module('app',[ ]).directive('abc',function(){
   return {
    restrict: 'EA',
    link: function (scope, element ,attr) {
        element.on('keydown', function (evt) {
          if (evt.which ===9) {
            //debugger;
            if(document.activeElement.localName==="select"){
                        angular.element(document.activeElement).attr("size",1);
             }
            if(document.activeElement.nextElementSibling!==null && document.activeElement.nextElementSibling.localName==="select"){
            angular.element(document.activeElement.nextElementSibling).attr("size",document.activeElement.nextElementSibling.childElementCount);
            }

            }
        });

    }
  }
 })

This is not a proper solution , just a workaround

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.