mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 05:08:36 +08:00
TimePicker: Close timepicker with esc (#39962)
This commit is contained in:
@ -66,6 +66,20 @@ export class UnthemedTimeRangePicker extends PureComponent<TimeRangePickerProps,
|
||||
this.setState({ isOpen: !isOpen });
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
window.addEventListener('keyup', this.onKeyUp);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
window.removeEventListener('keyup', this.onKeyUp);
|
||||
}
|
||||
|
||||
onKeyUp = (event: KeyboardEvent) => {
|
||||
if (event.code === 'Escape') {
|
||||
this.onClose();
|
||||
}
|
||||
};
|
||||
|
||||
onClose = () => {
|
||||
this.setState({ isOpen: false });
|
||||
};
|
||||
|
Reference in New Issue
Block a user