Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint-disable react/no-multi-comp */
const keyCode = require('rc-util').KeyCode;
const expect = require('expect.js');
const InputNum = require('../index');
const React = require('react');
const TestUtils = require('react-addons-test-utils');
const ReactDOM = require('react-dom');
const Simulate = TestUtils.Simulate;
require('../assets/index.less');
const defaultValue = 98;
describe('inputNumber', () => {
const container = document.createElement('div');
document.body.appendChild(container);
const Component = React.createClass({
getInitialState() {
onKeyDown: function onKeyDown(event) {
if (event.target.nodeName.toLowerCase() === 'input') {
return undefined;
}
var keyCode = event.keyCode;
// mac
var ctrlKey = event.ctrlKey || event.metaKey;
switch (keyCode) {
case _rcUtil.KeyCode.DOWN:
goWeek.call(this, 1);
event.preventDefault();
return 1;
case _rcUtil.KeyCode.UP:
goWeek.call(this, -1);
event.preventDefault();
return 1;
case _rcUtil.KeyCode.LEFT:
if (ctrlKey) {
this.previousYear();
} else {
goDay.call(this, -1);
}
event.preventDefault();
return 1;
case _rcUtil.KeyCode.RIGHT:
var React = require('react');
var DateTimeFormat = require('gregorian-calendar-format');
var GregorianCalendar = require('gregorian-calendar');
var rcUtil = require('rc-util');
var KeyCode = rcUtil.KeyCode;
var staticPrefixClsFn = require('./util/prefixClsFn');
function noop() {
}
function goStartMonth() {
var next = this.state.value.clone();
next.setDayOfMonth(1);
this.setState({value: next});
}
function goEndMonth() {
var next = this.state.value.clone();
next.setDayOfMonth(next.getActualMaximum(GregorianCalendar.MONTH));
this.setState({value: next});
}
onKeyDown: function onKeyDown(event) {
var props = this.props;
if (props.disabled) {
return;
}
var keyCode = event.keyCode;
if (this.state.open && !this.getInputDOMNode()) {
this.onInputKeyDown(event);
} else if (keyCode === _rcUtil.KeyCode.ENTER || keyCode === _rcUtil.KeyCode.DOWN) {
this.setOpenState(true);
event.preventDefault();
}
},
onKeyDown: function onKeyDown(event) {
var keyCode = event.keyCode;
var ctrlKey = event.ctrlKey || event.metaKey;
var stateValue = this.state.value;
var value = stateValue;
switch (keyCode) {
case _rcUtil.KeyCode.DOWN:
value = stateValue.clone();
value.addMonth(3);
break;
case _rcUtil.KeyCode.UP:
value = stateValue.clone();
value.addMonth(-3);
break;
case _rcUtil.KeyCode.LEFT:
value = stateValue.clone();
if (ctrlKey) {
value.addYear(-1);
} else {
value.addMonth(-1);
}
break;
case _rcUtil.KeyCode.RIGHT:
value = stateValue.clone();
if (ctrlKey) {
value.addYear(1);
} else {
onCalendarKeyDown: function onCalendarKeyDown(event) {
if (event.keyCode === _rcUtil.KeyCode.ESC) {
event.stopPropagation();
this.close(this.focus);
}
},
onCalendarSelect: function onCalendarSelect(value) {
var React = require('react');
var DateTimeFormat = require('gregorian-calendar-format');
var rcUtil = require('rc-util');
var KeyCode = rcUtil.KeyCode;
var domAlign = require('dom-align');
var orientMap = {
tl: ['top', 'left'],
tr: ['top', 'right'],
bl: ['bottom', 'left'],
br: ['bottom', 'right']
};
var createChainedFunction = rcUtil.createChainedFunction;
function getImmutableOrient(orient) {
if (orient) {
for (var i in orientMap) {
var original = orientMap[i];
if (original[0] === orient[0] && original[1] === orient[1]) {
return original;
}
onInputKeyDown: function onInputKeyDown(event) {
var props = this.props;
if (props.disabled) {
return;
}
var state = this.state;
var keyCode = event.keyCode;
if ((0, _util.isMultipleOrTags)(props) && !event.target.value && keyCode === _rcUtil.KeyCode.BACKSPACE) {
var value = state.value.concat();
if (value.length) {
var label = state.label.concat();
var popValue = value.pop();
label.pop();
props.onDeselect(popValue);
this.fireChange(value, label);
}
return;
}
if (keyCode === _rcUtil.KeyCode.DOWN) {
if (!state.open) {
this.openIfHasChildren();
event.preventDefault();
event.stopPropagation();
return;