bem / bem-components

Set of components for sites development
https://bem.info/libraries/classic/bem-components/6.0.0/
Other
333 stars 87 forks source link

menu: two _onKeyDown handler binds if block inited on focus #1381

Closed Guria closed 9 years ago

Guria commented 9 years ago

https://github.com/bem/bem-components/blob/v2/common.blocks/menu/menu.js#L34 https://github.com/bem/bem-components/blob/v2/common.blocks/menu/menu.js#L42 If menu block inited with tab focus _onKeyDown handler bound twice. It causes scrolling two items with one cursor keypress.

dfilatov commented 9 years ago

@Guria I can't reproduce this problem. There are no two bindings to _onKeyDown. The handler on L34 is bound only in case of hasMod('focused'), the handler on L42 is bound when focused mod is being set. As far as I see they are bound in mutually exclusive cases.

Guria commented 9 years ago

Ok, i'll try to prepare a demo.

Guria commented 9 years ago

Here is bemjson to reproduce

({
  block : 'page',
  head : [
    { elem : 'css', url : '_menu-bug.css' },
    { elem : 'js', url : '_menu-bug.js' }
  ],
  content : [
    { block : 'input' },
    {
        block : 'menu',
        mods : { theme : 'islands', size : 'm' },
        content : [
            {
                block : 'menu-item',
                content : '1'
            },
            {
                block : 'menu-item',
                content : '2'
            },
            {
                block : 'menu-item',
                content : '3'
            },
            {
                block : 'menu-item',
                content : '4'
            }
        ]
    }
  ]
})

Press Tab twice, then arrow keys. You shouldn't hover a menu with mouse. In case of menu inited by setting focus from keyboard both handlers would be run: _focused_true handler then _js_inited which will cound second _onKeyDown handler .

dfilatov commented 9 years ago

@Guria I've caught the problem.

qfox commented 9 years ago

PR #1383