Skip to content

Commit 988c7a2

Browse files
authored
Merge pull request #138 from unchartedsoftware/issue/136
#136 - setup enter and tab key handling for date picker
2 parents 8d5b226 + 6c004c0 commit 988c7a2

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/components/assistants/temporal/datetime-entry-assistant.jsx

+25-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { bind } from 'decko';
33
import { Assistant } from '../../assistant';
44
import TinyDatePicker from 'tiny-date-picker';
55
import { toChar } from '../../../lib/string-util';
6+
import { ENTER, TAB } from '../../../lib/keys';
67

78
/**
89
* A visual interaction mechanism for supplying values
@@ -43,13 +44,13 @@ export class DateTimeEntryAssistant extends Assistant {
4344
if (this.dateInput) {
4445
this.dateInput.setState({
4546
selectedDate: newDate,
46-
highlightedDate: newDate
47+
hilightedDate: newDate
4748
});
4849
}
4950
} else if (this.dateInput) {
5051
this.dateInput.setState({
5152
selectedDate: null,
52-
highlightedDate: new Date()
53+
hilightedDate: new Date()
5354
});
5455
}
5556
}
@@ -89,6 +90,28 @@ export class DateTimeEntryAssistant extends Assistant {
8990
this.requestRemoveArchivedValue(idx);
9091
}
9192

93+
delegateEvent (e) {
94+
let consumed = false;
95+
switch (e.keyCode) {
96+
case ENTER:
97+
case TAB:
98+
// Use the currently "focused" date if we dont have a value
99+
if (this.boxedValue == null && this.dateInput && this.dateInput.state.hilightedDate) {
100+
this.boxedValue = this.dateInput.state.hilightedDate;
101+
}
102+
103+
this.requestTransition();
104+
105+
consumed = true;
106+
break;
107+
}
108+
if (consumed) {
109+
e.stopPropagation();
110+
e.preventDefault();
111+
}
112+
return consumed;
113+
}
114+
92115
renderArchive () {
93116
if (this.machineState.isMultivalue) {
94117
return (

0 commit comments

Comments
 (0)