start to make nav accessible

This commit is contained in:
Cassie Tarakajian 2017-08-28 11:19:10 -04:00
parent 4e822809bb
commit 7d449e63b9
2 changed files with 63 additions and 12 deletions

View file

@ -37,7 +37,8 @@
"react/prefer-stateless-function": [2, "react/prefer-stateless-function": [2,
{ "ignorePureComponents": true { "ignorePureComponents": true
}], }],
"class-methods-use-this": 0 "class-methods-use-this": 0,
"react/jsx-no-bind": [2, {"allowBind": true, "allowArrowFunctions": true}]
}, },
"plugins": [ "plugins": [
"react", "jsx-a11y", "import" "react", "jsx-a11y", "import"

View file

@ -1,24 +1,69 @@
import React, { PropTypes } from 'react'; import React, { PropTypes } from 'react';
import { Link } from 'react-router'; import { Link } from 'react-router';
import InlineSVG from 'react-inlinesvg'; import InlineSVG from 'react-inlinesvg';
import classNames from 'classnames';
const triangleUrl = require('../images/down-filled-triangle.svg'); const triangleUrl = require('../images/down-filled-triangle.svg');
const logoUrl = require('../images/p5js-logo-small.svg'); const logoUrl = require('../images/p5js-logo-small.svg');
class Nav extends React.PureComponent { class Nav extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
dropdownOpen: 'none'
};
}
isUserOwner() { isUserOwner() {
return this.props.project.owner && this.props.project.owner.id === this.props.user.id; return this.props.project.owner && this.props.project.owner.id === this.props.user.id;
} }
toggleDropdown(dropdown) {
if (this.state.dropdownOpen === 'none') {
this.setState({
dropdownOpen: dropdown
});
} else {
this.setState({
dropdownOpen: 'none'
});
}
}
render() { render() {
const navDropdownState = {
file: classNames({
'nav__item': true,
'nav__item--open': this.state.dropdownOpen === 'file'
}),
edit: classNames({
'nav__item': true,
'nav__item--open': this.state.dropdownOpen === 'edit'
}),
sketch: classNames({
'nav__item': true,
'nav__item--open': this.state.dropdownOpen === 'sketch'
}),
help: classNames({
'nav__item': true,
'nav__item--open': this.state.dropdownOpen === 'help'
}),
account: classNames({
'nav__item': true,
'nav__item--open': this.state.dropdownOpen === 'account'
})
};
return ( return (
<nav className="nav" role="navigation" title="main-navigation"> <nav className="nav" role="navigation" title="main-navigation">
<ul className="nav__items-left" title="project-menu"> <ul className="nav__items-left" title="project-menu">
<li> <li>
<InlineSVG src={logoUrl} alt="p5.js logo" /> <InlineSVG src={logoUrl} alt="p5.js logo" />
</li> </li>
<li className="nav__item"> <li className={navDropdownState.file}>
<button> <button
onClick={this.toggleDropdown.bind(this, 'file')}
onBlur={this.toggleDropdown.bind(this, 'none')}
>
<span className="nav__item-header">File</span> <span className="nav__item-header">File</span>
<InlineSVG src={triangleUrl} /> <InlineSVG src={triangleUrl} />
</button> </button>
@ -87,8 +132,8 @@ class Nav extends React.PureComponent {
</li> </li>
</ul> </ul>
</li> </li>
<li className="nav__item"> <li className={navDropdownState.edit}>
<button> <button onClick={this.toggleDropdown.bind(this, 'edit')}>
<span className="nav__item-header">Edit</span> <span className="nav__item-header">Edit</span>
<InlineSVG src={triangleUrl} /> <InlineSVG src={triangleUrl} />
</button> </button>
@ -105,8 +150,8 @@ class Nav extends React.PureComponent {
</li> </li>
</ul> </ul>
</li> </li>
<li className="nav__item"> <li className={navDropdownState.sketch}>
<button> <button onClick={this.toggleDropdown.bind(this, 'sketch')}>
<span className="nav__item-header">Sketch</span> <span className="nav__item-header">Sketch</span>
<InlineSVG src={triangleUrl} /> <InlineSVG src={triangleUrl} />
</button> </button>
@ -123,8 +168,8 @@ class Nav extends React.PureComponent {
</li> </li>
</ul> </ul>
</li> </li>
<li className="nav__item"> <li className={navDropdownState.help}>
<button> <button onClick={this.toggleDropdown.bind(this, 'help')}>
<span className="nav__item-header">Help</span> <span className="nav__item-header">Help</span>
<InlineSVG src={triangleUrl} /> <InlineSVG src={triangleUrl} />
</button> </button>
@ -167,12 +212,17 @@ class Nav extends React.PureComponent {
<span>Hello, {this.props.user.username}!</span> <span>Hello, {this.props.user.username}!</span>
</li> </li>
<span className="nav__item-spacer">|</span> <span className="nav__item-spacer">|</span>
<li className="nav__item"> <li className={navDropdownState.account}>
<button className="nav__item-header">My Account</button> <button
className="nav__item-header"
onClick={this.toggleDropdown.bind(this, 'account')}
>
My Account
</button>
<InlineSVG src={triangleUrl} /> <InlineSVG src={triangleUrl} />
<ul className="nav__dropdown"> <ul className="nav__dropdown">
<li className="nav__dropdown-heading"> <li className="nav__dropdown-heading">
<button>My Account</button> <span>My Account</span>
<InlineSVG src={triangleUrl} /> <InlineSVG src={triangleUrl} />
</li> </li>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">