Skip to content
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

Add localized aria-labels to glyph buttons #10161

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions web/client/components/buttons/FullScreenButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import PropTypes from 'prop-types';
import React from 'react';

import ToggleButton from './ToggleButton';
import { Tooltip } from 'react-bootstrap';
import Message from '../I18N/Message';

/**
Expand Down Expand Up @@ -86,7 +85,7 @@ class FullScreenButton extends React.Component {
};

render() {
return (<ToggleButton {...this.getButtonProperties()} pressed={this.props.active} tooltip={<Tooltip id="full-screen-button-tip"><Message msgId={this.props.active ? this.props.activeTooltip : this.props.notActiveTooltip}/></Tooltip>} />);
return (<ToggleButton {...this.getButtonProperties()} pressed={this.props.active} tooltip={<Message msgId={this.props.active ? this.props.activeTooltip : this.props.notActiveTooltip}/>} />);
}
}

Expand Down
3 changes: 1 addition & 2 deletions web/client/components/buttons/GlobeViewSwitcherButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import React from 'react';
import PropTypes from 'prop-types';

import ToggleButton from './ToggleButton';
import { Tooltip } from 'react-bootstrap';
import Message from '../I18N/Message';

/**
Expand Down Expand Up @@ -85,7 +84,7 @@ class GlobeViewSwitcherButton extends React.Component {
};

render() {
return <ToggleButton {...this.getButtonProperties()} pressed={this.props.active} tooltip={<Tooltip id="globeViewSwitcher-tooltip"><Message msgId={this.props.active ? this.props.activeTooltip : this.props.notActiveTooltip}/></Tooltip>} />;
return <ToggleButton {...this.getButtonProperties()} pressed={this.props.active} tooltip={<Message msgId={this.props.active ? this.props.activeTooltip : this.props.notActiveTooltip}/>} />;
}
}

Expand Down
37 changes: 24 additions & 13 deletions web/client/components/buttons/ToggleButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import React from 'react';
import PropTypes from 'prop-types';
import { Glyphicon } from 'react-bootstrap';
import OverlayTrigger from '../misc/OverlayTrigger';
import Button from '../misc/Button';
import {ButtonWithTooltip} from '../misc/Button';
import ImageButton from './ImageButton';
import tooltip from "../misc/enhancers/tooltip";
/**
* Toggle button with tooltip and icons or image support.
* @memberof components.buttons
Expand Down Expand Up @@ -70,18 +71,36 @@ class ToggleButton extends React.Component {

renderNormalButton = () => {
return (
<Button id={this.props.id} {...this.props.btnConfig} onClick={this.onClick} bsStyle={this.props.pressed ? this.props.pressedStyle : this.props.defaultStyle} style={this.props.style}>
<ButtonWithTooltip
id={this.props.id}
{...this.props.btnConfig}
onClick={this.onClick}
bsStyle={this.props.pressed ? this.props.pressedStyle : this.props.defaultStyle}
style={this.props.style}
tooltip={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
>
{this.props.glyphicon ? <Glyphicon glyph={this.props.glyphicon}/> : null}
{this.props.glyphicon && this.props.text && !React.isValidElement(this.props.text) ? "\u00A0" : null}
{this.props.text}
{this.props.help}
</Button>
</ButtonWithTooltip>
);
};

renderImageButton = () => {
const ImageButtonT = tooltip(ImageButton);
return (
<ImageButton id={this.props.id} image={this.props.image} onClick={this.onClick} style={this.props.style}/>
<ImageButtonT
id={this.props.id}
image={this.props.image}
onClick={this.onClick}
style={this.props.style}
tooltip={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
/>
);
};

Expand All @@ -94,15 +113,7 @@ class ToggleButton extends React.Component {
};

render() {
var retval;
var btn = this.props.btnType === 'normal' ? this.renderNormalButton() : this.renderImageButton();
if (this.props.tooltip) {
retval = this.addTooltip(btn);
} else {
retval = btn;
}
return retval;

return this.props.btnType === 'normal' ? this.renderNormalButton() : this.renderImageButton();
}
}

Expand Down
48 changes: 18 additions & 30 deletions web/client/components/buttons/ZoomButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import PropTypes from 'prop-types';
import React from 'react';

import Button from '../misc/Button';
import { Glyphicon, Tooltip } from 'react-bootstrap';
import OverlayTrigger from '../misc/OverlayTrigger';
import { ButtonWithTooltip } from '../misc/Button';
import { Glyphicon } from 'react-bootstrap';

class ZoomButton extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -49,34 +48,23 @@ class ZoomButton extends React.Component {
};

render() {
return this.addTooltip(
<Button
id={this.props.id}
style={this.props.style}
onClick={() => this.props.onZoom(this.props.currentZoom + this.props.step)}
className={this.props.className}
disabled={this.props.currentZoom + this.props.step > this.props.maxZoom || this.props.currentZoom + this.props.step < this.props.minZoom}
bsStyle={this.props.bsStyle}
>
{this.props.glyphicon ? <Glyphicon glyph={this.props.glyphicon}/> : null}
{this.props.glyphicon && this.props.text ? "\u00A0" : null}
{this.props.text}
{this.props.help}
</Button>
);
return (<ButtonWithTooltip
id={this.props.id}
style={this.props.style}
onClick={() => this.props.onZoom(this.props.currentZoom + this.props.step)}
className={this.props.className}
disabled={this.props.currentZoom + this.props.step > this.props.maxZoom || this.props.currentZoom + this.props.step < this.props.minZoom}
bsStyle={this.props.bsStyle}
tooltip={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
>
{this.props.glyphicon ? <Glyphicon glyph={this.props.glyphicon}/> : null}
{this.props.glyphicon && this.props.text ? "\u00A0" : null}
{this.props.text}
{this.props.help}
</ButtonWithTooltip>);
}

addTooltip = (btn) => {
if (!this.props.tooltip) {
return btn;
}
let tooltip = <Tooltip id="locate-tooltip">{this.props.tooltip}</Tooltip>;
return (
<OverlayTrigger placement={this.props.tooltipPlace} key={"overlay-trigger." + this.props.id} overlay={tooltip}>
{btn}
</OverlayTrigger>
);
};
}

export default ZoomButton;
23 changes: 13 additions & 10 deletions web/client/components/home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ class Home extends React.Component {
let tooltip = <Tooltip id="toolbar-home-button">{<Message msgId="gohome"/>}</Tooltip>;
return hidden ? false : (
<React.Fragment>
<OverlayTrigger overlay={tooltip} placement={tooltipPosition}>
<Button
id="home-button"
className="square-button"
bsStyle={this.props.bsStyle}
onClick={this.checkUnsavedChanges}
tooltip={tooltip}
{...pick(restProps, ['disabled', 'active', 'block', 'componentClass', 'href', 'children', 'icon', 'bsStyle', 'className'])}
><Glyphicon glyph={this.props.icon}/></Button>
</OverlayTrigger>
<Message msgId="gohome">
{(label) => <OverlayTrigger overlay={tooltip} placement={tooltipPosition}>
<Button
id="home-button"
className="square-button"
bsStyle={this.props.bsStyle}
onClick={this.checkUnsavedChanges}
tooltip={tooltip}
aria-label={label}
{...pick(restProps, ['disabled', 'active', 'block', 'componentClass', 'href', 'children', 'icon', 'bsStyle', 'className'])}
><Glyphicon glyph={this.props.icon}/></Button>
</OverlayTrigger>}
</Message>
<ConfirmModal
ref="unsavedMapModal"
show={this.props.displayUnsavedDialog || false}
Expand Down
52 changes: 26 additions & 26 deletions web/client/components/mapcontrols/locate/LocateBtn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@

import PropTypes from 'prop-types';
import React from 'react';
import {Glyphicon, Tooltip} from 'react-bootstrap';
import {Glyphicon} from 'react-bootstrap';

import Message from '../../I18N/Message';
import OverlayTrigger from '../../misc/OverlayTrigger';
import defaultIcon from '../../misc/spinners/InlineSpinner/img/spinner.gif';
import Button from '../../misc/Button';
import {ButtonWithTooltip} from '../../misc/Button';
import('./css/locate.css');

let checkingGeoLocation = false;
Expand Down Expand Up @@ -74,9 +72,19 @@ class LocateBtn extends React.Component {
renderButton = () => {
const geoLocationDisabled = this.props.locate === "PERMISSION_DENIED";
return (
<Button id={this.props.id} disabled={geoLocationDisabled} {...this.props.btnConfig} onClick={this.onClick} bsStyle={this.getBtnStyle()} style={this.props.style}>
<ButtonWithTooltip
id={this.props.id}
disabled={geoLocationDisabled}
{...this.props.btnConfig}
onClick={this.onClick}
bsStyle={this.getBtnStyle()}
style={this.props.style}
tooltipId={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
>
<Glyphicon glyph={this.props.glyph}/>{this.props.text}{this.props.help}
</Button>
</ButtonWithTooltip>
);
};

Expand All @@ -91,18 +99,18 @@ class LocateBtn extends React.Component {
}} alt="..." />)
;
return (
<Button id={this.props.id} onClick={this.onClick} {...this.props.btnConfig} bsStyle={this.getBtnStyle()} style={this.props.style}>
<ButtonWithTooltip
id={this.props.id}
onClick={this.onClick}
{...this.props.btnConfig}
bsStyle={this.getBtnStyle()}
style={this.props.style}
tooltipId={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
>
{img}
</Button>
);
};

addTooltip = (btn) => {
const tooltip = <Tooltip id="locate-tooltip"><Message msgId={this.props.tooltip} /></Tooltip>;
return (
<OverlayTrigger placement={this.props.tooltipPlace} key={`{overlay-trigger.${this.props.id}-${this.props.tooltip}}`} overlay={tooltip}>
{btn}
</OverlayTrigger>
</ButtonWithTooltip>
);
};

Expand Down Expand Up @@ -130,15 +138,7 @@ class LocateBtn extends React.Component {
}

render() {
var retval;
var btn = this.props.locate === "LOCATING" ? this.renderLoadingButton() : this.renderButton();
if (this.props.tooltip) {
retval = this.addTooltip(btn);
} else {
retval = btn;
}
return retval;

return this.props.locate === "LOCATING" ? this.renderLoadingButton() : this.renderButton();
}

getBtnStyle = () => {
Expand Down
52 changes: 17 additions & 35 deletions web/client/components/mapcontrols/navigationhistory/RedoButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

import React from 'react';
import PropTypes from 'prop-types';
import { Glyphicon, Tooltip } from 'react-bootstrap';

import OverlayTrigger from '../../misc/OverlayTrigger';
import Button from '../../misc/Button';
import { Glyphicon } from 'react-bootstrap';
import {ButtonWithTooltip} from '../../misc/Button';

class RedoBtn extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -40,44 +38,28 @@ class RedoBtn extends React.Component {
}
};

onClick = () => {
this.props.onClick();
};

shouldComponentUpdate(nextProps) {
return this.props.disabled !== nextProps.disabled;
}

renderButton = () => {
return (
<Button id={this.props.id} disabled={this.props.disabled} {...this.props.btnConfig} onClick={this.onClick} bsStyle={this.props.buttonStyle} style={this.props.style}>
<Glyphicon glyph={this.props.glyph}/>{this.props.text}{this.props.help}
</Button>
);
};

addTooltip = (btn) => {
let tooltip = <Tooltip id="redo-btn-tooltip">{this.props.tooltip}</Tooltip>;
return (
<OverlayTrigger placement={this.props.tooltipPlace} key={"overlay-trigger." + this.props.id} overlay={tooltip}>
{btn}
</OverlayTrigger>
);
onClick = () => {
this.props.onClick();
};

UNSAFE_componentWillMount() {
// none
}

render() {
var retval;
var btn = this.renderButton();
if (this.props.tooltip) {
retval = this.addTooltip(btn);
} else {
retval = btn;
}
return retval;
return (<ButtonWithTooltip
id={this.props.id}
disabled={this.props.disabled}
{...this.props.btnConfig}
onClick={this.onClick}
bsStyle={this.props.buttonStyle}
style={this.props.style}
tooltip={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
>
<Glyphicon glyph={this.props.glyph}/>{this.props.text}{this.props.help}
</ButtonWithTooltip>);

}
}
Expand Down
Loading
Loading