Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onKeyDown = (event) => {
if (event.target.nodeName.toLowerCase() === 'input') {
return undefined;
}
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:
onKeyDown: event => {
const { which } = event;
switch (which) {
// >>> Arrow keys
case KeyCode.UP:
case KeyCode.DOWN: {
let offset = 0;
if (which === KeyCode.UP) {
offset = -1;
} else if (which === KeyCode.DOWN) {
offset = 1;
}
if (offset !== 0) {
const nextActiveIndex = getEnabledActiveIndex(
activeIndex + offset,
offset,
);
scrollIntoView(nextActiveIndex);
setActive(nextActiveIndex);
}
break;
}
// >>> Select
expect(instance.blurTimer).toBeTruthy();
instance.componentWillUnmount();
expect(instance.blurTimer).toBe(null);
});
it('clear dropdownContainer', () => {
instance.getDropdownContainer();
expect(instance.dropdownContainer).toBeTruthy();
instance.componentWillUnmount();
expect(instance.dropdownContainer).toBe(null);
});
});
[KeyCode.ENTER, KeyCode.DOWN].forEach(keyCode => {
it('open on key press', () => {
const wrapper = mount<select>(</select>);
wrapper.find('.rc-select-selection').simulate('keyDown', { keyCode });
expect(wrapper.state().open).toBe(true);
});
});
it('pass event to input', () => {
const wrapper = mount<select>(</select>);
wrapper.instance().onInputKeyDown = jest.fn();
wrapper.find('.rc-select').simulate('click');
wrapper.find('.rc-select-selection').simulate('keyDown');
expect(wrapper.instance().onInputKeyDown).toBeCalled();
});
step={1}
defaultValue={5}
useTouch
formatter={num => `$ ${num} boeing 737`}
parser={num => num.toString().split(' ')[1]}
/>);
},
});
example = ReactDOM.render(, container);
inputNumber = example.refs.inputNum;
inputElement = ReactDOM.findDOMNode(inputNumber.input);
Simulate.focus(inputElement);
Simulate.keyDown(inputElement, { keyCode: keyCode.UP });
expect(inputNumber.state.value).to.be(6);
expect(inputElement.value).to.be('$ 6 boeing 737');
Simulate.keyDown(inputElement, { keyCode: keyCode.DOWN });
expect(inputNumber.state.value).to.be(5);
expect(inputElement.value).to.be('$ 5 boeing 737');
Simulate.touchStart(ReactDOM.findDOMNode(inputNumber.upHandler));
expect(inputNumber.state.value).to.be(6);
expect(inputElement.value).to.be('$ 6 boeing 737');
});
});
}
if (keyCode === KeyCode.LEFT) {
let handled;
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);
}
};
}
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);
}
return undefined;
};
onKeyDown(e, callback) {
const keyCode = e.keyCode;
let handled;
this.getFlatInstanceArray().forEach((obj) => {
if (obj && obj.props.active && obj.onKeyDown) {
handled = obj.onKeyDown(e);
}
});
if (handled) {
return 1;
}
let activeItem = null;
if (keyCode === KeyCode.UP || keyCode === KeyCode.DOWN) {
activeItem = this.step(keyCode === KeyCode.UP ? -1 : 1);
}
if (activeItem) {
e.preventDefault();
updateActiveKey(this.getStore(), this.getEventKey(), activeItem.props.eventKey);
if (typeof callback === 'function') {
callback(activeItem);
}
return 1;
} else if (activeItem === undefined) {
e.preventDefault();
updateActiveKey(this.getStore(), this.getEventKey(), null);
return 1;
}
onKeyDown = event => {
if (!this.state.open && (event.keyCode === KeyCode.DOWN || event.keyCode === KeyCode.ENTER)) {
this.open();
event.preventDefault();
}
};
onKeyDown = (event) => {
if (event.target.nodeName.toLowerCase() === 'input') {
return undefined;
}else{
this.props.onKeyDown&&this.props.onKeyDown(event);
}
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:
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: