Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('filterOption is false', () => {
const wrapper = mount<select>(
</select>
<option value="1">1</option>
<option value="2">2</option>
,
);
// @HACK
const input = wrapper.find('input') as any;
input.instance().focus = jest.fn();
input
.simulate('change', { target: { value: 'a' } })
.simulate('keyDown', { keyCode: KeyCode.ENTER });
expect(wrapper.state().value).toEqual(['a']);
expect(wrapper.find('.rc-select-selection__choice__content').text()).toBe('a');
});
updateHoverPoint(time => goTime(time, 1, 'days'));
}
return;
case KeyCode.HOME:
updateHoverPoint(time => goStartMonth(time));
return;
case KeyCode.END:
updateHoverPoint(time => goEndMonth(time));
return;
case KeyCode.PAGE_DOWN:
updateHoverPoint(time => goTime(time, 1, 'month'));
return;
case KeyCode.PAGE_UP:
updateHoverPoint(time => goTime(time, -1, 'month'));
return;
case KeyCode.ENTER: {
let lastValue: Moment;
if (hoverValue.length === 0) {
lastValue = updateHoverPoint(time => time);
} else if (hoverValue.length === 1) {
// eslint-disable-next-line prefer-destructuring
lastValue = hoverValue[0];
} else {
lastValue = hoverValue[0].isSame(firstSelectedValue, 'day')
? hoverValue[1]
: hoverValue[0];
}
if (lastValue && (!disabledDate || !disabledDate(lastValue))) {
this.onSelect(lastValue);
}
event.preventDefault();
return;
it('not close on enter if disabled date', () => {
const picker = renderPicker({ value: moment() }, { disabledDate: () => true });
picker.find('.rc-calendar-picker-input').simulate('click');
picker.find('.rc-calendar-input').simulate('keyDown', {
keyCode: keyCode.ENTER,
});
expect(picker.state().open).toBe(true);
});
});
it('allow user input tags', () => {
const wrapper = mount<select>(</select>);
wrapper
.find('input')
.simulate('change', { target: { value: 'foo' } })
.simulate('keyDown', { keyCode: KeyCode.ENTER });
expect(wrapper.state().value).toEqual(['foo']);
expect(
wrapper
.update()
.find('.rc-select-selection__choice__content')
.text(),
).toBe('foo');
});
wrapper
.find('input')
.at(0)
.simulate('change', {
target: {
value: '1/1/2000',
},
});
expect(onSelect.mock.calls[0][1].source).toEqual('dateInput');
wrapper
.find('input')
.at(0)
.simulate('keyDown', {
keyCode: keyCode.ENTER,
});
expect(onSelect.mock.calls[1][1].source).toEqual('dateInputSelect');
});
onKeyDown = (e) => {
const keyCode = e.keyCode;
if (keyCode === KeyCode.ENTER) {
this.onClick(e);
return true;
}
};
onKeyDown = event => {
const { keyCode } = event;
const { onSelect, value, disabledDate } = this.props;
if (keyCode === KeyCode.ENTER && onSelect) {
const validateDate = !disabledDate || !disabledDate(value);
if (validateDate) {
onSelect(value.clone());
}
event.preventDefault();
}
};
updateHoverPoint((time) => goTime(time, 1, 'days'));
}
return;
case KeyCode.HOME:
updateHoverPoint((time) => goStartMonth(time));
return;
case KeyCode.END:
updateHoverPoint((time) => goEndMonth(time));
return;
case KeyCode.PAGE_DOWN:
updateHoverPoint((time) => goTime(time, 1, 'month'));
return;
case KeyCode.PAGE_UP:
updateHoverPoint((time) => goTime(time, -1, 'month'));
return;
case KeyCode.ENTER: {
let lastValue;
if (hoverValue.length === 0) {
lastValue = updateHoverPoint(time => time);
} else if (hoverValue.length === 1) {
lastValue = hoverValue[0];
} else {
lastValue = hoverValue[0].isSame(firstSelectedValue, 'day') ?
hoverValue[1] : hoverValue[0];
}
if (lastValue && (!disabledDate || !disabledDate(lastValue))) {
this.onSelect(lastValue);
}
event.preventDefault();
return;
}
default:
(ev: React.KeyboardEvent) => {
if (ev.which === KeyCode.ENTER) {
toggleDropdownVisible()
} else if (ev.which === KeyCode.ESC) {
setDropdownVisible(false)
}
onKeyDown && onKeyDown(ev)
},
[toggleDropdownVisible, onKeyDown]
return 1;
case KeyCode.END:
this.setValue(
goEndMonth(this.state.value),
);
event.preventDefault();
return 1;
case KeyCode.PAGE_DOWN:
this.goTime(1, 'month');
event.preventDefault();
return 1;
case KeyCode.PAGE_UP:
this.goTime(-1, 'month');
event.preventDefault();
return 1;
case KeyCode.ENTER:
if (!disabledDate || !disabledDate(value)) {
this.onSelect(value, {
source: 'keyboard',
});
}
event.preventDefault();
return 1;
}
}