Skip to content

Commit

Permalink
select: emit item-hover event on menu
Browse files Browse the repository at this point in the history
  • Loading branch information
aristov committed Sep 29, 2015
1 parent 3fdb0fb commit 4942fce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions common.blocks/menu/menu.js
Expand Up @@ -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 });
},

/**
Expand Down
8 changes: 8 additions & 0 deletions common.blocks/menu/menu.spec.js
Expand Up @@ -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() {
Expand Down
22 changes: 9 additions & 13 deletions common.blocks/select/select.js
Expand Up @@ -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);
}
},

Expand Down Expand Up @@ -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');
}
},

Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -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() {},
Expand Down

0 comments on commit 4942fce

Please sign in to comment.