ULS actions menu buttons: Add support for href

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
This commit is contained in:
NikG
2022-04-28 12:02:50 +03:00
committed by jenkins-bot
parent 449b43b2e3
commit 257112ce78
2 changed files with 22 additions and 6 deletions

View File

@@ -1,18 +1,34 @@
( function () { ( function () {
var ActionsMenuItem = function ( icon, text, handler ) { var ActionsMenuItem = function ( icon, text, handler, href ) {
this.icon = icon; this.icon = icon;
this.text = text; this.text = text;
this.handler = handler; this.handler = handler;
this.href = href;
}; };
/**
* @return {OO.ui.ButtonWidget}
*/
ActionsMenuItem.prototype.render = function () { ActionsMenuItem.prototype.render = function () {
return new OO.ui.ButtonWidget( { var actionButtonOptions = {
framed: false, framed: false,
icon: this.icon, icon: this.icon,
label: this.text, label: this.text,
classes: [ 'uls-language-action' ], classes: [ 'uls-language-action' ],
flags: [ 'progressive' ] 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; module.exports = ActionsMenuItem;

View File

@@ -7,7 +7,7 @@
this.options = options; this.options = options;
this.$template = $( ActionsMenu.template ); this.$template = $( ActionsMenu.template );
this.actionItems = options.actions.map( function ( action ) { this.actionItems = options.actions.map( function ( action ) {
return new ActionsMenuItem( action.icon, action.text, action.handler ); return new ActionsMenuItem( action.icon, action.text, action.handler, action.href );
} ); } );
this.rendered = false; this.rendered = false;
this.shown = false; this.shown = false;
@@ -65,14 +65,14 @@
actionItem = new ActionsMenuItem( actionItem = new ActionsMenuItem(
actionItem.icon, actionItem.icon,
actionItem.text, actionItem.text,
actionItem.handler actionItem.handler,
actionItem.href
); );
} }
var actionButton = actionItem.render(); var actionButton = actionItem.render();
this.$template.find( '.uls-language-action-items' ).prepend( this.$template.find( '.uls-language-action-items' ).prepend(
actionButton.$element actionButton.$element
); );
actionButton.$element.one( 'click', actionItem.handler );
}, },
i18n: function () { i18n: function () {