PolymerElements / iron-menu-behavior

Accessible menu behavior
18 stars 28 forks source link

_focusNext & _focusPrevious will skip focusing if the menu has only 1 item #66

Closed qqiao closed 8 years ago

qqiao commented 8 years ago

Description

_focusNext & _focusPrevious will skip if the menu has only 1 item If an element that uses IronMenuBehavior has only one child item, and the item isn't focused or selected initially, then there is no way that the user can focus the item using up/down keys.

Expected outcome

User will still be able to focus the item even if it is a 1 item menu

Actual outcome

On single item menus, the sole item cannot be focused by keyboard input

Live Demo

Item 0

Steps to reproduce

  1. Change one of the examples in the demo page to above
  2. Try to focus item 0 with keyboard

The reason for this is because the loop counter of the the for-loop in both _focusNext and _focusPrevious starts at 1, so if there's only 1 item, it will never get focused.

Browsers Affected

qqiao commented 8 years ago

Upon more investigation, I think the issue is with _onFocus, specifically around line 269.

In _onFocus, we check if there's 1 item, we'll then call _focusNext, which will skip over that item, thus in the case of a 1 item menu, nothing will gain initial focus.

bicknellr commented 8 years ago

Fixed by #67; released as v1.1.8 .