Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onKeyDown = (e: React.KeyboardEvent) => {
const props = this.props;
if (props.keyboard && e.keyCode === KeyCode.ESC) {
e.stopPropagation();
this.close(e);
return;
}
// keep focus inside dialog
if (props.visible) {
if (e.keyCode === KeyCode.TAB) {
const activeElement = document.activeElement;
const sentinelStart = this.sentinelStart;
if (e.shiftKey) {
if (activeElement === sentinelStart) {
this.sentinelEnd.focus();
}
} else if (activeElement === this.sentinelEnd) {
sentinelStart.focus();
}
const item = memoFlattenOptions[activeIndex];
if (item && !(item.data as OptionData).disabled) {
onSelectValue((item.data as OptionData).value);
} else {
onSelectValue(null);
}
if (open) {
event.preventDefault();
}
break;
}
// >>> Close
case KeyCode.ESC: {
onToggleOpen(false);
}
}
},
onKeyUp: () => {},
it(`${name} to open`, () => {
wrapper.find('input').simulate('keyDown', { keyCode });
expect(wrapper.find('.rc-cascader-menus-hidden').length).toBe(0);
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.ESC });
expect(wrapper.find('.rc-cascader-menus-hidden').length).toBe(1);
});
});
it('close by ESC key', () => {
const picker = renderPicker();
picker.find('.rc-calendar-picker-input').simulate('click');
picker.find('.rc-calendar').simulate('keyDown', {
keyCode: keyCode.ESC,
});
expect(picker.state().open).toBe(false);
});
}, (done) => {
Simulate.keyDown($('.rc-dialog')[0], {
keyCode: KeyCode.ESC,
});
setTimeout(done, 10);
}, (done) => {
expect(callback1).to.be(1);
(ev: React.KeyboardEvent) => {
if (ev.which === KeyCode.ENTER) {
toggleDropdownVisible()
} else if (ev.which === KeyCode.ESC) {
setDropdownVisible(false)
}
onKeyDown && onKeyDown(ev)
},
[toggleDropdownVisible, onKeyDown]
onKeyDown = e => {
if (e.keyCode === KeyCode.ESC) {
const { onMaskClick, onHandleClick } = this.props;
e.stopPropagation();
const onClose = onHandleClick || onMaskClick;
if (onClose) {
onClose(e);
} else {
this.onTouchEnd(e, true);
}
}
};
onCalendarKeyDown = event => {
if (event.keyCode === KeyCode.ESC) {
event.stopPropagation();
this.close(this.focus);
}
};
onCalendarKeyDown: function onCalendarKeyDown(event) {
if (event.keyCode === KeyCode.ESC) {
event.stopPropagation();
this.close(this.focus);
}
},
onCalendarSelect: function onCalendarSelect(value) {
> = event => {
const { which } = event;
if (which === KeyCode.UP || which === KeyCode.DOWN) {
event.preventDefault();
}
if (onInputKeyDown) {
onInputKeyDown(event);
}
if (
![KeyCode.SHIFT, KeyCode.TAB, KeyCode.BACKSPACE, KeyCode.ESC].includes(
which,
)
) {
onToggleOpen(true);
}
};