Skip to content

Commit

Permalink
better button tooltip accessability
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodrizer committed Jan 8, 2025
1 parent 3fb49bb commit 3b60d5d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
30 changes: 22 additions & 8 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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(){
Expand Down Expand Up @@ -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){

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

Expand Down Expand Up @@ -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)();
};
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion game.js
Original file line number Diff line number Diff line change
Expand Up @@ -3991,7 +3991,6 @@ dojo.declare("com.nuclearunicorn.game.ui.GamePage", null, {
dojo.connect(container, "onmouseout", this, function(){
dojo.style(container, "fontWeight", "normal");
});

},

/**
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
</div>

<div id="game" style="display:none;">
<div id="tooltip" class="button_tooltip"></div>
<div id="tooltip" class="button_tooltip" role="tooltip" tabindex="0"></div>

<!-- LEFT -->
<div id="leftColumn" class="column" style="vertical-align: top;" aria-label="Resource panel">
Expand Down
2 changes: 1 addition & 1 deletion js/jsx/left.jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ WCraftTable = React.createClass({
className: "link" + (this.state.isEditMode ? " toggled" : ""),
onClick: this.toggleEdit,
onKeyDown: this.onKeyDown,
tabIndex: 1
tabindex: 1
}, "⚙")
)
]),
Expand Down
3 changes: 3 additions & 0 deletions res/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ body {
margin: 0;
padding: 0;
background-color: #FFFFFF;
height: 100vh;
}

img.loader {
Expand Down Expand Up @@ -136,6 +137,7 @@ div#gameLog {
.bldTopContainer {
padding-bottom: 5px;
margin-bottom: 15px;
height: 100%;
}

.bldTopContainer > a, .bldTopContainer > span {
Expand Down Expand Up @@ -470,6 +472,7 @@ td.resLimitWarn, .res-cell.resLimitWarn {
padding-top: 15px;
border-top: 1px solid gray;
margin-top: 10px;
height: 100%;
}

.btn.modern {
Expand Down
2 changes: 1 addition & 1 deletion res/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@
"menu.wipe": "Wipe",
"menu.getTheApp": "Get the app",

"mid.buildings.tip": "Ctrl+click to buy/sell multiple buildings (meta+click on macOS). Shift+click to buy/sell all buildings.<br>You can set the batch size for ctrl+click in the game options.<br><br>Hold shift to see total effects of all buildings.",
"mid.buildings.tip": "Ctrl+click to buy/sell multiple buildings (meta+click on macOS). Shift+click to buy/sell all buildings.<br>You can set the batch size for ctrl+click in the game options.<br><br>Hold shift to see total effects of all buildings.<br><br>Use `Tab` to select building, `Enter` to buy it and `Space` to see detailed tooltip.",

"navbar.title": "Kittens Game",
"navbar.menu.title": "Menu",
Expand Down

0 comments on commit 3b60d5d

Please sign in to comment.