Skip to content

Bug(menu): Cannot read property 'disabled' of undefined #3317

Closed

Description

@holo-michael-simarta

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Should not cause an exception

What is the current behavior?

Causes an exception:
Cannot read property 'disabled' of undefined in the following function:

ListKeyManager.prototype._setActiveInWrapMode = function (delta, items) {
    // when active item would leave menu, wrap to beginning or end
    this._activeItemIndex =
        (this._activeItemIndex + delta + items.length) % items.length;
    // skip all disabled menu items recursively until an enabled one is reached
    if (items[this._activeItemIndex].disabled) {
        this._setActiveInWrapMode(delta, items);
    }
    else {
        this.setActiveItem(this._activeItemIndex);
    }
};

What are the steps to reproduce?

Providing a Plunker (or similar) is the best way to get the team to see your issue.
Plunker template: http://plnkr.co/edit/o077B6uEiiIgkC0S06dd

https://material.angular.io/components/component/menu
focus on a menu item then use an arrow key

What is the use-case or motivation for changing an existing behavior?

Need to implement keyboard navigation to go through a menu

Which versions of Angular, Material, OS, browsers are affected?

Angular 2.4.5
Material 2.0.0-beta.2
Windows 10

Chrome Version 56.0.2924.87 (64-bit)
Microsoft Edge 38.14393.0.0
Microsoft EdgeHTML 14.14393

Is there anything else we should know?

Activity

  1. dahaupt commented on Feb 26, 2017

    @dahaupt

    @userexperiences I can't reproduce this (tested in Google Chrome and Microsoft Edge). Can you provide more information?

  2. kara commented on Feb 26, 2017

    @kara
    Contributor

    Yeah, I'm not able to get the error either. More information to repro?

  3. added
    cannot reproduce
    on Feb 26, 2017
  4. holo-michael-simarta commented on Feb 26, 2017

    @holo-michael-simarta
    Author

    Sorry, it's just the up and down arrow keys, make sure the menu is still open and an item is in focus.

  5. HumanMedia commented on Feb 27, 2017

    @HumanMedia

    Yes I can reproduce. One step has been left out.

    • Reload the page
    • Pop the menu open
    • Mousedown on a menu item then without mousing-up, drag the cursor off the menu, then mouseup
    • Use up and down cursor keys
    • TypeError: Unable to get property 'disabled' of undefined or null reference
  6. added
    P5
    help wanted
    and removed
    cannot reproduce
    on Mar 1, 2017
  7. leocaseiro commented on Mar 2, 2017

    @leocaseiro
    Contributor

    I thought the <md-menu> and the <md-select> were sharing the same html. As it doesn't happen with <md-select>.

  8. leocaseiro commented on Mar 2, 2017

    @leocaseiro
    Contributor

    Sorry @kara, I was wondering why mouse users could not see the focus on click or not navigate with keys.
    I normally click on a menu, then, I use keys to navigate.

    PS: If we remove the condition, the menu works nice on mouse click and it seems to fix this issue.

    Update: On Menu AngularJS the behaviour is open on click, then focus by default.

  9. dahaupt commented on Mar 2, 2017

    @dahaupt

    @leocaseiro Removing the condition fixes the problem, but the behavior is not perfect because the first focused element will stay active if the mouse hovers over another item. In material1 it works nice, you are right.

  10. crisbeto commented on Mar 4, 2017

    @crisbeto
    Member

    I ran into this while working on another issue. The problem is that we have a check for null a little bit down, but the _activeItemIndex is undefined by default. I've fixed it here, but I'll backport it since it's a quick fix and the other PR may take longer to go through.

  11. self-assigned this
    on Mar 4, 2017
  12. added a commit that references this issue on Mar 4, 2017
    1f87cfc
  13. added a commit that references this issue on Mar 7, 2017
    842896b
  14. added a commit that references this issue on Mar 8, 2017
    787a644
  15. added a commit that references this issue on Apr 16, 2017
    ac476e4
  16. angular-automatic-lock-bot commented on Sep 5, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  17. locked and limited conversation to collaborators on Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P5help wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions