Skip to content

Commit 04fdf10

Browse files
committed
Pass field-dirty,field-error className to field component
1 parent 2199337 commit 04fdf10

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

docs/Troubleshooting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ When you use [styled-components](https://github.com/styled-components/styled-com
3636
```tsx
3737
// Example styled CustomInput
3838
const StyledCustomInput: typeof CustomInput = styled(CustomInput)`
39-
&.typed-form-dirty {
39+
&.field-dirty {
4040
background-color: #0001;
4141
}
4242
43-
&.typed-form-error {
43+
&.field-error {
4444
color: red;
4545
font-weight: bold;
4646
}

docs/reference/Field.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The input transforms its value based on the `type` prop, which **currently suppo
2121

2222
It is allowed to use multiple inputs on the same field, all of them will be synchronized.
2323

24-
These inputs are given a `className` when errored (`typed-form-error`) or modified (`typed-form-dirty`) by default.
24+
These inputs are given a `className` when errored (`field-error`) or modified (`field-dirty`) by default.
2525

2626
## Examples
2727

@@ -180,11 +180,11 @@ The name of the field in the form that will be bound to this input.
180180

181181
#### `errorClassName` and `errorStyle`
182182

183-
The className and/or style to set when there is an error on this field. Default className is `typed-form-error`.
183+
The className and/or style to set when there is an error on this field. Default className is `field-error`.
184184

185185
#### `dirtyClassName` and `dirtyStyle`
186186

187-
The className and/or style to set when this field has been modified. Default className is `typed-form-dirty`.
187+
The className and/or style to set when this field has been modified. Default className is `field-dirty`.
188188

189189
#### `dateAsNumber` (only type="date")
190190

src/Field.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export function Field<T extends object, K extends keyof T, C extends React.Funct
6666
checked: typeof v === "boolean" ? v : undefined,
6767
value: typeof v === "boolean" ? undefined : v,
6868
disabled: field.state.isSubmitting || props.disabled,
69+
className: (field.dirty ? "field-dirty " : "") + (field.error ? "field-error " : "") + props.className,
6970
field,
7071
onChange: (ev: any) => {
7172
let v = "target" in ev ? (["checkbox", "radio"].includes(props.type!) ? ev.target.checked : ev.target.value) : ev;

testing/src/index.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
body {
22
margin: 0;
33
padding: 0;
4-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
4+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
5+
sans-serif;
56
-webkit-font-smoothing: antialiased;
67
-moz-osx-font-smoothing: grayscale;
78
}
@@ -32,12 +33,12 @@ small {
3233
font-weight: normal;
3334
}
3435

35-
.typed-form-dirty {
36+
.field-dirty {
3637
outline: 3px solid #0004;
3738
transition: 50ms linear;
3839
}
3940

40-
.typed-form-error {
41+
.field-error {
4142
outline: 3px solid #f009;
4243
transition: 50ms linear;
4344
}

0 commit comments

Comments
 (0)