Ivan - Table Component - Add tabbable property to menu [skip ci]

This commit is contained in:
ivan 2016-08-16 21:01:36 -03:00
parent fc11eb8cb1
commit cfb65f2306
8 changed files with 28 additions and 10 deletions

View File

@ -8,7 +8,7 @@ gulp.task('browserSync', function() {
browserSync({ browserSync({
proxy: 'localhost:' + config.serverport, proxy: 'localhost:' + config.serverport,
startPath: 'app' startPath: '/'
}); });
}); });

View File

@ -21,7 +21,7 @@ var util = require('gulp-util');
function buildScript(file, watch) { function buildScript(file, watch) {
var bundler = browserify({ var bundler = browserify({
entries: [config.sourceDir + '/' + file], entries: [config.sourceDir + file],
debug: !global.isProd, debug: !global.isProd,
insertGlobalVars: { insertGlobalVars: {
noFixtures: function() { noFixtures: function() {

View File

@ -56,6 +56,7 @@
"app-module-path": "^1.0.3", "app-module-path": "^1.0.3",
"classnames": "^2.1.3", "classnames": "^2.1.3",
"jquery": "^2.1.4", "jquery": "^2.1.4",
"keycode": "^2.1.4",
"localStorage": "^1.0.3", "localStorage": "^1.0.3",
"lodash": "^3.10.0", "lodash": "^3.10.0",
"messageformat": "^0.2.2", "messageformat": "^0.2.2",

View File

@ -31,6 +31,7 @@ class DashboardMenu extends React.Component {
items: this.getMenuItems(), items: this.getMenuItems(),
selectedIndex: this.getSelectedIndex(), selectedIndex: this.getSelectedIndex(),
onItemClick: this.goToPathByIndex.bind(this), onItemClick: this.goToPathByIndex.bind(this),
tabbable: true,
type: 'secondary' type: 'secondary'
}; };
} }

View File

@ -74,7 +74,7 @@ class MainRecoverPasswordPage extends React.Component {
} }
onPasswordRecovered() { onPasswordRecovered() {
setTimeout(() => {this.props.history.push('/app')}, 2000); setTimeout(() => {this.props.history.push('/')}, 2000);
this.setState({ this.setState({
recoverStatus: 'valid', recoverStatus: 'valid',
loading: false loading: false

View File

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import _ from 'lodash'; import _ from 'lodash';
import keyCode from 'keycode';
import callback from 'lib-core/callback'; import callback from 'lib-core/callback';
import getIcon from 'lib-core/get-icon'; import getIcon from 'lib-core/get-icon';
@ -87,7 +88,7 @@ class CheckBox extends React.Component {
} }
handleIconKeyDown(event) { handleIconKeyDown(event) {
if (event.keyCode == 32) { if (event.keyCode === keyCode('SPACE')) {
event.preventDefault(); event.preventDefault();
callback(this.handleChange.bind(this), this.props.onChange)({ callback(this.handleChange.bind(this), this.props.onChange)({

View File

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import _ from 'lodash'; import _ from 'lodash';
import classNames from 'classnames'; import classNames from 'classnames';
import keyCode from 'keycode';
import Icon from 'core-components/icon'; import Icon from 'core-components/icon';
@ -13,12 +14,14 @@ class Menu extends React.Component {
content: React.PropTypes.string.isRequired, content: React.PropTypes.string.isRequired,
icon: React.PropTypes.string icon: React.PropTypes.string
})).isRequired, })).isRequired,
selectedIndex: React.PropTypes.number selectedIndex: React.PropTypes.number,
tabbable: React.PropTypes.boolean
}; };
static defaultProps = { static defaultProps = {
type: 'primary', type: 'primary',
selectedIndex: 0 selectedIndex: 0,
tabbable: false
}; };
render() { render() {
@ -65,6 +68,7 @@ class Menu extends React.Component {
delete props.items; delete props.items;
delete props.onItemClick; delete props.onItemClick;
delete props.selectedIndex; delete props.selectedIndex;
delete props.tabbable;
delete props.type; delete props.type;
return props; return props;
@ -84,7 +88,9 @@ class Menu extends React.Component {
getItemProps(index) { getItemProps(index) {
return { return {
className: this.getItemClass(index), className: this.getItemClass(index),
onClick: this.handleItemClick.bind(this, index), onClick: this.onItemClick.bind(this, index),
tabIndex: (this.props.tabbable) ? '0' : null,
onKeyDown: this.onKeyDown.bind(this, index),
key: index key: index
}; };
} }
@ -98,7 +104,16 @@ class Menu extends React.Component {
return classNames(classes); return classNames(classes);
} }
handleItemClick(index) { onKeyDown(index, event) {
let enterKey = keyCode('ENTER');
let spaceKey = keyCode('SPACE');
if(event.keyCode === enterKey || event.keyCode === spaceKey) {
this.onItemClick(index);
}
}
onItemClick(index) {
if (this.props.onItemClick) { if (this.props.onItemClick) {
this.props.onItemClick(index); this.props.onItemClick(index);
} }

View File

@ -4,8 +4,8 @@ import { Provider } from 'react-redux';
import SessionActions from 'actions/session-actions'; import SessionActions from 'actions/session-actions';
import ConfigActions from 'actions/config-actions'; import ConfigActions from 'actions/config-actions';
import routes from './Routes'; import routes from 'app/Routes';
import store from './store'; import store from 'app/store';
if ( process.env.NODE_ENV !== 'production' ) { if ( process.env.NODE_ENV !== 'production' ) {
// Enable React devtools // Enable React devtools