mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-30 14:17:36 -10:00
To accomplish this, the added aria-pressed attribute turns the buttons into toggle buttons, and the one that is visually selected, gets the "true" attribute value, others are "false". That way, the screen reader and other assistive technologies will indicate that this is the selected or pressed button. MozReview-Commit-ID: L2lcw2wOyYw
85 lines
2.2 KiB
JavaScript
85 lines
2.2 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
"use strict";
|
|
|
|
const { Component } = require("devtools/client/shared/vendor/react");
|
|
const PropTypes = require("devtools/client/shared/vendor/react-prop-types");
|
|
const dom = require("devtools/client/shared/vendor/react-dom-factories");
|
|
const {img, button, span} = dom;
|
|
|
|
class ToolboxTab extends Component {
|
|
// See toolbox-toolbar propTypes for details on the props used here.
|
|
static get propTypes() {
|
|
return {
|
|
currentToolId: PropTypes.string,
|
|
focusButton: PropTypes.func,
|
|
focusedButton: PropTypes.string,
|
|
highlightedTools: PropTypes.object.isRequired,
|
|
panelDefinition: PropTypes.object,
|
|
selectTool: PropTypes.func,
|
|
};
|
|
}
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
this.renderIcon = this.renderIcon.bind(this);
|
|
}
|
|
|
|
renderIcon(definition, isHighlighted) {
|
|
const {icon} = definition;
|
|
if (!icon) {
|
|
return [];
|
|
}
|
|
return [
|
|
img({
|
|
src: icon
|
|
}),
|
|
];
|
|
}
|
|
|
|
render() {
|
|
const {panelDefinition, currentToolId, highlightedTools, selectTool,
|
|
focusedButton, focusButton} = this.props;
|
|
const {id, tooltip, label, iconOnly} = panelDefinition;
|
|
const isHighlighted = id === currentToolId;
|
|
|
|
const className = [
|
|
"devtools-tab",
|
|
currentToolId === id ? "selected" : "",
|
|
highlightedTools.has(id) ? "highlighted" : "",
|
|
iconOnly ? "devtools-tab-icon-only" : ""
|
|
].join(" ");
|
|
|
|
return button(
|
|
{
|
|
className,
|
|
id: `toolbox-tab-${id}`,
|
|
"data-id": id,
|
|
title: tooltip,
|
|
type: "button",
|
|
"aria-pressed": currentToolId === id ? "true" : "false",
|
|
tabIndex: focusedButton === id ? "0" : "-1",
|
|
onFocus: () => focusButton(id),
|
|
onMouseDown: () => selectTool(id),
|
|
},
|
|
span(
|
|
{
|
|
className: "devtools-tab-line"
|
|
}
|
|
),
|
|
...this.renderIcon(panelDefinition, isHighlighted),
|
|
iconOnly ?
|
|
null :
|
|
span(
|
|
{
|
|
className: "devtools-tab-label"
|
|
},
|
|
label
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
module.exports = ToolboxTab;
|