Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Should prevent keypress actions when event is generated by a form element #2960

Closed
exocom opened this issue May 23, 2015 · 1 comment
Closed
Assignees
Milestone

Comments

@exocom
Copy link

exocom commented May 23, 2015

It would be nice if the keydownListener would NOT fire if the event comes is generated by a form element. IE input, select, textarea.

For example when using md radio group with a nested form in each. When the LEFT_ARROW is pressed inside of the nested input, the md radio group is switched.

P.S. I believe this will apply to ALL of the arrow events on every material directive, not just md-radio-groups.

<md-radio-group ng-model="model.hasInsurance">
    <md-radio-button value="Basic">Basic Form</md-radio-button>
    <div ng-if="model.hasInsurance === 'basic'">
        <!-- Pushing the left arrow inside the input triggers this div to hide :( -->
        <input type="text" ng-model="account.insurance.id" required>
        <input type="text" ng-model="account.insurance.id" required>
    </div>

    <md-radio-button value="Advanced">Basic Form</md-radio-button>
    <div ng-if="model.hasInsurance === 'Advanced'">
        <!-- Pushing the left arrow inside the inputs triggers this div to hide :( -->
        <input type="text" ng-model="account.insurance.id" required>
        <input type="text" ng-model="account.insurance.id" required>
        <input type="text" ng-model="account.insurance.id" required>
        <input type="text" ng-model="account.insurance.id" required>
        <input type="text" ng-model="account.insurance.id" required>
        <input type="text" ng-model="account.insurance.id" required>
        <input type="text" ng-model="account.insurance.id" required>
    </div>
</md-radio-group>

Here is my current hack

function keydownListener(ev) {
  var keyCode = ev.which || ev.keyCode;
  var isValidElement = true; 
    switch (ev.originalEvent.originalTarget.tagName){
      case 'INPUT':
      case 'SELECT':
      case 'TEXTAREA':
        isValidElement = false;
      break;
    }
    if(isValidElement) {
       switch(keyCode) {
            case $mdConstant.KEY_CODE.LEFT_ARROW:
            case $mdConstant.KEY_CODE.UP_ARROW:
              ev.preventDefault();
              rgCtrl.selectPrevious();
              setFocus();
              break;

            case $mdConstant.KEY_CODE.RIGHT_ARROW:
            case $mdConstant.KEY_CODE.DOWN_ARROW:
              ev.preventDefault();
              rgCtrl.selectNext();
              setFocus();
              break;

            case $mdConstant.KEY_CODE.ENTER:
              var form = angular.element($mdUtil.getClosest(element[0], 'form'));
              if (form.length > 0) {
                form.triggerHandler('submit');
              }
              break;
          }
          break;
    }
@ThomasBurleson ThomasBurleson modified the milestone: Backlog May 27, 2015
@Clan-Utility
Copy link

Facing the same problem. I put a <input> after each <md-radio-button> and would like to use the arrow inside rather than navigation through <md-radio-button>s.

Is there a general way to disable arrow key navigation for <md-radio-button>?

@ThomasBurleson ThomasBurleson modified the milestones: 0.12.0, Backlog Sep 4, 2015
@ThomasBurleson ThomasBurleson modified the milestones: 1.0-rc1, 1.0-rc2, 1.0-rc3 Oct 27, 2015
@ThomasBurleson ThomasBurleson modified the milestones: 1.0-rc3, 1.0-rc4 Nov 7, 2015
@ThomasBurleson ThomasBurleson modified the milestones: 1.0-rc4, 1.0-rc5 Nov 16, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants