@atlaskit/form 8.7.1 → 8.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/field.js +32 -13
- package/dist/cjs/form.js +23 -3
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/field.js +32 -13
- package/dist/es2019/form.js +22 -4
- package/dist/es2019/version.json +1 -1
- package/dist/esm/field.js +32 -13
- package/dist/esm/form.js +24 -4
- package/dist/esm/version.json +1 -1
- package/dist/types/form.d.ts +5 -1
- package/package.json +4 -4
- package/report.api.md +24 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/form
|
|
2
2
|
|
|
3
|
+
## 8.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 8.8.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`f2d39d67a70`](https://bitbucket.org/atlassian/atlassian-frontend/commits/f2d39d67a70) - Fixed the issue where field's value was reset on the component re-mount.
|
|
14
|
+
|
|
3
15
|
## 8.7.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/cjs/field.js
CHANGED
|
@@ -93,9 +93,22 @@ function isShallowEqual(previousValue, currentValue) {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
function Field(props) {
|
|
96
|
-
var
|
|
96
|
+
var _getCurrentValue;
|
|
97
|
+
|
|
98
|
+
var _useContext = (0, _react.useContext)(_form.FormContext),
|
|
99
|
+
registerField = _useContext.registerField,
|
|
100
|
+
getCurrentValue = _useContext.getCurrentValue;
|
|
101
|
+
|
|
97
102
|
var isDisabled = (0, _react.useContext)(_form.IsDisabledContext) || props.isDisabled || false;
|
|
98
103
|
var defaultValue = isFunction(props.defaultValue) ? props.defaultValue() : props.defaultValue;
|
|
104
|
+
var latestPropsRef = usePreviousRef(props);
|
|
105
|
+
/**
|
|
106
|
+
* HACK: defaultValue can potentially be an array or object which cannot be
|
|
107
|
+
* passed directly into a `useEffect` dependency array, since it will trigger
|
|
108
|
+
* the hook every time.
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
var isDefaultValueChanged = !isShallowEqual(latestPropsRef.current.defaultValue, props.defaultValue);
|
|
99
112
|
|
|
100
113
|
var _useState = (0, _react.useState)({
|
|
101
114
|
fieldProps: {
|
|
@@ -108,9 +121,13 @@ function Field(props) {
|
|
|
108
121
|
* prop types defined defaultValue as required, so inside the component it was not
|
|
109
122
|
* valid for defaultValue to be undefined. We need to suppress the error
|
|
110
123
|
* after changing defaultValue to explictly be an optional prop.
|
|
124
|
+
* If default value has changed we are using new default value.
|
|
125
|
+
* Otherwise we need to check if we already have value for this field
|
|
126
|
+
* (because we are using changing key prop to re-run field level validation, and that
|
|
127
|
+
* cause the component re-mounting) to not override the actual value with the default value.
|
|
111
128
|
*/
|
|
112
129
|
// @ts-ignore
|
|
113
|
-
value: defaultValue
|
|
130
|
+
value: isDefaultValueChanged ? defaultValue : (_getCurrentValue = getCurrentValue(props.name)) !== null && _getCurrentValue !== void 0 ? _getCurrentValue : defaultValue
|
|
114
131
|
},
|
|
115
132
|
error: undefined,
|
|
116
133
|
valid: false,
|
|
@@ -130,15 +147,7 @@ function Field(props) {
|
|
|
130
147
|
state = _useState2[0],
|
|
131
148
|
setState = _useState2[1];
|
|
132
149
|
|
|
133
|
-
var latestPropsRef = usePreviousRef(props);
|
|
134
150
|
var latestStateRef = usePreviousRef(state);
|
|
135
|
-
/**
|
|
136
|
-
* HACK: defaultValue can potentially be an array or object which cannot be
|
|
137
|
-
* passed directly into a `useEffect` dependency array, since it will trigger
|
|
138
|
-
* the hook every time.
|
|
139
|
-
*/
|
|
140
|
-
|
|
141
|
-
var hasDefaultValueChanged = isShallowEqual(latestPropsRef.current.defaultValue, props.defaultValue);
|
|
142
151
|
(0, _react.useEffect)(function () {
|
|
143
152
|
if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
|
|
144
153
|
(0, _tinyInvariant.default)(latestPropsRef.current.name, '@atlaskit/form: Field components have a required name prop');
|
|
@@ -159,8 +168,18 @@ function Field(props) {
|
|
|
159
168
|
};
|
|
160
169
|
}
|
|
161
170
|
|
|
162
|
-
var unregister = registerField(latestPropsRef.current.name,
|
|
163
|
-
|
|
171
|
+
var unregister = registerField(latestPropsRef.current.name,
|
|
172
|
+
/**
|
|
173
|
+
* Similar as for setting initial state value.
|
|
174
|
+
* Additionally we are checking if the default value is a function,
|
|
175
|
+
* it is used in checkbox fields, where fields with same name and
|
|
176
|
+
* defaultIsChecked should create array of values. In this situation we can't
|
|
177
|
+
* override the default value on re-registering, but also we don't need to change
|
|
178
|
+
* the key prop to re-run validation.
|
|
179
|
+
*/
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
isDefaultValueChanged || // @ts-ignore
|
|
182
|
+
isFunction(latestPropsRef.current.defaultValue) ? latestPropsRef.current.defaultValue : latestStateRef.current.fieldProps.value, function (fieldState) {
|
|
164
183
|
/**
|
|
165
184
|
* Do not update dirtySinceLastSubmit until submission has finished.
|
|
166
185
|
*/
|
|
@@ -248,7 +267,7 @@ function Field(props) {
|
|
|
248
267
|
}
|
|
249
268
|
});
|
|
250
269
|
return unregister;
|
|
251
|
-
}, [latestPropsRef, latestStateRef, registerField, props.name,
|
|
270
|
+
}, [latestPropsRef, latestStateRef, registerField, props.name, isDefaultValueChanged]);
|
|
252
271
|
var fieldId = (0, _react.useMemo)( // eslint-disable-next-line @repo/internal/react/disallow-unstable-values
|
|
253
272
|
function () {
|
|
254
273
|
return props.id ? props.id : "".concat(props.name, "-").concat((0, _reactUid.uid)({
|
package/dist/cjs/form.js
CHANGED
|
@@ -29,8 +29,13 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
29
29
|
*
|
|
30
30
|
* A form context creates a context for the field values and allows them to be accessed by the children.
|
|
31
31
|
*/
|
|
32
|
-
var FormContext = /*#__PURE__*/(0, _react.createContext)(
|
|
33
|
-
|
|
32
|
+
var FormContext = /*#__PURE__*/(0, _react.createContext)({
|
|
33
|
+
registerField: function registerField() {
|
|
34
|
+
return function () {};
|
|
35
|
+
},
|
|
36
|
+
getCurrentValue: function getCurrentValue() {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
34
39
|
});
|
|
35
40
|
/**
|
|
36
41
|
* __Is disabled context__
|
|
@@ -143,8 +148,23 @@ function Form(props) {
|
|
|
143
148
|
children = props.children;
|
|
144
149
|
var dirty = state.dirty,
|
|
145
150
|
submitting = state.submitting;
|
|
151
|
+
/**
|
|
152
|
+
* This method is needed in FormContext to use it on the field level
|
|
153
|
+
* to check the current value of the field in case of the component re-mounting.
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
var getCurrentValue = (0, _react.useCallback)(function (name) {
|
|
157
|
+
var formState = form.getState();
|
|
158
|
+
return (formState === null || formState === void 0 ? void 0 : formState.values[name]) || undefined;
|
|
159
|
+
}, [form]);
|
|
160
|
+
var FormContextValue = (0, _react.useMemo)(function () {
|
|
161
|
+
return {
|
|
162
|
+
registerField: registerField,
|
|
163
|
+
getCurrentValue: getCurrentValue
|
|
164
|
+
};
|
|
165
|
+
}, [registerField, getCurrentValue]);
|
|
146
166
|
return /*#__PURE__*/_react.default.createElement(FormContext.Provider, {
|
|
147
|
-
value:
|
|
167
|
+
value: FormContextValue
|
|
148
168
|
}, /*#__PURE__*/_react.default.createElement(IsDisabledContext.Provider, {
|
|
149
169
|
value: isDisabled
|
|
150
170
|
}, children({
|
package/dist/cjs/version.json
CHANGED
package/dist/es2019/field.js
CHANGED
|
@@ -65,9 +65,22 @@ function isShallowEqual(previousValue, currentValue) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export default function Field(props) {
|
|
68
|
-
|
|
68
|
+
var _getCurrentValue;
|
|
69
|
+
|
|
70
|
+
const {
|
|
71
|
+
registerField,
|
|
72
|
+
getCurrentValue
|
|
73
|
+
} = useContext(FormContext);
|
|
69
74
|
const isDisabled = useContext(IsDisabledContext) || props.isDisabled || false;
|
|
70
75
|
const defaultValue = isFunction(props.defaultValue) ? props.defaultValue() : props.defaultValue;
|
|
76
|
+
const latestPropsRef = usePreviousRef(props);
|
|
77
|
+
/**
|
|
78
|
+
* HACK: defaultValue can potentially be an array or object which cannot be
|
|
79
|
+
* passed directly into a `useEffect` dependency array, since it will trigger
|
|
80
|
+
* the hook every time.
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
const isDefaultValueChanged = !isShallowEqual(latestPropsRef.current.defaultValue, props.defaultValue);
|
|
71
84
|
const [state, setState] = useState({
|
|
72
85
|
fieldProps: {
|
|
73
86
|
onChange: () => {},
|
|
@@ -79,9 +92,13 @@ export default function Field(props) {
|
|
|
79
92
|
* prop types defined defaultValue as required, so inside the component it was not
|
|
80
93
|
* valid for defaultValue to be undefined. We need to suppress the error
|
|
81
94
|
* after changing defaultValue to explictly be an optional prop.
|
|
95
|
+
* If default value has changed we are using new default value.
|
|
96
|
+
* Otherwise we need to check if we already have value for this field
|
|
97
|
+
* (because we are using changing key prop to re-run field level validation, and that
|
|
98
|
+
* cause the component re-mounting) to not override the actual value with the default value.
|
|
82
99
|
*/
|
|
83
100
|
// @ts-ignore
|
|
84
|
-
value: defaultValue
|
|
101
|
+
value: isDefaultValueChanged ? defaultValue : (_getCurrentValue = getCurrentValue(props.name)) !== null && _getCurrentValue !== void 0 ? _getCurrentValue : defaultValue
|
|
85
102
|
},
|
|
86
103
|
error: undefined,
|
|
87
104
|
valid: false,
|
|
@@ -97,15 +114,7 @@ export default function Field(props) {
|
|
|
97
114
|
submitError: undefined
|
|
98
115
|
}
|
|
99
116
|
});
|
|
100
|
-
const latestPropsRef = usePreviousRef(props);
|
|
101
117
|
const latestStateRef = usePreviousRef(state);
|
|
102
|
-
/**
|
|
103
|
-
* HACK: defaultValue can potentially be an array or object which cannot be
|
|
104
|
-
* passed directly into a `useEffect` dependency array, since it will trigger
|
|
105
|
-
* the hook every time.
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
const hasDefaultValueChanged = isShallowEqual(latestPropsRef.current.defaultValue, props.defaultValue);
|
|
109
118
|
useEffect(() => {
|
|
110
119
|
if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
|
|
111
120
|
invariant(latestPropsRef.current.name, '@atlaskit/form: Field components have a required name prop');
|
|
@@ -125,8 +134,18 @@ export default function Field(props) {
|
|
|
125
134
|
};
|
|
126
135
|
}
|
|
127
136
|
|
|
128
|
-
const unregister = registerField(latestPropsRef.current.name,
|
|
129
|
-
|
|
137
|
+
const unregister = registerField(latestPropsRef.current.name,
|
|
138
|
+
/**
|
|
139
|
+
* Similar as for setting initial state value.
|
|
140
|
+
* Additionally we are checking if the default value is a function,
|
|
141
|
+
* it is used in checkbox fields, where fields with same name and
|
|
142
|
+
* defaultIsChecked should create array of values. In this situation we can't
|
|
143
|
+
* override the default value on re-registering, but also we don't need to change
|
|
144
|
+
* the key prop to re-run validation.
|
|
145
|
+
*/
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
isDefaultValueChanged || // @ts-ignore
|
|
148
|
+
isFunction(latestPropsRef.current.defaultValue) ? latestPropsRef.current.defaultValue : latestStateRef.current.fieldProps.value, fieldState => {
|
|
130
149
|
/**
|
|
131
150
|
* Do not update dirtySinceLastSubmit until submission has finished.
|
|
132
151
|
*/
|
|
@@ -214,7 +233,7 @@ export default function Field(props) {
|
|
|
214
233
|
}
|
|
215
234
|
});
|
|
216
235
|
return unregister;
|
|
217
|
-
}, [latestPropsRef, latestStateRef, registerField, props.name,
|
|
236
|
+
}, [latestPropsRef, latestStateRef, registerField, props.name, isDefaultValueChanged]);
|
|
218
237
|
const fieldId = useMemo( // eslint-disable-next-line @repo/internal/react/disallow-unstable-values
|
|
219
238
|
() => props.id ? props.id : `${props.name}-${uid({
|
|
220
239
|
id: props.name
|
package/dist/es2019/form.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { createContext, useCallback, useEffect, useRef, useState } from 'react';
|
|
1
|
+
import React, { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { createForm } from 'final-form';
|
|
3
3
|
import createDecorator from 'final-form-focus';
|
|
4
4
|
import set from 'lodash/set';
|
|
@@ -8,8 +8,11 @@ import set from 'lodash/set';
|
|
|
8
8
|
*
|
|
9
9
|
* A form context creates a context for the field values and allows them to be accessed by the children.
|
|
10
10
|
*/
|
|
11
|
-
export const FormContext = /*#__PURE__*/createContext(
|
|
12
|
-
|
|
11
|
+
export const FormContext = /*#__PURE__*/createContext({
|
|
12
|
+
registerField: function () {
|
|
13
|
+
return () => {};
|
|
14
|
+
},
|
|
15
|
+
getCurrentValue: () => undefined
|
|
13
16
|
});
|
|
14
17
|
/**
|
|
15
18
|
* __Is disabled context__
|
|
@@ -105,8 +108,23 @@ export default function Form(props) {
|
|
|
105
108
|
dirty,
|
|
106
109
|
submitting
|
|
107
110
|
} = state;
|
|
111
|
+
/**
|
|
112
|
+
* This method is needed in FormContext to use it on the field level
|
|
113
|
+
* to check the current value of the field in case of the component re-mounting.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
const getCurrentValue = useCallback(name => {
|
|
117
|
+
const formState = form.getState();
|
|
118
|
+
return (formState === null || formState === void 0 ? void 0 : formState.values[name]) || undefined;
|
|
119
|
+
}, [form]);
|
|
120
|
+
const FormContextValue = useMemo(() => {
|
|
121
|
+
return {
|
|
122
|
+
registerField,
|
|
123
|
+
getCurrentValue
|
|
124
|
+
};
|
|
125
|
+
}, [registerField, getCurrentValue]);
|
|
108
126
|
return /*#__PURE__*/React.createElement(FormContext.Provider, {
|
|
109
|
-
value:
|
|
127
|
+
value: FormContextValue
|
|
110
128
|
}, /*#__PURE__*/React.createElement(IsDisabledContext.Provider, {
|
|
111
129
|
value: isDisabled
|
|
112
130
|
}, children({
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/field.js
CHANGED
|
@@ -73,9 +73,22 @@ function isShallowEqual(previousValue, currentValue) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
export default function Field(props) {
|
|
76
|
-
var
|
|
76
|
+
var _getCurrentValue;
|
|
77
|
+
|
|
78
|
+
var _useContext = useContext(FormContext),
|
|
79
|
+
registerField = _useContext.registerField,
|
|
80
|
+
getCurrentValue = _useContext.getCurrentValue;
|
|
81
|
+
|
|
77
82
|
var isDisabled = useContext(IsDisabledContext) || props.isDisabled || false;
|
|
78
83
|
var defaultValue = isFunction(props.defaultValue) ? props.defaultValue() : props.defaultValue;
|
|
84
|
+
var latestPropsRef = usePreviousRef(props);
|
|
85
|
+
/**
|
|
86
|
+
* HACK: defaultValue can potentially be an array or object which cannot be
|
|
87
|
+
* passed directly into a `useEffect` dependency array, since it will trigger
|
|
88
|
+
* the hook every time.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
var isDefaultValueChanged = !isShallowEqual(latestPropsRef.current.defaultValue, props.defaultValue);
|
|
79
92
|
|
|
80
93
|
var _useState = useState({
|
|
81
94
|
fieldProps: {
|
|
@@ -88,9 +101,13 @@ export default function Field(props) {
|
|
|
88
101
|
* prop types defined defaultValue as required, so inside the component it was not
|
|
89
102
|
* valid for defaultValue to be undefined. We need to suppress the error
|
|
90
103
|
* after changing defaultValue to explictly be an optional prop.
|
|
104
|
+
* If default value has changed we are using new default value.
|
|
105
|
+
* Otherwise we need to check if we already have value for this field
|
|
106
|
+
* (because we are using changing key prop to re-run field level validation, and that
|
|
107
|
+
* cause the component re-mounting) to not override the actual value with the default value.
|
|
91
108
|
*/
|
|
92
109
|
// @ts-ignore
|
|
93
|
-
value: defaultValue
|
|
110
|
+
value: isDefaultValueChanged ? defaultValue : (_getCurrentValue = getCurrentValue(props.name)) !== null && _getCurrentValue !== void 0 ? _getCurrentValue : defaultValue
|
|
94
111
|
},
|
|
95
112
|
error: undefined,
|
|
96
113
|
valid: false,
|
|
@@ -110,15 +127,7 @@ export default function Field(props) {
|
|
|
110
127
|
state = _useState2[0],
|
|
111
128
|
setState = _useState2[1];
|
|
112
129
|
|
|
113
|
-
var latestPropsRef = usePreviousRef(props);
|
|
114
130
|
var latestStateRef = usePreviousRef(state);
|
|
115
|
-
/**
|
|
116
|
-
* HACK: defaultValue can potentially be an array or object which cannot be
|
|
117
|
-
* passed directly into a `useEffect` dependency array, since it will trigger
|
|
118
|
-
* the hook every time.
|
|
119
|
-
*/
|
|
120
|
-
|
|
121
|
-
var hasDefaultValueChanged = isShallowEqual(latestPropsRef.current.defaultValue, props.defaultValue);
|
|
122
131
|
useEffect(function () {
|
|
123
132
|
if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
|
|
124
133
|
invariant(latestPropsRef.current.name, '@atlaskit/form: Field components have a required name prop');
|
|
@@ -139,8 +148,18 @@ export default function Field(props) {
|
|
|
139
148
|
};
|
|
140
149
|
}
|
|
141
150
|
|
|
142
|
-
var unregister = registerField(latestPropsRef.current.name,
|
|
143
|
-
|
|
151
|
+
var unregister = registerField(latestPropsRef.current.name,
|
|
152
|
+
/**
|
|
153
|
+
* Similar as for setting initial state value.
|
|
154
|
+
* Additionally we are checking if the default value is a function,
|
|
155
|
+
* it is used in checkbox fields, where fields with same name and
|
|
156
|
+
* defaultIsChecked should create array of values. In this situation we can't
|
|
157
|
+
* override the default value on re-registering, but also we don't need to change
|
|
158
|
+
* the key prop to re-run validation.
|
|
159
|
+
*/
|
|
160
|
+
// @ts-ignore
|
|
161
|
+
isDefaultValueChanged || // @ts-ignore
|
|
162
|
+
isFunction(latestPropsRef.current.defaultValue) ? latestPropsRef.current.defaultValue : latestStateRef.current.fieldProps.value, function (fieldState) {
|
|
144
163
|
/**
|
|
145
164
|
* Do not update dirtySinceLastSubmit until submission has finished.
|
|
146
165
|
*/
|
|
@@ -228,7 +247,7 @@ export default function Field(props) {
|
|
|
228
247
|
}
|
|
229
248
|
});
|
|
230
249
|
return unregister;
|
|
231
|
-
}, [latestPropsRef, latestStateRef, registerField, props.name,
|
|
250
|
+
}, [latestPropsRef, latestStateRef, registerField, props.name, isDefaultValueChanged]);
|
|
232
251
|
var fieldId = useMemo( // eslint-disable-next-line @repo/internal/react/disallow-unstable-values
|
|
233
252
|
function () {
|
|
234
253
|
return props.id ? props.id : "".concat(props.name, "-").concat(uid({
|
package/dist/esm/form.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import React, { createContext, useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import React, { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { createForm } from 'final-form';
|
|
4
4
|
import createDecorator from 'final-form-focus';
|
|
5
5
|
import set from 'lodash/set';
|
|
@@ -9,8 +9,13 @@ import set from 'lodash/set';
|
|
|
9
9
|
*
|
|
10
10
|
* A form context creates a context for the field values and allows them to be accessed by the children.
|
|
11
11
|
*/
|
|
12
|
-
export var FormContext = /*#__PURE__*/createContext(
|
|
13
|
-
|
|
12
|
+
export var FormContext = /*#__PURE__*/createContext({
|
|
13
|
+
registerField: function registerField() {
|
|
14
|
+
return function () {};
|
|
15
|
+
},
|
|
16
|
+
getCurrentValue: function getCurrentValue() {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
14
19
|
});
|
|
15
20
|
/**
|
|
16
21
|
* __Is disabled context__
|
|
@@ -120,8 +125,23 @@ export default function Form(props) {
|
|
|
120
125
|
children = props.children;
|
|
121
126
|
var dirty = state.dirty,
|
|
122
127
|
submitting = state.submitting;
|
|
128
|
+
/**
|
|
129
|
+
* This method is needed in FormContext to use it on the field level
|
|
130
|
+
* to check the current value of the field in case of the component re-mounting.
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
var getCurrentValue = useCallback(function (name) {
|
|
134
|
+
var formState = form.getState();
|
|
135
|
+
return (formState === null || formState === void 0 ? void 0 : formState.values[name]) || undefined;
|
|
136
|
+
}, [form]);
|
|
137
|
+
var FormContextValue = useMemo(function () {
|
|
138
|
+
return {
|
|
139
|
+
registerField: registerField,
|
|
140
|
+
getCurrentValue: getCurrentValue
|
|
141
|
+
};
|
|
142
|
+
}, [registerField, getCurrentValue]);
|
|
123
143
|
return /*#__PURE__*/React.createElement(FormContext.Provider, {
|
|
124
|
-
value:
|
|
144
|
+
value: FormContextValue
|
|
125
145
|
}, /*#__PURE__*/React.createElement(IsDisabledContext.Provider, {
|
|
126
146
|
value: isDisabled
|
|
127
147
|
}, children({
|
package/dist/esm/version.json
CHANGED
package/dist/types/form.d.ts
CHANGED
|
@@ -3,12 +3,16 @@ import { FieldConfig, FieldSubscriber, FieldSubscription, FormState, Unsubscribe
|
|
|
3
3
|
import { OnSubmitHandler } from './types';
|
|
4
4
|
declare type DefaultValue<FieldValue> = (value?: FieldValue) => FieldValue;
|
|
5
5
|
declare type RegisterField = <FieldValue>(name: string, defaultValue: FieldValue | DefaultValue<FieldValue>, subscriber: FieldSubscriber<FieldValue>, subscription: FieldSubscription, config: FieldConfig<FieldValue>) => Unsubscribe;
|
|
6
|
+
declare type GetCurrentValue = <FormValues>(name: string) => FormValues[keyof FormValues] | undefined;
|
|
6
7
|
/**
|
|
7
8
|
* __Form context__
|
|
8
9
|
*
|
|
9
10
|
* A form context creates a context for the field values and allows them to be accessed by the children.
|
|
10
11
|
*/
|
|
11
|
-
export declare const FormContext: React.Context<
|
|
12
|
+
export declare const FormContext: React.Context<{
|
|
13
|
+
registerField: RegisterField;
|
|
14
|
+
getCurrentValue: GetCurrentValue;
|
|
15
|
+
}>;
|
|
12
16
|
/**
|
|
13
17
|
* __Is disabled context__
|
|
14
18
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/form",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.8.1",
|
|
4
4
|
"description": "A form allows users to input information.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@atlaskit/icon": "^21.11.0",
|
|
43
43
|
"@atlaskit/theme": "^12.2.0",
|
|
44
|
-
"@atlaskit/tokens": "^0.
|
|
44
|
+
"@atlaskit/tokens": "^0.12.0",
|
|
45
45
|
"@babel/runtime": "^7.0.0",
|
|
46
46
|
"@emotion/react": "^11.7.1",
|
|
47
47
|
"final-form": "^4.20.1",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"react": "^16.8.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@atlaskit/button": "^16.
|
|
57
|
+
"@atlaskit/button": "^16.5.0",
|
|
58
58
|
"@atlaskit/calendar": "^12.4.0",
|
|
59
59
|
"@atlaskit/checkbox": "^12.4.0",
|
|
60
60
|
"@atlaskit/datetime-picker": "^12.3.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@atlaskit/radio": "^5.4.0",
|
|
67
67
|
"@atlaskit/range": "^7.0.0",
|
|
68
68
|
"@atlaskit/section-message": "^6.3.0",
|
|
69
|
-
"@atlaskit/select": "^
|
|
69
|
+
"@atlaskit/select": "^16.0.0",
|
|
70
70
|
"@atlaskit/ssr": "*",
|
|
71
71
|
"@atlaskit/textarea": "^4.5.0",
|
|
72
72
|
"@atlaskit/textfield": "^5.3.0",
|
package/report.api.md
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
<!-- API Report Version: 2.2 -->
|
|
2
|
+
|
|
1
3
|
## API Report File for "@atlaskit/form"
|
|
2
4
|
|
|
3
|
-
> Do not edit this file.
|
|
5
|
+
> Do not edit this file. This report is auto-generated using [API Extractor](https://api-extractor.com/).
|
|
6
|
+
> [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
|
|
7
|
+
|
|
8
|
+
### Table of contents
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
Generated API Report version: 2.0
|
|
7
|
-
-->
|
|
10
|
+
- [Main Entry Types](#main-entry-types)
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
### Main Entry Types
|
|
13
|
+
|
|
14
|
+
<!--SECTION START: Main Entry Types-->
|
|
10
15
|
|
|
11
16
|
```ts
|
|
12
17
|
import { FC } from 'react';
|
|
@@ -18,7 +23,7 @@ import { default as React_2 } from 'react';
|
|
|
18
23
|
import { ReactNode } from 'react';
|
|
19
24
|
|
|
20
25
|
// @public (undocumented)
|
|
21
|
-
type Align = '
|
|
26
|
+
type Align = 'end' | 'start';
|
|
22
27
|
|
|
23
28
|
// @public
|
|
24
29
|
export const CheckboxField: FC<CheckboxProps>;
|
|
@@ -63,22 +68,23 @@ interface FieldComponentProps<FieldValue, Element extends SupportedElements> {
|
|
|
63
68
|
meta: Meta;
|
|
64
69
|
}) => ReactNode;
|
|
65
70
|
defaultValue?:
|
|
66
|
-
| FieldValue
|
|
67
|
-
|
|
|
71
|
+
| ((currentDefaultValue?: FieldValue) => FieldValue)
|
|
72
|
+
| FieldValue;
|
|
73
|
+
elementAfterLabel?: ReactNode;
|
|
68
74
|
id?: string;
|
|
69
75
|
isDisabled?: boolean;
|
|
70
76
|
isRequired?: boolean;
|
|
71
77
|
label?: ReactNode;
|
|
72
78
|
name: string;
|
|
73
79
|
transform?: (
|
|
74
|
-
event: FormEvent<Element
|
|
80
|
+
event: FieldValue | FormEvent<Element>,
|
|
75
81
|
current: FieldValue,
|
|
76
82
|
) => FieldValue;
|
|
77
83
|
validate?: (
|
|
78
84
|
value: FieldValue | undefined,
|
|
79
85
|
formState: Object,
|
|
80
86
|
fieldState: Meta,
|
|
81
|
-
) => string | void |
|
|
87
|
+
) => Promise<string | void> | string | void;
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
// @public (undocumented)
|
|
@@ -87,7 +93,7 @@ export interface FieldProps<
|
|
|
87
93
|
Element extends SupportedElements = HTMLInputElement,
|
|
88
94
|
> {
|
|
89
95
|
// (undocumented)
|
|
90
|
-
'aria-invalid': '
|
|
96
|
+
'aria-invalid': 'false' | 'true';
|
|
91
97
|
// (undocumented)
|
|
92
98
|
'aria-labelledby': string;
|
|
93
99
|
// (undocumented)
|
|
@@ -103,7 +109,7 @@ export interface FieldProps<
|
|
|
103
109
|
// (undocumented)
|
|
104
110
|
onBlur: () => void;
|
|
105
111
|
// (undocumented)
|
|
106
|
-
onChange: (value: FormEvent<Element>
|
|
112
|
+
onChange: (value: FieldValue | FormEvent<Element>) => void;
|
|
107
113
|
// (undocumented)
|
|
108
114
|
onFocus: () => void;
|
|
109
115
|
// (undocumented)
|
|
@@ -241,7 +247,7 @@ export type OnSubmitHandler<FormData> = (
|
|
|
241
247
|
values: FormData,
|
|
242
248
|
form: FormApi<FormData>,
|
|
243
249
|
callback?: (errors?: Record<string, string>) => void,
|
|
244
|
-
) =>
|
|
250
|
+
) => Object | Promise<Object | void> | void;
|
|
245
251
|
|
|
246
252
|
// @public
|
|
247
253
|
export const RangeField: FC<RangeFieldProps>;
|
|
@@ -254,7 +260,7 @@ export interface RangeFieldProps {
|
|
|
254
260
|
error?: string;
|
|
255
261
|
meta: Meta;
|
|
256
262
|
}) => React_2.ReactNode;
|
|
257
|
-
defaultValue:
|
|
263
|
+
defaultValue: ((currentDefaultValue?: number) => number) | number;
|
|
258
264
|
id?: string;
|
|
259
265
|
isDisabled?: boolean;
|
|
260
266
|
label?: ReactNode;
|
|
@@ -267,11 +273,13 @@ type RangeProps = Omit<FieldProps<number>, 'isInvalid' | 'isRequired'>;
|
|
|
267
273
|
// @public (undocumented)
|
|
268
274
|
type SupportedElements =
|
|
269
275
|
| HTMLInputElement
|
|
270
|
-
|
|
|
271
|
-
|
|
|
276
|
+
| HTMLSelectElement
|
|
277
|
+
| HTMLTextAreaElement;
|
|
272
278
|
|
|
273
279
|
// @public
|
|
274
280
|
export const ValidMessage: React_2.FC<MessageProps>;
|
|
275
281
|
|
|
276
282
|
// (No @packageDocumentation comment for this package)
|
|
277
283
|
```
|
|
284
|
+
|
|
285
|
+
<!--SECTION END: Main Entry Types-->
|