Skip to content

Commit 2ca8b15

Browse files
author
JelteMX
committed
Add focus handler
1 parent 3cbade3 commit 2ca8b15

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "timeinput",
33
"widgetName": "TimeInput",
4-
"version": "1.0.0",
4+
"version": "1.1.0",
55
"description": "Input field/dropdown for time",
66
"copyright": "Jelte Lagendijk 2020",
77
"author": "Jelte Lagendijk",

src/components/TimeSelector.tsx

+33-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@ export interface TimeSelectorProps extends TimePickerProps {
88
containerClassName?: string;
99
}
1010

11-
export class TimeSelector extends Component<TimeSelectorProps> {
11+
interface TimeSelectorState {
12+
focus: boolean;
13+
}
14+
15+
export class TimeSelector extends Component<TimeSelectorProps, TimeSelectorState> {
16+
onOpen = this.openHandler.bind(this);
17+
onClose = this.closeHandler.bind(this);
18+
19+
constructor(props: TimeSelectorProps) {
20+
super(props);
21+
22+
this.state = {
23+
focus: false
24+
};
25+
}
26+
1227
render(): ReactNode {
1328
return (
1429
<FormGroup
@@ -23,12 +38,13 @@ export class TimeSelector extends Component<TimeSelectorProps> {
2338
)}
2439
>
2540
<TimePicker
41+
className={this.state.focus ? "focus" : ""}
2642
value={this.props.value}
2743
placement="bottomLeft"
2844
prefixCls="time-input-widget"
2945
onChange={this.props.onChange}
30-
onOpen={this.props.onOpen}
31-
onClose={this.props.onClose}
46+
onOpen={this.onOpen}
47+
onClose={this.onClose}
3248
allowEmpty={false}
3349
use12Hours={this.props.use12Hours}
3450
showHour={this.props.showHour}
@@ -54,4 +70,18 @@ export class TimeSelector extends Component<TimeSelectorProps> {
5470
const { label } = this.props;
5571
return label === null ? null : <label className={classnames("control-label", "col-sm-3")}>{label}</label>;
5672
}
73+
74+
openHandler(): void {
75+
this.setState({ focus: true });
76+
if (this.props.onOpen) {
77+
this.props.onOpen({ open: true });
78+
}
79+
}
80+
81+
closeHandler(): void {
82+
this.setState({ focus: false });
83+
if (this.props.onClose) {
84+
this.props.onClose({ open: false });
85+
}
86+
}
5787
}

src/package.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="TimeInput" version="1.0.0" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="TimeInput" version="1.1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="TimeInput.xml"/>
66
</widgetFiles>

0 commit comments

Comments
 (0)