Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 09-30 page up 08-30
keySimulateCheck(keyCode.PAGE_UP, 'Aug', 30);
// 08-30 page down 09-30
keySimulateCheck(keyCode.PAGE_DOWN, 'Sep', 30);
keyDown(keyCode.BACKSLASH);
expect(keyDownEvent).toEqual(1);
keyDown(keyCode.ENTER);
expect(onChange.mock.calls[0][0][0].format(format)).toEqual('2000-09-30');
// 2000-09-30 ctrl+right 2001-09-30
keySimulateCheck(keyCode.RIGHT, 'Sep', 30, {
ctrlKey: true,
});
expect(wrapper.find('.rc-calendar-range-right .rc-calendar-year-select').text()).toEqual(
'2001',
);
// 2001-09-30 ctrl+right 2000-09-30
keySimulateCheck(keyCode.LEFT, 'Sep', 30, {
ctrlKey: true,
});
keyDown(keyCode.ENTER);
expect(onChange.mock.calls[1][0][0].format(format)).toEqual('2000-09-30');
expect(onChange.mock.calls[1][0][1].format(format)).toEqual('2000-09-30');
expect(onSelect.mock.calls[0][0][0].format(format)).toEqual('2000-09-30');
it('right works', () => {
const original = calendar.state().value;
const expected = original.clone();
expected.add(1, 'day');
calendar.simulate('keyDown', { keyCode: keyCode.RIGHT });
expect(calendar.state().value.date()).toBe(expected.date());
expect(input.getDOMNode().value).toBe('');
});
it('should have keyboard support', () => {
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.DOWN });
menus = wrapper.find('.rc-cascader-menu');
expect(wrapper.find('.rc-cascader-menus-hidden').length).toBe(0);
expect(menus.length).toBe(1);
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.DOWN });
menus = wrapper.find('.rc-cascader-menu');
expect(menus.length).toBe(2);
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.RIGHT });
menus = wrapper.find('.rc-cascader-menu');
expect(menus.length).toBe(3);
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.RIGHT });
menus = wrapper.find('.rc-cascader-menu');
expect(menus.length).toBe(3);
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.LEFT });
menus = wrapper.find('.rc-cascader-menu');
expect(menus.length).toBe(3);
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.QUESTION_MARK });
menus = wrapper.find('.rc-cascader-menu');
expect(menus.length).toBe(3);
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.LEFT });
menus = wrapper.find('.rc-cascader-menu');
expect(menus.length).toBe(2);
expect(
wrapper
).toBe(false);
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.BACKSPACE });
expect(
wrapper
.find('.rc-cascader-menus')
.hostNodes()
.hasClass('rc-cascader-menus-hidden'),
).toBe(true);
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.DOWN });
expect(
wrapper
.find('.rc-cascader-menus')
.hostNodes()
.hasClass('rc-cascader-menus-hidden'),
).toBe(false);
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.RIGHT });
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.ESC });
expect(
wrapper
.find('.rc-cascader-menus')
.hostNodes()
.hasClass('rc-cascader-menus-hidden'),
).toBe(true);
});
value = stateValue.clone();
value.add(3, 'months');
break;
case KeyCode.UP:
value = stateValue.clone();
value.add(-3, 'months');
break;
case KeyCode.LEFT:
value = stateValue.clone();
if (ctrlKey) {
value.add(-1, 'years');
} else {
value.add(-1, 'months');
}
break;
case KeyCode.RIGHT:
value = stateValue.clone();
if (ctrlKey) {
value.add(1, 'years');
} else {
value.add(1, 'months');
}
break;
case KeyCode.ENTER:
if (!disabledDate || !disabledDate(stateValue)) {
this.onSelect(stateValue);
}
event.preventDefault();
return 1;
default:
return undefined;
}
value = stateValue.clone();
value.add(3, 'months');
break;
case KeyCode.UP:
value = stateValue.clone();
value.add(-3, 'months');
break;
case KeyCode.LEFT:
value = stateValue.clone();
if (ctrlKey) {
value.add(-1, 'years');
} else {
value.add(-1, 'months');
}
break;
case KeyCode.RIGHT:
value = stateValue.clone();
if (ctrlKey) {
value.add(1, 'years');
} else {
value.add(1, 'months');
}
break;
case KeyCode.ENTER:
if (!disabledDate || !disabledDate(stateValue)) {
this.onSelect(stateValue);
}
event.preventDefault();
return 1;
default:
return undefined;
}
this.goTime(1, 'weeks');
event.preventDefault();
return 1;
case KeyCode.UP:
this.goTime(-1, 'weeks');
event.preventDefault();
return 1;
case KeyCode.LEFT:
if (ctrlKey) {
this.goTime(-1, 'years');
} else {
this.goTime(-1, 'days');
}
event.preventDefault();
return 1;
case KeyCode.RIGHT:
if (ctrlKey) {
this.goTime(1, 'years');
} else {
this.goTime(1, 'days');
}
event.preventDefault();
return 1;
case KeyCode.HOME:
this.setValue(
goStartMonth(this.state.value),
);
event.preventDefault();
return 1;
case KeyCode.END:
this.setValue(
goEndMonth(this.state.value),
if (nextIndex !== -1) {
if (e.keyCode === KeyCode.DOWN) {
nextIndex += 1;
nextIndex = nextIndex >= currentOptions.length ? 0 : nextIndex;
} else {
nextIndex -= 1;
nextIndex = nextIndex < 0 ? currentOptions.length - 1 : nextIndex;
}
} else {
nextIndex = 0;
}
activeValue[currentLevel] = currentOptions[nextIndex][this.getFieldName('value')];
} else if (e.keyCode === KeyCode.LEFT || e.keyCode === KeyCode.BACKSPACE) {
e.preventDefault();
activeValue.splice(activeValue.length - 1, 1);
} else if (e.keyCode === KeyCode.RIGHT) {
e.preventDefault();
if (
currentOptions[currentIndex] &&
currentOptions[currentIndex][this.getFieldName('children')]
) {
activeValue.push(
currentOptions[currentIndex][this.getFieldName('children')][0][
this.getFieldName('value')
],
);
}
} else if (e.keyCode === KeyCode.ESC || e.keyCode === KeyCode.TAB) {
this.setPopupVisible(false);
return;
}
if (!activeValue || activeValue.length === 0) {
export function getKeyboardValueMutator(e) {
switch (e.keyCode) {
case keyCode.UP:
case keyCode.RIGHT:
return (value, props) => calculateNextValue('increase', value, props)
case keyCode.DOWN:
case keyCode.LEFT:
return (value, props) => calculateNextValue('decrease', value, props)
case keyCode.END:
return (value, props) => props.max
case keyCode.HOME:
return (value, props) => props.min
case keyCode.PAGE_UP:
return (value, props) => value + props.step * 2
case keyCode.PAGE_DOWN:
return (value, props) => value - props.step * 2
default: