From 257112ce780ddc001fa56c525384b42f77974d53 Mon Sep 17 00:00:00 2001 From: NikG Date: Thu, 28 Apr 2022 12:02:50 +0300 Subject: [PATCH] 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 --- resources/js/ext.uls.actions.menu.item.js | 22 +++++++++++++++++++--- resources/js/ext.uls.actions.menu.js | 6 +++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/resources/js/ext.uls.actions.menu.item.js b/resources/js/ext.uls.actions.menu.item.js index e06f47bc..999bb2e8 100644 --- a/resources/js/ext.uls.actions.menu.item.js +++ b/resources/js/ext.uls.actions.menu.item.js @@ -1,18 +1,34 @@ ( function () { - var ActionsMenuItem = function ( icon, text, handler ) { + 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 () { - return new OO.ui.ButtonWidget( { + 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; diff --git a/resources/js/ext.uls.actions.menu.js b/resources/js/ext.uls.actions.menu.js index 9178734f..347c8778 100644 --- a/resources/js/ext.uls.actions.menu.js +++ b/resources/js/ext.uls.actions.menu.js @@ -7,7 +7,7 @@ this.options = options; this.$template = $( ActionsMenu.template ); 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.shown = false; @@ -65,14 +65,14 @@ actionItem = new ActionsMenuItem( actionItem.icon, actionItem.text, - actionItem.handler + actionItem.handler, + actionItem.href ); } var actionButton = actionItem.render(); this.$template.find( '.uls-language-action-items' ).prepend( actionButton.$element ); - actionButton.$element.one( 'click', actionItem.handler ); }, i18n: function () {