Skip to content

feat: Improve keyboard navigation of modebar (by @davidangarita1) #7492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
54d1253
Add role="toolbar" to enhance accessibility semantics
davidangarita1 May 28, 2025
318530e
Add tabindex="0" to buttons
davidangarita1 May 28, 2025
ebb7b12
Add custom CSS class "modebar--custom"
davidangarita1 May 28, 2025
8748342
Add aria label
davidangarita1 May 29, 2025
fd9ad69
Add modebar tabindex 0
davidangarita1 May 29, 2025
e2c6615
Add listener of Intro key for Modebar buttons
davidangarita1 May 29, 2025
a2fa286
Move button listener
davidangarita1 May 29, 2025
06d3d1f
Add style for focus in modebar
davidangarita1 May 29, 2025
e557ee1
Change "a" tag for "button" tag
davidangarita1 Jun 3, 2025
9386b15
Add styles for focus in button
davidangarita1 Jun 3, 2025
6dc49c9
Change the indentation to the correct format
davidangarita1 Jun 3, 2025
905cab1
Update build
davidangarita1 Jun 3, 2025
363a873
Fix scss indentation
davidangarita1 Jun 4, 2025
165dffe
Remove unnecessary js for the button
davidangarita1 Jun 4, 2025
904e64a
Fix indentation for spaces
davidangarita1 Jun 4, 2025
605c627
Merge remote-tracking branch 'origin/master' into david/enhancement-m…
davidangarita1 Jun 4, 2025
663dbf1
Re-add deleted files from dist
davidangarita1 Jun 12, 2025
b17b7f0
Merge remote-tracking branch 'origin/master' into david/enhancement-m…
ayjayt Jun 17, 2025
0f7e1e5
Merge branch 'master' into david-enhancement-modebar-emilykl
emilykl Jul 23, 2025
dbd4594
update jasmine tests
emilykl Jun 17, 2025
b250897
add draftlog
emilykl Jul 24, 2025
4698ac6
Update 7492_add.md
emilykl Jul 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions build/plotcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ var rules = {
"X .ease-bg": "-webkit-transition:background-color .3s ease 0s;-moz-transition:background-color .3s ease 0s;-ms-transition:background-color .3s ease 0s;-o-transition:background-color .3s ease 0s;transition:background-color .3s ease 0s;",
"X .modebar--hover>:not(.watermark)": "opacity:0;-webkit-transition:opacity .3s ease 0s;-moz-transition:opacity .3s ease 0s;-ms-transition:opacity .3s ease 0s;-o-transition:opacity .3s ease 0s;transition:opacity .3s ease 0s;",
"X:hover .modebar--hover .modebar-group": "opacity:1;",
"X:focus-within .modebar--hover .modebar-group": "opacity:1;",
"X .modebar-group": "float:left;display:inline-block;box-sizing:border-box;padding-left:8px;position:relative;vertical-align:middle;white-space:nowrap;",
"X .modebar-btn": "position:relative;font-size:16px;padding:3px 4px;height:22px;cursor:pointer;line-height:normal;box-sizing:border-box;",
"X .modebar-btn svg": "position:relative;top:2px;",
"X .modebar-group a": "display:grid;place-content:center;",
"X .modebar-btn": "position:relative;font-size:16px;padding:3px 4px;height:22px;cursor:pointer;line-height:normal;box-sizing:border-box;border:none;background:rgba(0,0,0,0);",
"X .modebar-btn svg": "position:relative;",
"X .modebar-btn:focus-visible": "outline:1px solid #000;outline-offset:1px;border-radius:3px;",
"X .modebar.vertical": "display:flex;flex-direction:column;flex-wrap:wrap;align-content:flex-end;max-height:100%;",
"X .modebar.vertical svg": "top:-1px;",
"X .modebar.vertical .modebar-group": "display:block;float:none;padding-left:0px;padding-bottom:8px;",
Expand Down
1 change: 1 addition & 0 deletions draftlogs/7492_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Make modebar keyboard-accessible via tabbing [[#7492](https://github.com/plotly/plotly.js/pull/7492)], with thanks to @davidangarita1 for the contribution!
13 changes: 9 additions & 4 deletions src/components/modebar/modebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ proto.update = function(graphInfo, buttons) {
var modeBarId = 'modebar-' + fullLayout._uid;

this.element.setAttribute('id', modeBarId);
this._uid = modeBarId;
this.element.setAttribute('role', 'toolbar');

this.element.className = 'modebar';
this._uid = modeBarId;
this.element.className = 'modebar modebar--custom';
if(context.displayModeBar === 'hover') this.element.className += ' modebar--hover ease-bg';

if(fullLayout.modebar.orientation === 'v') {
Expand Down Expand Up @@ -145,8 +146,9 @@ proto.createGroup = function() {
*/
proto.createButton = function(config) {
var _this = this;
var button = document.createElement('a');
var button = document.createElement('button');

button.setAttribute('type', 'button');
button.setAttribute('rel', 'tooltip');
button.className = 'modebar-btn';

Expand All @@ -155,7 +157,10 @@ proto.createButton = function(config) {
// for localization: allow title to be a callable that takes gd as arg
else if(typeof title === 'function') title = title(this.graphInfo);

if(title || title === 0) button.setAttribute('data-title', title);
if(title || title === 0) {
button.setAttribute('data-title', title)
button.setAttribute("aria-label", title)
};

if(config.attr !== undefined) button.setAttribute('data-attr', config.attr);

Expand Down
28 changes: 22 additions & 6 deletions src/css/_modebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@include vendor('transition', background-color 0.3s ease 0s);
}

.modebar--hover > :not(.watermark) {
.modebar--hover> :not(.watermark) {
opacity: 0;
@include vendor('transition', opacity 0.3s ease 0s);
}
Expand All @@ -17,6 +17,10 @@
opacity: 1;
}

&:focus-within .modebar--hover .modebar-group {
opacity: 1;
}

.modebar-group {
float: left;
display: inline-block;
Expand All @@ -25,6 +29,11 @@
position: relative;
vertical-align: middle;
white-space: nowrap;

a {
display: grid;
place-content: center;
}
}

.modebar-btn {
Expand All @@ -36,15 +45,20 @@
cursor: pointer;
line-height: normal;
box-sizing: border-box;
border: none;
background: transparent;

svg {
position: relative;
top: 2px;
}

&.modebar-btn--logo {

&:focus-visible {
outline: 1px solid black;
outline-offset: 1px;
border-radius: 3px;
}

&.modebar-btn--logo {}
}

.modebar.vertical {
Expand All @@ -53,9 +67,11 @@
flex-wrap: wrap;
align-content: flex-end;
max-height: 100%;

svg {
top: -1px;
top: -1px;
}

.modebar-group {
display: block;
float: none;
Expand All @@ -67,4 +83,4 @@
text-align: center;
}
}
}
}
14 changes: 7 additions & 7 deletions test/jasmine/tests/modebar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ describe('ModeBar', function() {
}

function countButtons(modeBar) {
return d3Select(modeBar.element).selectAll('a.modebar-btn').size();
return d3Select(modeBar.element).selectAll('button.modebar-btn, a.modebar-btn').size();
}

function countLogo(modeBar) {
return d3Select(modeBar.element).selectAll('a.plotlyjsicon').size();
}

function checkBtnAttr(modeBar, index, attr) {
var buttons = d3Select(modeBar.element).selectAll('a.modebar-btn');
var buttons = d3Select(modeBar.element).selectAll('button.modebar-btn, a.modebar-btn');
return d3Select(buttons[0][index]).attr(attr);
}

Expand Down Expand Up @@ -1676,7 +1676,7 @@ describe('ModeBar', function() {
it('add predefined shape drawing and hover buttons via layout.modebar.add', function(done) {
function countButtons() {
var modeBarEl = gd._fullLayout._modeBar.element;
return d3Select(modeBarEl).selectAll('a.modebar-btn').size();
return d3Select(modeBarEl).selectAll('button.modebar-btn, a.modebar-btn').size();
}

var initial = 10;
Expand Down Expand Up @@ -1761,7 +1761,7 @@ describe('ModeBar', function() {
it('remove buttons using exact (camel case) and short (lower case) names via layout.modebar.remove and template', function(done) {
function countButtons() {
var modeBarEl = gd._fullLayout._modeBar.element;
return d3Select(modeBarEl).selectAll('a.modebar-btn').size();
return d3Select(modeBarEl).selectAll('button.modebar-btn, a.modebar-btn').size();
}

var initial = 10;
Expand Down Expand Up @@ -1842,7 +1842,7 @@ describe('ModeBar', function() {
it('add buttons using template', function(done) {
function countButtons() {
var modeBarEl = gd._fullLayout._modeBar.element;
return d3Select(modeBarEl).selectAll('a.modebar-btn').size();
return d3Select(modeBarEl).selectAll('button.modebar-btn, a.modebar-btn').size();
}

var initial = 10;
Expand All @@ -1865,7 +1865,7 @@ describe('ModeBar', function() {
it('add ' + t + ' button if removed by layout and added by config', function(done) {
function countButtons() {
var modeBarEl = gd._fullLayout._modeBar.element;
return d3Select(modeBarEl).selectAll('a.modebar-btn').size();
return d3Select(modeBarEl).selectAll('button.modebar-btn, a.modebar-btn').size();
}

var initial = 10;
Expand All @@ -1886,7 +1886,7 @@ describe('ModeBar', function() {
it('remove button if added by layout and removed by config', function(done) {
function countButtons() {
var modeBarEl = gd._fullLayout._modeBar.element;
return d3Select(modeBarEl).selectAll('a.modebar-btn').size();
return d3Select(modeBarEl).selectAll('button.modebar-btn, a.modebar-btn').size();
}

var initial = 10;
Expand Down