From 4942fce97f0d97c2edb18a4c8396c428c4b98af6 Mon Sep 17 00:00:00 2001 From: aristov Date: Sat, 26 Sep 2015 14:41:30 +0300 Subject: [PATCH] select: emit item-hover event on menu --- common.blocks/menu/menu.js | 1 + common.blocks/menu/menu.spec.js | 8 ++++++++ common.blocks/select/select.js | 22 +++++++++------------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/common.blocks/menu/menu.js b/common.blocks/menu/menu.js index fd45268da..a7e1cfee7 100644 --- a/common.blocks/menu/menu.js +++ b/common.blocks/menu/menu.js @@ -153,6 +153,7 @@ provide(BEMDOM.decl({ block : this.name, baseBlock : Control }, /** @lends menu. this._hoveredItem = null; this.domElem.removeAttr('aria-activedescendant'); } + this.emit('item-hover', { item : item }); }, /** diff --git a/common.blocks/menu/menu.spec.js b/common.blocks/menu/menu.spec.js index dbd770fc0..2198c2978 100644 --- a/common.blocks/menu/menu.spec.js +++ b/common.blocks/menu/menu.spec.js @@ -209,6 +209,14 @@ describe('menu', function() { spy.args[0][1].item.should.be.equal(menuItems[1]); spy.args[0][1].source.should.be.equal('pointer'); }); + + it('should emit "item-hover" event on item hover', function() { + var spy = sinon.spy(); + menu.on('item-hover', spy); + menuItems[1].setMod('hovered', true); + spy.should.have.been.called; + spy.args[0][1].item.should.be.equal(menuItems[1]); + }); }); describe('setContent()', function() { diff --git a/common.blocks/select/select.js b/common.blocks/select/select.js index 736ad2518..e7427b3ed 100644 --- a/common.blocks/select/select.js +++ b/common.blocks/select/select.js @@ -42,20 +42,14 @@ provide(BEMDOM.decl(this.name, /** @lends select.prototype */{ this._menu = this._popup.findBlockInside('menu') .on({ 'change' : this._onMenuChange, - 'item-click' : this._onMenuItemClick + 'item-click' : this._onMenuItemClick, + 'item-hover' : this._onMenuItemHover }, this); this._isPointerPressInProgress = false; this._buttonWidth = null; this.hasMod('focused') && this._focus(); - - MenuItem.on(this._menu.domElem, - { modName : 'hovered', modVal : true }, this._onItemHovered, this); - }, - '' : function() { - MenuItem.un(this._menu.domElem, - { modName : 'hovered', modVal : true }, this._onItemHovered, this); } }, @@ -89,7 +83,6 @@ provide(BEMDOM.decl(this.name, /** @lends select.prototype */{ this .unbindFromDoc('pointerpress', this._onDocPointerPress) ._popup.delMod('visible'); - this._button.domElem.removeAttr('aria-activedescendant'); } }, @@ -142,10 +135,6 @@ provide(BEMDOM.decl(this.name, /** @lends select.prototype */{ }; }, - _onItemHovered : function(e) { - this._button.domElem.attr('aria-activedescendant', e.target.domElem.attr('id')); - }, - _focus : function() { this .bindTo('button', { @@ -234,6 +223,13 @@ provide(BEMDOM.decl(this.name, /** @lends select.prototype */{ _onMenuItemClick : function() {}, + _onMenuItemHover : function(e, data) { + var item = data.item; + item.hasMod('hovered')? + this._button.domElem.attr('aria-activedescendant', item.domElem.attr('id')) : + this._button.domElem.removeAttr('aria-activedescendant'); + }, + _updateControl : function() {}, _updateButton : function() {},