Skip to content

Commit

Permalink
improve a11y on some buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
psalaets committed Aug 28, 2017
1 parent a13038e commit 528433d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/components/controls/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
class Button extends Component {
static propTypes = {
onClick: PropTypes.func.isRequired,
label: PropTypes.string.isRequired,
animateIn: PropTypes.bool
}

Expand All @@ -19,7 +20,7 @@ class Button extends Component {

render() {
return (
<button className={this.className()} onClick={this.handleClick}>
<button className={this.className()} onClick={this.handleClick} aria-label={this.props.label}>
{this.props.children}
</button>
);
Expand Down
10 changes: 9 additions & 1 deletion src/components/fullscreen-button/FullscreenButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ class FullscreenButton extends Component {
const icon = this.renderIcon();

return (
<Button aria-label="fullscreen" onClick={this.handleClick}>
<Button label={this.label()} onClick={this.handleClick}>
{icon}
</Button>
);
}

label() {
if (this.props.isFullscreen) {
return 'Exit fullscreen';
} else {
return 'Enter fullscreen';
}
}

renderIcon() {
if (this.props.isFullscreen) {
return <Icon type="exit-fullscreen" />;
Expand Down
6 changes: 3 additions & 3 deletions src/components/navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ class Navigation extends Component {

renderLeft() {
return (
<NavigationButton key="left" onClick={this.handleSecondaryClick} />
<NavigationButton key="left" onClick={this.handleSecondaryClick} label="Go to previous page" />
);
}

renderCenter() {
return (
<NavigationButton key="center" type="center" onClick={this.handleTertiaryClick} />
<NavigationButton key="center" type="center" onClick={this.handleTertiaryClick} label="Toggle controls" />
);
}

renderRight() {
return (
<NavigationButton key="right" onClick={this.handlePrimaryClick} />
<NavigationButton key="right" onClick={this.handlePrimaryClick} label="Go to next page" />
);
}

Expand Down
13 changes: 11 additions & 2 deletions src/components/navigation/NavigationButton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import React from 'react';

export default function NavigationButton(props) {
const className = (props.type === 'center') ? 'lb-c-navigation__button lb-c-navigation__button--center': 'lb-c-navigation__button';
const className = props.type === 'center'
? 'lb-c-navigation__button lb-c-navigation__button--center'
: 'lb-c-navigation__button';

return <div className={className} onClick={props.onClick} />;
return (
<div
className={className}
onClick={props.onClick}
role="button"
aria-label={props.label}
/>
);
}
14 changes: 11 additions & 3 deletions src/components/share-button/ShareButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,29 @@ class ShareButton extends Component {
render() {
return (
<span>
<Button onClick={this.handleClick}>
<Button onClick={this.handleClick} label={this.label()}>
<Icon type="share" />
</Button>
{this.renderSocialMediaButtons()}
</span>
);
}

label() {
if (this.state.open) {
return 'Hide share options';
} else {
return 'Show share options';
}
}

renderSocialMediaButtons() {
if (this.state.open) {
return [
<Button key="facebook" onClick={this.handleFacebookClick} animateIn={true}>
<Button key="facebook" label="Share on Facebook" onClick={this.handleFacebookClick} animateIn={true}>
<Icon type="facebook" />
</Button>,
<Button key="twitter" onClick={this.handleTwitterClick} animateIn={true}>
<Button key="twitter" label="Share on Twitter" onClick={this.handleTwitterClick} animateIn={true}>
<Icon type="twitter" />
</Button>
];
Expand Down

0 comments on commit 528433d

Please sign in to comment.