From 3b60d5d396df9bee94b6945b127b315fae4d9c3a Mon Sep 17 00:00:00 2001 From: bloodrizer Date: Tue, 7 Jan 2025 18:07:22 -0800 Subject: [PATCH] better button tooltip accessability --- core.js | 30 ++++++++++++++++++++++-------- game.js | 1 - index.html | 2 +- js/jsx/left.jsx.js | 2 +- res/default.css | 3 +++ res/i18n/en.json | 2 +- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/core.js b/core.js index c343a8676b..ab1d922133 100644 --- a/core.js +++ b/core.js @@ -918,6 +918,7 @@ dojo.declare("com.nuclearunicorn.game.ui.Button", com.nuclearunicorn.core.Contro position: "relative", display: this.model.visible ? "block" : "none" }, + "aria-description": this.model.description, tabIndex: 0 }, btnContainer); @@ -944,11 +945,10 @@ dojo.declare("com.nuclearunicorn.game.ui.Button", com.nuclearunicorn.core.Contro } this.updateVisible(); + this.afterRender(); dojo.connect(this.domNode, "onclick", this, "onClick"); dojo.connect(this.domNode, "onkeypress", this, "onKeyPress"); - - this.afterRender(); }, animate: function(){ @@ -978,14 +978,13 @@ dojo.declare("com.nuclearunicorn.game.ui.Button", com.nuclearunicorn.core.Contro }, - onKeyPress: function(event){ - if (event.key == "Enter"){ - this.onClick(event); + onKeyPress: function(e){ + if (e.key == "Enter"){ + this.onClick(e); } }, afterRender: function(){ - var prices = this.model.prices; if (prices.length && !this.tooltip){ @@ -1031,8 +1030,11 @@ dojo.declare("com.nuclearunicorn.game.ui.Button", com.nuclearunicorn.core.Contro dojo.connect(this.domNode, "onmouseover", this, dojo.partial(function(tooltip){ dojo.style(tooltip, "display", ""); }, tooltip)); dojo.connect(this.domNode, "onmouseout", this, dojo.partial(function(tooltip){ dojo.style(tooltip, "display", "none"); }, tooltip)); + this.tooltip = tooltip; this.tooltipPricesNodes = tooltipPricesNodes; + + console.log("this after render", this); } }, @@ -2518,7 +2520,7 @@ UIUtils = { var gameNode = dojo.byId("game"); var tooltip = dojo.byId("tooltip"); - dojo.connect(container, "onmouseover", this, function() { + var showTooltip = function () { game.tooltipUpdateFunc = function(){ tooltip.innerHTML = dojo.hitch(game, htmlProvider)(); }; @@ -2549,12 +2551,24 @@ UIUtils = { if (tooltip.innerHTML) { dojo.style(tooltip, "display", ""); } - }); + }; + + dojo.connect(container, "onmouseover", this, showTooltip); dojo.connect(container, "onmouseout", this, function(){ game.tooltipUpdateFunc = null; dojo.style(tooltip, "display", "none"); }); + + dojo.connect(container, "onkeydown", this, function(e){ + if (e.code == "Space"){ + e.stopPropagation(); + e.preventDefault(); + + showTooltip(); + tooltip.focus(); + } + }); return htmlProvider; } diff --git a/game.js b/game.js index 5fe81ae9b6..e19dd52f8c 100644 --- a/game.js +++ b/game.js @@ -3991,7 +3991,6 @@ dojo.declare("com.nuclearunicorn.game.ui.GamePage", null, { dojo.connect(container, "onmouseout", this, function(){ dojo.style(container, "fontWeight", "normal"); }); - }, /** diff --git a/index.html b/index.html index 7d0a12a120..a3f55437cd 100644 --- a/index.html +++ b/index.html @@ -373,7 +373,7 @@