Skip to content

Commit 9381135

Browse files
isTouched.
1 parent 187658d commit 9381135

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/app.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useState, useEffect, ErrorInfo } from "react";
22
import ReactDOM from "react-dom";
3-
import { TextField } from "./components/text-field";
43
import { GroupStoreMutable } from "./stores/group-store";
54
import { GroupContext, GroupContextObject } from "./contexts/group-context";
65
import { useForceUpdate } from "./force-update";

src/components/text-field.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ function useField(props: TextFieldProps): FieldResult {
5151
return;
5252
}
5353

54-
// Initial update is skipped, because field is registered during first render and
55-
// store listener is added asynchronously. The change action is emitted in-between.
5654
setCurrentValue(field.currentValue);
5755
};
56+
57+
// Initial update is skipped, because field is registered during first render and
58+
// store listener is added asynchronously. The change action is emitted in-between.
59+
// Thus, a manual update is needed.
5860
storeUpdated();
5961

6062
store.addListener(storeUpdated);
@@ -73,14 +75,8 @@ function useField(props: TextFieldProps): FieldResult {
7375
fieldProps: {
7476
value: currentValue,
7577
onChange: event => store.updateValue(fieldId, event.target.value),
76-
onFocus: () => {
77-
console.log(`Field '${fieldId}' has been focused.`);
78-
store.focus(fieldId);
79-
},
80-
onBlur: () => {
81-
console.log(`Field '${fieldId}' has been blurred.`);
82-
store.blur(fieldId);
83-
}
78+
onFocus: () => store.focus(fieldId),
79+
onBlur: () => store.blur(fieldId)
8480
}
8581
};
8682
}

src/stores/group-store.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ export class GroupStoreMutable extends TinyEmitter<Callback> {
8484
if (field == null) {
8585
return;
8686
}
87+
88+
// Value equality check should be abstracted for particular component and value type
89+
if (field.currentValue !== value) {
90+
field.isTouched = true;
91+
}
8792
field.currentValue = value;
8893
});
8994

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"jsx": "react",
55
"strict": true,
66
"esModuleInterop": true,
7+
"strictNullChecks": true,
78
"plugins": [
89
{
910
"name": "tslint-language-service",

0 commit comments

Comments
 (0)