@atlaskit/form 10.5.2 → 10.5.3

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
+ ## 10.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`34d8c0a75098e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/34d8c0a75098e) -
8
+ [ux] accessibility improvements to the error validation
9
+
3
10
  ## 10.5.2
4
11
 
5
12
  ### Patch Changes
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "HelperMessage", {
15
15
  return _messages.HelperMessage;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "MessageWrapper", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _messages.MessageWrapper;
22
+ }
23
+ });
18
24
  Object.defineProperty(exports, "ValidMessage", {
19
25
  enumerable: true,
20
26
  get: function get() {
package/dist/cjs/index.js CHANGED
@@ -64,6 +64,12 @@ Object.defineProperty(exports, "Legend", {
64
64
  return _label.Legend;
65
65
  }
66
66
  });
67
+ Object.defineProperty(exports, "MessageWrapper", {
68
+ enumerable: true,
69
+ get: function get() {
70
+ return _messages.MessageWrapper;
71
+ }
72
+ });
67
73
  Object.defineProperty(exports, "RangeField", {
68
74
  enumerable: true,
69
75
  get: function get() {
@@ -4,8 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.ValidMessage = exports.HelperMessage = exports.ErrorMessage = void 0;
8
- var _react = require("@emotion/react");
7
+ exports.ValidMessage = exports.MessageWrapperContext = exports.MessageWrapper = exports.HelperMessage = exports.ErrorMessage = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _react2 = require("@emotion/react");
9
11
  var _success = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/success"));
10
12
  var _error = _interopRequireDefault(require("@atlaskit/icon/glyph/error"));
11
13
  var _colors = require("@atlaskit/theme/colors");
@@ -25,7 +27,7 @@ var _fieldIdContext = require("./field-id-context");
25
27
  * Public API of the various message components.
26
28
  */
27
29
 
28
- var messageStyles = (0, _react.css)({
30
+ var messageStyles = (0, _react2.css)({
29
31
  display: 'flex',
30
32
  justifyContent: 'baseline',
31
33
  gap: "var(--ds-space-050, 4px)",
@@ -33,31 +35,31 @@ var messageStyles = (0, _react.css)({
33
35
  marginBlockStart: "var(--ds-space-050, 4px)"
34
36
  });
35
37
  var messageAppearanceStyles = {
36
- default: (0, _react.css)({
38
+ default: (0, _react2.css)({
37
39
  color: "var(--ds-text-subtlest, ".concat(_colors.N200, ")")
38
40
  }),
39
- error: (0, _react.css)({
41
+ error: (0, _react2.css)({
40
42
  color: "var(--ds-text-danger, #AE2A19)"
41
43
  }),
42
- valid: (0, _react.css)({
44
+ valid: (0, _react2.css)({
43
45
  color: "var(--ds-text-success, #216E4E)"
44
46
  })
45
47
  };
46
- var iconWrapperStyles = (0, _react.css)({
48
+ var iconWrapperStyles = (0, _react2.css)({
47
49
  display: 'flex'
48
50
  });
49
51
  var IconWrapper = function IconWrapper(_ref) {
50
52
  var children = _ref.children;
51
- return (0, _react.jsx)("span", {
53
+ return (0, _react2.jsx)("span", {
52
54
  css: iconWrapperStyles
53
55
  }, children);
54
56
  };
55
57
  var messageIcons = {
56
- error: (0, _react.jsx)(_error.default, {
58
+ error: (0, _react2.jsx)(_error.default, {
57
59
  size: "small",
58
60
  label: "error"
59
61
  }),
60
- valid: (0, _react.jsx)(_success.default, {
62
+ valid: (0, _react2.jsx)(_success.default, {
61
63
  size: "small",
62
64
  label: "success"
63
65
  })
@@ -69,6 +71,18 @@ var Message = function Message(_ref2) {
69
71
  fieldId = _ref2.fieldId,
70
72
  testId = _ref2.testId;
71
73
  var icon = messageIcons[appearance];
74
+ var messageRef = (0, _react.useRef)(null);
75
+ var _useState = (0, _react.useState)(false),
76
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
77
+ hasMessageWrapper = _useState2[0],
78
+ setHasMessageWrapper = _useState2[1];
79
+ var _useContext = (0, _react.useContext)(MessageWrapperContext),
80
+ isWrapper = _useContext.isWrapper;
81
+ (0, _react.useEffect)(function () {
82
+ if (messageRef.current) {
83
+ setHasMessageWrapper(isWrapper);
84
+ }
85
+ }, [isWrapper]);
72
86
 
73
87
  /**
74
88
  * The wrapping span is necessary to preserve spaces between children.
@@ -78,13 +92,16 @@ var Message = function Message(_ref2) {
78
92
  * If the child is just a string, this is not required and we can use one
79
93
  * less DOM element.
80
94
  */
81
- var content = typeof children === 'string' ? children : (0, _react.jsx)("span", null, children);
82
- return (0, _react.jsx)("div", {
95
+ var content = typeof children === 'string' ? children : (0, _react2.jsx)("span", null, children);
96
+ return (0, _react2.jsx)("div", {
83
97
  css: [messageStyles, messageAppearanceStyles[appearance]],
84
98
  "data-testid": testId,
85
99
  id: fieldId,
86
- "aria-live": "polite"
87
- }, icon && (0, _react.jsx)(IconWrapper, null, icon), content);
100
+ ref: messageRef
101
+ // For backwards compatability, if there is a wrapper, aria-live is not needed
102
+ ,
103
+ "aria-live": !hasMessageWrapper ? 'polite' : undefined
104
+ }, icon && (0, _react2.jsx)(IconWrapper, null, icon), content);
88
105
  };
89
106
 
90
107
  /**
@@ -97,8 +114,8 @@ var Message = function Message(_ref2) {
97
114
  var HelperMessage = exports.HelperMessage = function HelperMessage(_ref3) {
98
115
  var children = _ref3.children,
99
116
  testId = _ref3.testId;
100
- return (0, _react.jsx)(_fieldIdContext.FieldId.Consumer, null, function (fieldId) {
101
- return (0, _react.jsx)(Message, {
117
+ return (0, _react2.jsx)(_fieldIdContext.FieldId.Consumer, null, function (fieldId) {
118
+ return (0, _react2.jsx)(Message, {
102
119
  fieldId: fieldId ? "".concat(fieldId, "-helper") : undefined,
103
120
  testId: testId
104
121
  }, children);
@@ -115,8 +132,8 @@ var HelperMessage = exports.HelperMessage = function HelperMessage(_ref3) {
115
132
  var ErrorMessage = exports.ErrorMessage = function ErrorMessage(_ref4) {
116
133
  var children = _ref4.children,
117
134
  testId = _ref4.testId;
118
- return (0, _react.jsx)(_fieldIdContext.FieldId.Consumer, null, function (fieldId) {
119
- return (0, _react.jsx)(Message, {
135
+ return (0, _react2.jsx)(_fieldIdContext.FieldId.Consumer, null, function (fieldId) {
136
+ return (0, _react2.jsx)(Message, {
120
137
  appearance: "error",
121
138
  fieldId: fieldId ? "".concat(fieldId, "-error") : undefined,
122
139
  testId: testId
@@ -134,11 +151,43 @@ var ErrorMessage = exports.ErrorMessage = function ErrorMessage(_ref4) {
134
151
  var ValidMessage = exports.ValidMessage = function ValidMessage(_ref5) {
135
152
  var children = _ref5.children,
136
153
  testId = _ref5.testId;
137
- return (0, _react.jsx)(_fieldIdContext.FieldId.Consumer, null, function (fieldId) {
138
- return (0, _react.jsx)(Message, {
154
+ return (0, _react2.jsx)(_fieldIdContext.FieldId.Consumer, null, function (fieldId) {
155
+ return (0, _react2.jsx)(Message, {
139
156
  appearance: "valid",
140
157
  fieldId: fieldId ? "".concat(fieldId, "-valid") : undefined,
141
158
  testId: testId
142
159
  }, children);
143
160
  });
161
+ };
162
+
163
+ /**
164
+ * __Message wrapper context__
165
+ *
166
+ * A message wrapper context allows the children to check
167
+ * if it is contained within the MessageWrapper.
168
+ */
169
+ var MessageWrapperContext = exports.MessageWrapperContext = /*#__PURE__*/(0, _react.createContext)({
170
+ isWrapper: false
171
+ });
172
+
173
+ /**
174
+ * __Message wrapper __
175
+ *
176
+ * A message wrapper is used to allow assistive technologies, like screen readers, to announce error or
177
+ * valid messages. This must be loaded into the DOM before the
178
+ * ErrorMessage, ValidMessage is loaded. Otherwise, assistive technologies
179
+ * may not render the message.
180
+ *
181
+ */
182
+ var MessageWrapper = exports.MessageWrapper = function MessageWrapper(_ref6) {
183
+ var children = _ref6.children;
184
+ var contextValue = {
185
+ isWrapper: true
186
+ };
187
+ return (0, _react2.jsx)(MessageWrapperContext.Provider, {
188
+ value: contextValue
189
+ }, (0, _react2.jsx)("div", {
190
+ "aria-live": "polite",
191
+ "data-testid": "message-wrapper"
192
+ }, children));
144
193
  };
@@ -1 +1 @@
1
- export { HelperMessage, ErrorMessage, ValidMessage } from '../messages';
1
+ export { HelperMessage, ErrorMessage, MessageWrapper, ValidMessage } from '../messages';
@@ -6,7 +6,7 @@ export { default as Field } from './field';
6
6
  export { default as CheckboxField } from './checkbox-field';
7
7
  export { default as RangeField } from './range-field';
8
8
  export { Label, Legend } from './label';
9
- export { HelperMessage, ErrorMessage, ValidMessage } from './messages';
9
+ export { HelperMessage, ErrorMessage, MessageWrapper, ValidMessage } from './messages';
10
10
  export { default as Fieldset } from './fieldset';
11
11
  export { default as RequiredAsterisk } from './required-asterisk';
12
12
  // eslint-disable-next-line import/no-unresolved
@@ -3,6 +3,8 @@
3
3
  * @jsx jsx
4
4
  */
5
5
 
6
+ import { createContext, useContext, useEffect, useRef, useState } from 'react';
7
+
6
8
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
7
9
  import { css, jsx } from '@emotion/react';
8
10
  import SuccessIcon from '@atlaskit/icon/glyph/editor/success';
@@ -63,6 +65,16 @@ const Message = ({
63
65
  testId
64
66
  }) => {
65
67
  const icon = messageIcons[appearance];
68
+ const messageRef = useRef(null);
69
+ const [hasMessageWrapper, setHasMessageWrapper] = useState(false);
70
+ const {
71
+ isWrapper
72
+ } = useContext(MessageWrapperContext);
73
+ useEffect(() => {
74
+ if (messageRef.current) {
75
+ setHasMessageWrapper(isWrapper);
76
+ }
77
+ }, [isWrapper]);
66
78
 
67
79
  /**
68
80
  * The wrapping span is necessary to preserve spaces between children.
@@ -77,7 +89,10 @@ const Message = ({
77
89
  css: [messageStyles, messageAppearanceStyles[appearance]],
78
90
  "data-testid": testId,
79
91
  id: fieldId,
80
- "aria-live": "polite"
92
+ ref: messageRef
93
+ // For backwards compatability, if there is a wrapper, aria-live is not needed
94
+ ,
95
+ "aria-live": !hasMessageWrapper ? 'polite' : undefined
81
96
  }, icon && jsx(IconWrapper, null, icon), content);
82
97
  };
83
98
 
@@ -126,4 +141,37 @@ export const ValidMessage = ({
126
141
  appearance: "valid",
127
142
  fieldId: fieldId ? `${fieldId}-valid` : undefined,
128
143
  testId: testId
129
- }, children));
144
+ }, children));
145
+
146
+ /**
147
+ * __Message wrapper context__
148
+ *
149
+ * A message wrapper context allows the children to check
150
+ * if it is contained within the MessageWrapper.
151
+ */
152
+ export const MessageWrapperContext = /*#__PURE__*/createContext({
153
+ isWrapper: false
154
+ });
155
+
156
+ /**
157
+ * __Message wrapper __
158
+ *
159
+ * A message wrapper is used to allow assistive technologies, like screen readers, to announce error or
160
+ * valid messages. This must be loaded into the DOM before the
161
+ * ErrorMessage, ValidMessage is loaded. Otherwise, assistive technologies
162
+ * may not render the message.
163
+ *
164
+ */
165
+ export const MessageWrapper = ({
166
+ children
167
+ }) => {
168
+ const contextValue = {
169
+ isWrapper: true
170
+ };
171
+ return jsx(MessageWrapperContext.Provider, {
172
+ value: contextValue
173
+ }, jsx("div", {
174
+ "aria-live": "polite",
175
+ "data-testid": "message-wrapper"
176
+ }, children));
177
+ };
@@ -1 +1 @@
1
- export { HelperMessage, ErrorMessage, ValidMessage } from '../messages';
1
+ export { HelperMessage, ErrorMessage, MessageWrapper, ValidMessage } from '../messages';
package/dist/esm/index.js CHANGED
@@ -6,7 +6,7 @@ export { default as Field } from './field';
6
6
  export { default as CheckboxField } from './checkbox-field';
7
7
  export { default as RangeField } from './range-field';
8
8
  export { Label, Legend } from './label';
9
- export { HelperMessage, ErrorMessage, ValidMessage } from './messages';
9
+ export { HelperMessage, ErrorMessage, MessageWrapper, ValidMessage } from './messages';
10
10
  export { default as Fieldset } from './fieldset';
11
11
  export { default as RequiredAsterisk } from './required-asterisk';
12
12
  // eslint-disable-next-line import/no-unresolved
@@ -1,8 +1,11 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
1
2
  /**
2
3
  * @jsxRuntime classic
3
4
  * @jsx jsx
4
5
  */
5
6
 
7
+ import { createContext, useContext, useEffect, useRef, useState } from 'react';
8
+
6
9
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
7
10
  import { css, jsx } from '@emotion/react';
8
11
  import SuccessIcon from '@atlaskit/icon/glyph/editor/success';
@@ -62,6 +65,18 @@ var Message = function Message(_ref2) {
62
65
  fieldId = _ref2.fieldId,
63
66
  testId = _ref2.testId;
64
67
  var icon = messageIcons[appearance];
68
+ var messageRef = useRef(null);
69
+ var _useState = useState(false),
70
+ _useState2 = _slicedToArray(_useState, 2),
71
+ hasMessageWrapper = _useState2[0],
72
+ setHasMessageWrapper = _useState2[1];
73
+ var _useContext = useContext(MessageWrapperContext),
74
+ isWrapper = _useContext.isWrapper;
75
+ useEffect(function () {
76
+ if (messageRef.current) {
77
+ setHasMessageWrapper(isWrapper);
78
+ }
79
+ }, [isWrapper]);
65
80
 
66
81
  /**
67
82
  * The wrapping span is necessary to preserve spaces between children.
@@ -76,7 +91,10 @@ var Message = function Message(_ref2) {
76
91
  css: [messageStyles, messageAppearanceStyles[appearance]],
77
92
  "data-testid": testId,
78
93
  id: fieldId,
79
- "aria-live": "polite"
94
+ ref: messageRef
95
+ // For backwards compatability, if there is a wrapper, aria-live is not needed
96
+ ,
97
+ "aria-live": !hasMessageWrapper ? 'polite' : undefined
80
98
  }, icon && jsx(IconWrapper, null, icon), content);
81
99
  };
82
100
 
@@ -134,4 +152,36 @@ export var ValidMessage = function ValidMessage(_ref5) {
134
152
  testId: testId
135
153
  }, children);
136
154
  });
155
+ };
156
+
157
+ /**
158
+ * __Message wrapper context__
159
+ *
160
+ * A message wrapper context allows the children to check
161
+ * if it is contained within the MessageWrapper.
162
+ */
163
+ export var MessageWrapperContext = /*#__PURE__*/createContext({
164
+ isWrapper: false
165
+ });
166
+
167
+ /**
168
+ * __Message wrapper __
169
+ *
170
+ * A message wrapper is used to allow assistive technologies, like screen readers, to announce error or
171
+ * valid messages. This must be loaded into the DOM before the
172
+ * ErrorMessage, ValidMessage is loaded. Otherwise, assistive technologies
173
+ * may not render the message.
174
+ *
175
+ */
176
+ export var MessageWrapper = function MessageWrapper(_ref6) {
177
+ var children = _ref6.children;
178
+ var contextValue = {
179
+ isWrapper: true
180
+ };
181
+ return jsx(MessageWrapperContext.Provider, {
182
+ value: contextValue
183
+ }, jsx("div", {
184
+ "aria-live": "polite",
185
+ "data-testid": "message-wrapper"
186
+ }, children));
137
187
  };
@@ -1 +1 @@
1
- export { HelperMessage, ErrorMessage, ValidMessage } from '../messages';
1
+ export { HelperMessage, ErrorMessage, MessageWrapper, ValidMessage } from '../messages';
@@ -11,7 +11,7 @@ export { default as RangeField } from './range-field';
11
11
  export type { RangeFieldProps } from './range-field';
12
12
  export { Label, Legend } from './label';
13
13
  export type { LabelProps, LegendProps } from './label';
14
- export { HelperMessage, ErrorMessage, ValidMessage } from './messages';
14
+ export { HelperMessage, ErrorMessage, MessageWrapper, ValidMessage } from './messages';
15
15
  export { default as Fieldset } from './fieldset';
16
16
  export { default as RequiredAsterisk } from './required-asterisk';
17
17
  export type { OnSubmitHandler, FormApi } from './types';
@@ -53,4 +53,23 @@ export declare const ErrorMessage: ({ children, testId }: MessageProps) => jsx.J
53
53
  *
54
54
  */
55
55
  export declare const ValidMessage: ({ children, testId }: MessageProps) => jsx.JSX.Element;
56
+ /**
57
+ * __Message wrapper context__
58
+ *
59
+ * A message wrapper context allows the children to check
60
+ * if it is contained within the MessageWrapper.
61
+ */
62
+ export declare const MessageWrapperContext: import("react").Context<{
63
+ isWrapper: boolean;
64
+ }>;
65
+ /**
66
+ * __Message wrapper __
67
+ *
68
+ * A message wrapper is used to allow assistive technologies, like screen readers, to announce error or
69
+ * valid messages. This must be loaded into the DOM before the
70
+ * ErrorMessage, ValidMessage is loaded. Otherwise, assistive technologies
71
+ * may not render the message.
72
+ *
73
+ */
74
+ export declare const MessageWrapper: ({ children }: MessageProps) => jsx.JSX.Element;
56
75
  export {};
@@ -1 +1 @@
1
- export { HelperMessage, ErrorMessage, ValidMessage } from '../messages';
1
+ export { HelperMessage, ErrorMessage, MessageWrapper, ValidMessage } from '../messages';
@@ -11,7 +11,7 @@ export { default as RangeField } from './range-field';
11
11
  export type { RangeFieldProps } from './range-field';
12
12
  export { Label, Legend } from './label';
13
13
  export type { LabelProps, LegendProps } from './label';
14
- export { HelperMessage, ErrorMessage, ValidMessage } from './messages';
14
+ export { HelperMessage, ErrorMessage, MessageWrapper, ValidMessage } from './messages';
15
15
  export { default as Fieldset } from './fieldset';
16
16
  export { default as RequiredAsterisk } from './required-asterisk';
17
17
  export type { OnSubmitHandler, FormApi } from './types';
@@ -53,4 +53,23 @@ export declare const ErrorMessage: ({ children, testId }: MessageProps) => jsx.J
53
53
  *
54
54
  */
55
55
  export declare const ValidMessage: ({ children, testId }: MessageProps) => jsx.JSX.Element;
56
+ /**
57
+ * __Message wrapper context__
58
+ *
59
+ * A message wrapper context allows the children to check
60
+ * if it is contained within the MessageWrapper.
61
+ */
62
+ export declare const MessageWrapperContext: import("react").Context<{
63
+ isWrapper: boolean;
64
+ }>;
65
+ /**
66
+ * __Message wrapper __
67
+ *
68
+ * A message wrapper is used to allow assistive technologies, like screen readers, to announce error or
69
+ * valid messages. This must be loaded into the DOM before the
70
+ * ErrorMessage, ValidMessage is loaded. Otherwise, assistive technologies
71
+ * may not render the message.
72
+ *
73
+ */
74
+ export declare const MessageWrapper: ({ children }: MessageProps) => jsx.JSX.Element;
56
75
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/form",
3
- "version": "10.5.2",
3
+ "version": "10.5.3",
4
4
  "description": "A form allows users to input information.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@atlaskit/heading": "^2.4.0",
32
- "@atlaskit/icon": "^22.12.0",
32
+ "@atlaskit/icon": "^22.13.0",
33
33
  "@atlaskit/primitives": "^12.0.0",
34
34
  "@atlaskit/theme": "^13.0.0",
35
35
  "@atlaskit/tokens": "^1.58.0",
@@ -49,7 +49,7 @@
49
49
  "@af/integration-testing": "*",
50
50
  "@af/visual-regression": "*",
51
51
  "@atlaskit/banner": "^12.5.0",
52
- "@atlaskit/button": "^19.2.0",
52
+ "@atlaskit/button": "^20.0.0",
53
53
  "@atlaskit/checkbox": "^13.7.0",
54
54
  "@atlaskit/ds-lib": "^2.4.0",
55
55
  "@atlaskit/modal-dialog": "^12.15.0",