@atlaskit/form 12.4.1 → 12.5.0

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/form
2
2
 
3
+ ## 12.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`c22bdb7c0b0f8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c22bdb7c0b0f8) -
8
+ [ux] Added support for focusing error fields containing react-select when submitting with errors
9
+
3
10
  ## 12.4.1
4
11
 
5
12
  ### Patch Changes
package/dist/cjs/form.js CHANGED
@@ -14,6 +14,7 @@ var _finalForm = require("final-form");
14
14
  var _finalFormFocus = _interopRequireDefault(require("final-form-focus"));
15
15
  var _set = _interopRequireDefault(require("lodash/set"));
16
16
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
17
+ var _utils = require("./utils");
17
18
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
18
19
  /**
19
20
  * __Form context__
@@ -69,7 +70,7 @@ function Form(props) {
69
70
  });
70
71
  (0, _finalFormFocus.default)(function () {
71
72
  return formRef.current ? Array.from(formRef.current.querySelectorAll('input')) : [];
72
- })(finalForm);
73
+ }, (0, _platformFeatureFlags.fg)('platform-form-field-error-focus') ? _utils.getFirstErrorField : undefined)(finalForm);
73
74
  return finalForm;
74
75
  }),
75
76
  _useState2 = (0, _slicedToArray2.default)(_useState, 1),
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getFirstErrorField = void 0;
7
+ var _finalForm = require("final-form");
8
+ var getFirstErrorField = exports.getFirstErrorField = function getFirstErrorField(inputs, errors) {
9
+ // Guaranteed to be of type HTMLInputElement[] due to getInputs function overrided in createDecorator
10
+ var htmlInputs = inputs;
11
+ return htmlInputs.find(function (input) {
12
+ // If input is hidden, do not focus
13
+ if (input.type === 'hidden') {
14
+ return false;
15
+ }
16
+
17
+ // If input ID matches the error, focus
18
+ if (input.id && (0, _finalForm.getIn)(errors, input.id)) {
19
+ return true;
20
+ }
21
+
22
+ // Default to base behavior
23
+ return input.name && (0, _finalForm.getIn)(errors, input.name);
24
+ });
25
+ };
@@ -4,6 +4,7 @@ import { createForm } from 'final-form';
4
4
  import createDecorator from 'final-form-focus';
5
5
  import set from 'lodash/set';
6
6
  import { fg } from '@atlaskit/platform-feature-flags';
7
+ import { getFirstErrorField } from './utils';
7
8
  /**
8
9
  * __Form context__
9
10
  *
@@ -51,7 +52,7 @@ export default function Form(props) {
51
52
  }
52
53
  }
53
54
  });
54
- createDecorator(() => formRef.current ? Array.from(formRef.current.querySelectorAll('input')) : [])(finalForm);
55
+ createDecorator(() => formRef.current ? Array.from(formRef.current.querySelectorAll('input')) : [], fg('platform-form-field-error-focus') ? getFirstErrorField : undefined)(finalForm);
55
56
  return finalForm;
56
57
  });
57
58
  const [state, setState] = useState({
@@ -0,0 +1,19 @@
1
+ import { getIn } from 'final-form';
2
+ export const getFirstErrorField = (inputs, errors) => {
3
+ // Guaranteed to be of type HTMLInputElement[] due to getInputs function overrided in createDecorator
4
+ let htmlInputs = inputs;
5
+ return htmlInputs.find(function (input) {
6
+ // If input is hidden, do not focus
7
+ if (input.type === 'hidden') {
8
+ return false;
9
+ }
10
+
11
+ // If input ID matches the error, focus
12
+ if (input.id && getIn(errors, input.id)) {
13
+ return true;
14
+ }
15
+
16
+ // Default to base behavior
17
+ return input.name && getIn(errors, input.name);
18
+ });
19
+ };
package/dist/esm/form.js CHANGED
@@ -5,6 +5,7 @@ import { createForm } from 'final-form';
5
5
  import createDecorator from 'final-form-focus';
6
6
  import set from 'lodash/set';
7
7
  import { fg } from '@atlaskit/platform-feature-flags';
8
+ import { getFirstErrorField } from './utils';
8
9
  /**
9
10
  * __Form context__
10
11
  *
@@ -59,7 +60,7 @@ export default function Form(props) {
59
60
  });
60
61
  createDecorator(function () {
61
62
  return formRef.current ? Array.from(formRef.current.querySelectorAll('input')) : [];
62
- })(finalForm);
63
+ }, fg('platform-form-field-error-focus') ? getFirstErrorField : undefined)(finalForm);
63
64
  return finalForm;
64
65
  }),
65
66
  _useState2 = _slicedToArray(_useState, 1),
@@ -0,0 +1,19 @@
1
+ import { getIn } from 'final-form';
2
+ export var getFirstErrorField = function getFirstErrorField(inputs, errors) {
3
+ // Guaranteed to be of type HTMLInputElement[] due to getInputs function overrided in createDecorator
4
+ var htmlInputs = inputs;
5
+ return htmlInputs.find(function (input) {
6
+ // If input is hidden, do not focus
7
+ if (input.type === 'hidden') {
8
+ return false;
9
+ }
10
+
11
+ // If input ID matches the error, focus
12
+ if (input.id && getIn(errors, input.id)) {
13
+ return true;
14
+ }
15
+
16
+ // Default to base behavior
17
+ return input.name && getIn(errors, input.name);
18
+ });
19
+ };
@@ -0,0 +1,2 @@
1
+ import type { FocusableInput } from 'final-form-focus';
2
+ export declare const getFirstErrorField: (inputs: FocusableInput[], errors: Object) => HTMLInputElement | undefined;
@@ -0,0 +1,2 @@
1
+ import type { FocusableInput } from 'final-form-focus';
2
+ export declare const getFirstErrorField: (inputs: FocusableInput[], errors: Object) => HTMLInputElement | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/form",
3
- "version": "12.4.1",
3
+ "version": "12.5.0",
4
4
  "description": "A form allows users to input information.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -119,6 +119,9 @@
119
119
  },
120
120
  "platform_design-system-team_checkbox-field-spread": {
121
121
  "type": "boolean"
122
+ },
123
+ "platform-form-field-error-focus": {
124
+ "type": "boolean"
122
125
  }
123
126
  }
124
127
  }