Currently, actions menu button only support an event handler to be called upon button click. However, when the desired result of a button click is just a redirection, "href" attributes are preferable, due to their accessibility support. To better handle such cases, this patch also adds support for "href" attributes inside action item buttons. When "href" property exists for an actions menu item, it is used and the event handler is ignored. Bug: T289840 Change-Id: I776680c19564f032acd550206c7d1306407420e0
36 lines
714 B
JavaScript
36 lines
714 B
JavaScript
( function () {
|
|
var ActionsMenuItem = function ( icon, text, handler, href ) {
|
|
this.icon = icon;
|
|
this.text = text;
|
|
this.handler = handler;
|
|
this.href = href;
|
|
};
|
|
|
|
/**
|
|
* @return {OO.ui.ButtonWidget}
|
|
*/
|
|
ActionsMenuItem.prototype.render = function () {
|
|
var actionButtonOptions = {
|
|
framed: false,
|
|
icon: this.icon,
|
|
label: this.text,
|
|
classes: [ 'uls-language-action' ],
|
|
flags: [ 'progressive' ]
|
|
};
|
|
|
|
if ( this.href ) {
|
|
actionButtonOptions.href = this.href;
|
|
}
|
|
|
|
var actionButton = new OO.ui.ButtonWidget( actionButtonOptions );
|
|
|
|
if ( !this.href ) {
|
|
actionButton.$element.one( 'click', this.handler );
|
|
}
|
|
|
|
return actionButton;
|
|
};
|
|
|
|
module.exports = ActionsMenuItem;
|
|
}() );
|