Skip to content

David/enhancement modebar #7429

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 18 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 @@ -147,15 +148,19 @@ proto.createButton = function(config) {
var _this = this;
var button = document.createElement('a');

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

var title = config.title;
if(title === undefined) title = config.name;
// 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 All @@ -175,6 +180,15 @@ proto.createButton = function(config) {
// only needed for 'hoverClosestGeo' which does not call relayout
_this.updateActiveButton(ev.currentTarget);
});
button.addEventListener('keydown', function(e) {
if (e.key === 'Enter' || e.key === ' ') {
const activeButton = e.target.closest('.modebar-btn');
if (activeButton) {
activeButton.click();
e.preventDefault();
}
}
});
}

button.setAttribute('data-toggle', config.toggle || false);
Expand Down
4 changes: 4 additions & 0 deletions src/css/_modebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
opacity: 1;
}

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

.modebar-group {
float: left;
display: inline-block;
Expand Down