Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const keyCode = event.keyCode;
// mac
const ctrlKey = event.ctrlKey || event.metaKey;
const { disabledDate } = this.props;
const { value } = this.state;
switch (keyCode) {
case KeyCode.DOWN:
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:
// https://github.com/ant-design/ant-design/issues/6717
// Don't bind keyboard support when children specify the onKeyDown
if (children && children.props.onKeyDown) {
children.props.onKeyDown(e);
return;
}
const activeValue = [...this.state.activeValue];
const currentLevel = activeValue.length - 1 < 0 ? 0 : activeValue.length - 1;
const currentOptions = this.getCurrentLevelOptions();
const currentIndex = currentOptions
.map(o => o[this.getFieldName('value')])
.indexOf(activeValue[currentLevel]);
if (
e.keyCode !== KeyCode.DOWN &&
e.keyCode !== KeyCode.UP &&
e.keyCode !== KeyCode.LEFT &&
e.keyCode !== KeyCode.RIGHT &&
e.keyCode !== KeyCode.ENTER &&
e.keyCode !== KeyCode.SPACE &&
e.keyCode !== KeyCode.BACKSPACE &&
e.keyCode !== KeyCode.ESC &&
e.keyCode !== KeyCode.TAB
) {
return;
}
// Press any keys above to reopen menu
if (
!this.state.popupVisible &&
e.keyCode !== KeyCode.BACKSPACE &&
e.keyCode !== KeyCode.LEFT &&
e.keyCode !== KeyCode.RIGHT &&
e.keyCode !== KeyCode.ESC &&
this.onTitleClick(e);
updateDefaultActiveFirst(store, this.props.eventKey, true);
return true;
}
if (keyCode === KeyCode.RIGHT) {
if (isOpen) {
menu.onKeyDown(e);
} else {
this.triggerOpenChange(true);
// need to update current menu's defaultActiveFirst value
updateDefaultActiveFirst(store, this.props.eventKey, true);
}
return true;
}
if (keyCode === KeyCode.LEFT) {
let handled: boolean;
if (isOpen) {
handled = menu.onKeyDown(e);
} else {
return undefined;
}
if (!handled) {
this.triggerOpenChange(false);
handled = true;
}
return handled;
}
if (isOpen && (keyCode === KeyCode.UP || keyCode === KeyCode.DOWN)) {
return menu.onKeyDown(e);
}
it('enter not to select disabled month', () => {
const onSelect = jest.fn();
function disabledDate(current) {
if (!current) {
return false;
}
const date = moment();
return current.month() < date.month();
}
wrapper = mount();
wrapper.simulate('keydown', {
keyCode: keyCode.LEFT,
});
wrapper.simulate('keydown', {
keyCode: keyCode.ENTER,
});
expect(onSelect).not.toHaveBeenCalled();
});
it('left works', () => {
const original = calendar.state().value;
const expected = original.clone();
expected.add(-1, 'day');
calendar.simulate('keyDown', { keyCode: keyCode.LEFT });
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
.find('.rc-cascader-menu-item-active')
.at(0)
.text(),
).toBe(addressOptions[0].label);
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.DOWN });
menus = wrapper.find('.rc-cascader-menu');
}
}
event.preventDefault();
return nextHoverTime;
};
switch (keyCode) {
case KeyCode.DOWN:
updateHoverPoint((time) => goTime(time, 1, 'weeks'));
return;
case KeyCode.UP:
updateHoverPoint((time) => goTime(time, -1, 'weeks'));
return;
case KeyCode.LEFT:
if (ctrlKey) {
updateHoverPoint((time) => goTime(time, -1, 'years'));
} else {
updateHoverPoint((time) => goTime(time, -1, 'days'));
}
return;
case KeyCode.RIGHT:
if (ctrlKey) {
updateHoverPoint((time) => goTime(time, 1, 'years'));
} else {
updateHoverPoint((time) => goTime(time, 1, 'days'));
}
return;
case KeyCode.HOME:
updateHoverPoint((time) => goStartMonth(time));
return;
}
}
event.preventDefault();
return nextHoverTime;
};
switch (keyCode) {
case KeyCode.DOWN:
updateHoverPoint(time => goTime(time, 1, 'weeks'));
return;
case KeyCode.UP:
updateHoverPoint(time => goTime(time, -1, 'weeks'));
return;
case KeyCode.LEFT:
if (ctrlKey) {
updateHoverPoint(time => goTime(time, -1, 'years'));
} else {
updateHoverPoint(time => goTime(time, -1, 'days'));
}
return;
case KeyCode.RIGHT:
if (ctrlKey) {
updateHoverPoint(time => goTime(time, 1, 'years'));
} else {
updateHoverPoint(time => goTime(time, 1, 'days'));
}
return;
case KeyCode.HOME:
updateHoverPoint(time => goStartMonth(time));
return;
onKeyDown = event => {
const { keyCode } = event;
const ctrlKey = event.ctrlKey || event.metaKey;
const stateValue = this.state.value;
const { disabledDate } = this.props;
let value = stateValue;
switch (keyCode) {
case KeyCode.DOWN:
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:
}
const keyCode = event.keyCode;
const ctrlKey = event.ctrlKey || event.metaKey;
const stateValue = this.state.value;
const { disabledDate } = this.props;
let value = stateValue;
switch (keyCode) {
case KeyCode.DOWN:
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: