@pingux/astro 1.9.0-alpha.1 → 1.9.0-alpha.2
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/lib/cjs/components/ComboBoxField/ComboBoxField.stories.js +16 -1
- package/lib/cjs/components/ComboBoxField/ComboBoxField.test.js +71 -12
- package/lib/cjs/components/PasswordField/PasswordField.js +4 -1
- package/lib/cjs/components/SearchField/SearchField.js +4 -1
- package/lib/cjs/components/SearchField/SearchField.stories.js +1 -1
- package/lib/cjs/components/TextAreaField/TextAreaField.js +4 -1
- package/lib/cjs/components/TextField/TextField.js +4 -1
- package/lib/cjs/hooks/useField/useField.js +1 -1
- package/lib/cjs/hooks/useField/useField.test.js +27 -10
- package/lib/components/ComboBoxField/ComboBoxField.stories.js +12 -0
- package/lib/components/ComboBoxField/ComboBoxField.test.js +56 -9
- package/lib/components/PasswordField/PasswordField.js +4 -1
- package/lib/components/SearchField/SearchField.js +4 -1
- package/lib/components/SearchField/SearchField.stories.js +1 -1
- package/lib/components/TextAreaField/TextAreaField.js +4 -1
- package/lib/components/TextField/TextField.js +4 -1
- package/lib/hooks/useField/useField.js +1 -1
- package/lib/hooks/useField/useField.test.js +27 -10
- package/package.json +1 -1
@@ -14,7 +14,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
14
14
|
value: true
|
15
15
|
});
|
16
16
|
|
17
|
-
exports["default"] = exports.WithoutStatusIndicator = exports.WithSections = exports.WithCustomHeight = exports.Required = exports.HelperText = exports.FocusMenuTrigger = exports.DisabledKeys = exports.Disabled = exports.Default = exports.CustomDefaultFilter = exports.ControlledWithCustomValue = exports.ControlledSelection = exports.ControlledMenu = exports.ControlledInput = exports.ControlledFiltering = exports.AsyncLoading = exports.AllowCustomValue = void 0;
|
17
|
+
exports["default"] = exports.WithoutStatusIndicator = exports.WithSections = exports.WithCustomInputValue = exports.WithCustomHeight = exports.Required = exports.HelperText = exports.FocusMenuTrigger = exports.DisabledKeys = exports.Disabled = exports.Default = exports.CustomDefaultFilter = exports.ControlledWithCustomValue = exports.ControlledSelection = exports.ControlledMenu = exports.ControlledInput = exports.ControlledFiltering = exports.AsyncLoading = exports.AllowCustomValue = void 0;
|
18
18
|
|
19
19
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
20
20
|
|
@@ -415,6 +415,21 @@ var ControlledWithCustomValue = function ControlledWithCustomValue() {
|
|
415
415
|
|
416
416
|
exports.ControlledWithCustomValue = ControlledWithCustomValue;
|
417
417
|
|
418
|
+
var WithCustomInputValue = function WithCustomInputValue() {
|
419
|
+
return (0, _react2.jsx)(_index.OverlayProvider, null, (0, _react2.jsx)(_ComboBoxField["default"], {
|
420
|
+
label: "Example label",
|
421
|
+
defaultItems: items,
|
422
|
+
hasCustomValue: true
|
423
|
+
}, function (item) {
|
424
|
+
return (0, _react2.jsx)(_index.Item, {
|
425
|
+
key: item.id,
|
426
|
+
textValue: item.id
|
427
|
+
}, item.name);
|
428
|
+
}));
|
429
|
+
};
|
430
|
+
|
431
|
+
exports.WithCustomInputValue = WithCustomInputValue;
|
432
|
+
|
418
433
|
var AllowCustomValue = function AllowCustomValue() {
|
419
434
|
return (0, _react2.jsx)(_index.OverlayProvider, null, (0, _react2.jsx)(_ComboBoxField["default"], (0, _extends2["default"])({
|
420
435
|
label: "Example label",
|
@@ -2,13 +2,29 @@
|
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
4
|
|
5
|
-
var
|
5
|
+
var _typeof = require("@babel/runtime-corejs3/helpers/typeof");
|
6
|
+
|
7
|
+
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
|
6
8
|
|
7
9
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
8
10
|
|
9
|
-
var
|
11
|
+
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
10
12
|
|
11
|
-
var
|
13
|
+
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
14
|
+
|
15
|
+
var _forEachInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
16
|
+
|
17
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
18
|
+
|
19
|
+
var _filterInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
20
|
+
|
21
|
+
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
22
|
+
|
23
|
+
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
24
|
+
|
25
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
26
|
+
|
27
|
+
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
12
28
|
|
13
29
|
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
|
14
30
|
|
@@ -44,6 +60,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "functi
|
|
44
60
|
|
45
61
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
46
62
|
|
63
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty2(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
64
|
+
|
65
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context5, _context6; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty2(_context5 = ownKeys(Object(source), !0)).call(_context5, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty2(_context6 = ownKeys(Object(source))).call(_context6, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
66
|
+
|
47
67
|
var items = [{
|
48
68
|
name: 'Aardvark',
|
49
69
|
id: '1'
|
@@ -67,10 +87,10 @@ var getComponent = function getComponent() {
|
|
67
87
|
renderFn = _ref$renderFn === void 0 ? _testWrapper.render : _ref$renderFn;
|
68
88
|
|
69
89
|
return renderFn((0, _react2.jsx)(_index.OverlayProvider, null, (0, _react2.jsx)(_index.ComboBoxField, (0, _extends2["default"])({}, defaultProps, props), function (item) {
|
70
|
-
return (0, _react2.jsx)(_index.Item, {
|
90
|
+
return (0, _react2.jsx)(_index.Item, (0, _extends2["default"])({}, item, {
|
71
91
|
key: item.id,
|
72
92
|
"data-id": item.name
|
73
|
-
}, item.name);
|
93
|
+
}), item.name);
|
74
94
|
})));
|
75
95
|
};
|
76
96
|
|
@@ -504,6 +524,45 @@ test('should be able to use custom default filtering', /*#__PURE__*/(0, _asyncTo
|
|
504
524
|
}
|
505
525
|
}, _callee2);
|
506
526
|
})));
|
527
|
+
test('should show in input "textValue" if provided', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
|
528
|
+
var newItems, input, options;
|
529
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
530
|
+
while (1) {
|
531
|
+
switch (_context3.prev = _context3.next) {
|
532
|
+
case 0:
|
533
|
+
newItems = (0, _map["default"])(items).call(items, function (item) {
|
534
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
535
|
+
textValue: item.id
|
536
|
+
});
|
537
|
+
});
|
538
|
+
getComponent({
|
539
|
+
items: newItems
|
540
|
+
});
|
541
|
+
input = _testWrapper.screen.queryByRole('combobox');
|
542
|
+
|
543
|
+
_userEvent["default"].click(input);
|
544
|
+
|
545
|
+
_context3.next = 6;
|
546
|
+
return _testWrapper.screen.findAllByRole('option');
|
547
|
+
|
548
|
+
case 6:
|
549
|
+
options = _context3.sent;
|
550
|
+
|
551
|
+
_userEvent["default"].click(options[0]);
|
552
|
+
|
553
|
+
expect(input).toHaveValue(newItems[0].textValue); // Check that on clicking again "textValue" still returning
|
554
|
+
|
555
|
+
_userEvent["default"].click(options[0]);
|
556
|
+
|
557
|
+
expect(input).toHaveValue(newItems[0].textValue);
|
558
|
+
|
559
|
+
case 11:
|
560
|
+
case "end":
|
561
|
+
return _context3.stop();
|
562
|
+
}
|
563
|
+
}
|
564
|
+
}, _callee3);
|
565
|
+
})));
|
507
566
|
describe('loadingState', function () {
|
508
567
|
it('combobox should not render a loader if menu is not open', function () {
|
509
568
|
var _getComponent = getComponent({
|
@@ -870,26 +929,26 @@ test('onSelectionChange works properly with custom value', function () {
|
|
870
929
|
|
871
930
|
expect(onSelectionChange).toHaveBeenCalledWith('');
|
872
931
|
});
|
873
|
-
test('should have no accessibility violations', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
932
|
+
test('should have no accessibility violations', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
874
933
|
var _getComponent6, container, results;
|
875
934
|
|
876
|
-
return _regenerator["default"].wrap(function
|
935
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
877
936
|
while (1) {
|
878
|
-
switch (
|
937
|
+
switch (_context4.prev = _context4.next) {
|
879
938
|
case 0:
|
880
939
|
jest.useRealTimers();
|
881
940
|
_getComponent6 = getComponent(), container = _getComponent6.container;
|
882
|
-
|
941
|
+
_context4.next = 4;
|
883
942
|
return (0, _jestAxe.axe)(container);
|
884
943
|
|
885
944
|
case 4:
|
886
|
-
results =
|
945
|
+
results = _context4.sent;
|
887
946
|
expect(results).toHaveNoViolations();
|
888
947
|
|
889
948
|
case 6:
|
890
949
|
case "end":
|
891
|
-
return
|
950
|
+
return _context4.stop();
|
892
951
|
}
|
893
952
|
}
|
894
|
-
},
|
953
|
+
}, _callee4);
|
895
954
|
})));
|
@@ -262,7 +262,10 @@ PasswordField.propTypes = {
|
|
262
262
|
/** The value for the input element (controlled). */
|
263
263
|
value: _propTypes["default"].string,
|
264
264
|
|
265
|
-
/** How the input
|
265
|
+
/** How the input should handle autocompletion according to the browser. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). The `autocomplete` prop is an alias for this. */
|
266
|
+
autoComplete: _propTypes["default"].string,
|
267
|
+
|
268
|
+
/** @ignore Alias for `autoComplete` prop. Exists for backwards-compatibility. */
|
266
269
|
autocomplete: _propTypes["default"].string,
|
267
270
|
|
268
271
|
/** A list of class names to apply to the input element. */
|
@@ -127,7 +127,10 @@ var SearchField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
127
127
|
}))));
|
128
128
|
});
|
129
129
|
SearchField.propTypes = {
|
130
|
-
/**
|
130
|
+
/** How the input should handle autocompletion according to the browser. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). The `autocomplete` prop is an alias for this. */
|
131
|
+
autoComplete: _propTypes["default"].string,
|
132
|
+
|
133
|
+
/** @ignore Alias for `autoComplete` prop. Exists for backwards-compatibility. */
|
131
134
|
autocomplete: _propTypes["default"].string,
|
132
135
|
|
133
136
|
/** The default value (uncontrolled). */
|
@@ -211,7 +211,10 @@ TextAreaField.propTypes = {
|
|
211
211
|
/** The value for the textarea element (controlled). */
|
212
212
|
value: _propTypes["default"].string,
|
213
213
|
|
214
|
-
/** How the
|
214
|
+
/** How the input should handle autocompletion according to the browser. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). The `autocomplete` prop is an alias for this. */
|
215
|
+
autoComplete: _propTypes["default"].string,
|
216
|
+
|
217
|
+
/** @ignore Alias for `autoComplete` prop. Exists for backwards-compatibility. */
|
215
218
|
autocomplete: _propTypes["default"].string,
|
216
219
|
|
217
220
|
/** A list of class names to apply to the textarea element. */
|
@@ -139,7 +139,10 @@ TextField.propTypes = {
|
|
139
139
|
/** The value for the input element (controlled). */
|
140
140
|
value: _propTypes["default"].string,
|
141
141
|
|
142
|
-
/** How the input
|
142
|
+
/** How the input should handle autocompletion according to the browser. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). The `autocomplete` prop is an alias for this. */
|
143
|
+
autoComplete: _propTypes["default"].string,
|
144
|
+
|
145
|
+
/** @ignore Alias for `autoComplete` prop. Exists for backwards-compatibility. */
|
143
146
|
autocomplete: _propTypes["default"].string,
|
144
147
|
|
145
148
|
/** A list of class names to apply to the input element. */
|
@@ -213,7 +213,7 @@ var useField = function useField() {
|
|
213
213
|
});
|
214
214
|
|
215
215
|
var fieldControlProps = _objectSpread(_objectSpread(_objectSpread({
|
216
|
-
|
216
|
+
autoComplete: autocomplete || autoComplete,
|
217
217
|
autoCorrect: autoCorrect,
|
218
218
|
autoFocus: hasAutoFocus,
|
219
219
|
className: classNames,
|
@@ -35,7 +35,7 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (
|
|
35
35
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
36
36
|
|
37
37
|
var defaultProps = {
|
38
|
-
|
38
|
+
autoComplete: 'off',
|
39
39
|
className: 'test',
|
40
40
|
containerProps: {
|
41
41
|
id: 'test'
|
@@ -88,7 +88,7 @@ test('should return props objects for field components', function () {
|
|
88
88
|
})
|
89
89
|
});
|
90
90
|
expect(fieldControlProps).toEqual({
|
91
|
-
|
91
|
+
autoComplete: defaultProps.autoComplete,
|
92
92
|
autoFocus: defaultProps.hasAutoFocus,
|
93
93
|
className: (0, _concat["default"])(_context = "".concat(defaultProps.className, " is-disabled is-read-only is-")).call(_context, _statuses["default"].DEFAULT, " is-tested"),
|
94
94
|
defaultSelected: true,
|
@@ -117,16 +117,33 @@ test('should return props objects for field components', function () {
|
|
117
117
|
isRequired: true
|
118
118
|
});
|
119
119
|
});
|
120
|
+
test('should support autocomplete additionally', function () {
|
121
|
+
var newProps = _objectSpread(_objectSpread({}, defaultProps), {}, {
|
122
|
+
autocomplete: 'new-password'
|
123
|
+
});
|
124
|
+
|
125
|
+
delete newProps.autoComplete;
|
126
|
+
|
127
|
+
var _renderHook2 = (0, _reactHooks.renderHook)(function () {
|
128
|
+
return (0, _useField["default"])(newProps);
|
129
|
+
}),
|
130
|
+
result = _renderHook2.result;
|
131
|
+
|
132
|
+
var fieldControlProps = result.current.fieldControlProps;
|
133
|
+
expect(fieldControlProps).toMatchObject({
|
134
|
+
autoComplete: 'new-password'
|
135
|
+
});
|
136
|
+
});
|
120
137
|
test('should return isFloatLabelActive class for container', function () {
|
121
|
-
var
|
138
|
+
var _renderHook3 = (0, _reactHooks.renderHook)(function (initialProps) {
|
122
139
|
return (0, _useField["default"])(_objectSpread(_objectSpread({}, initialProps), {}, {
|
123
140
|
placeholder: null
|
124
141
|
}));
|
125
142
|
}, {
|
126
143
|
initialProps: defaultProps
|
127
144
|
}),
|
128
|
-
result =
|
129
|
-
rerender =
|
145
|
+
result = _renderHook3.result,
|
146
|
+
rerender = _renderHook3.rerender; // Does not have the class if the label mode is not set to float
|
130
147
|
|
131
148
|
|
132
149
|
expect(result.current.fieldContainerProps.className).not.toContain('is-float-label-active'); // Has the class if the value is valid and label mode is float
|
@@ -168,13 +185,13 @@ test('should return isFloatLabelActive class for container', function () {
|
|
168
185
|
expect(result.current.fieldContainerProps.className).toContain('is-float-label-active');
|
169
186
|
});
|
170
187
|
test('should return isLeftLabel class for container', function () {
|
171
|
-
var
|
188
|
+
var _renderHook4 = (0, _reactHooks.renderHook)(function (initialProps) {
|
172
189
|
return (0, _useField["default"])(initialProps);
|
173
190
|
}, {
|
174
191
|
initialProps: defaultProps
|
175
192
|
}),
|
176
|
-
result =
|
177
|
-
rerender =
|
193
|
+
result = _renderHook4.result,
|
194
|
+
rerender = _renderHook4.rerender; // Does not have the class if the label mode is not set to left
|
178
195
|
|
179
196
|
|
180
197
|
expect(result.current.fieldContainerProps.className).not.toContain('is-left-label'); // Has the class if the value is valid and label mode is left
|
@@ -188,7 +205,7 @@ test('should return hasValue class for container when onChange updates internal
|
|
188
205
|
var onChange = jest.fn();
|
189
206
|
var numCalls = 0;
|
190
207
|
|
191
|
-
var
|
208
|
+
var _renderHook5 = (0, _reactHooks.renderHook)(function () {
|
192
209
|
return (0, _useField["default"])(_objectSpread(_objectSpread({}, defaultProps), {}, {
|
193
210
|
defaultValue: null,
|
194
211
|
placeholder: null,
|
@@ -196,7 +213,7 @@ test('should return hasValue class for container when onChange updates internal
|
|
196
213
|
value: ''
|
197
214
|
}));
|
198
215
|
}),
|
199
|
-
result =
|
216
|
+
result = _renderHook5.result; // Empty string is not a valid value
|
200
217
|
|
201
218
|
|
202
219
|
expect(result.current.fieldContainerProps.className).not.toContain('has-value'); // 0 should be a valid value
|
@@ -351,6 +351,18 @@ export var ControlledWithCustomValue = function ControlledWithCustomValue() {
|
|
351
351
|
}, item.name);
|
352
352
|
}));
|
353
353
|
};
|
354
|
+
export var WithCustomInputValue = function WithCustomInputValue() {
|
355
|
+
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(ComboBoxField, {
|
356
|
+
label: "Example label",
|
357
|
+
defaultItems: items,
|
358
|
+
hasCustomValue: true
|
359
|
+
}, function (item) {
|
360
|
+
return ___EmotionJSX(Item, {
|
361
|
+
key: item.id,
|
362
|
+
textValue: item.id
|
363
|
+
}, item.name);
|
364
|
+
}));
|
365
|
+
};
|
354
366
|
export var AllowCustomValue = function AllowCustomValue() {
|
355
367
|
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(ComboBoxField, _extends({
|
356
368
|
label: "Example label",
|
@@ -1,3 +1,11 @@
|
|
1
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
2
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
3
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
4
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
5
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
6
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
7
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
8
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
1
9
|
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
2
10
|
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
3
11
|
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
@@ -5,6 +13,11 @@ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/insta
|
|
5
13
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
6
14
|
import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/starts-with";
|
7
15
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
16
|
+
|
17
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
18
|
+
|
19
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context5, _context6; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context5 = ownKeys(Object(source), !0)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context6 = ownKeys(Object(source))).call(_context6, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
20
|
+
|
8
21
|
import React, { useState, useMemo } from 'react';
|
9
22
|
import { axe } from 'jest-axe';
|
10
23
|
import { useFilter } from '@react-aria/i18n';
|
@@ -36,10 +49,10 @@ var getComponent = function getComponent() {
|
|
36
49
|
renderFn = _ref$renderFn === void 0 ? render : _ref$renderFn;
|
37
50
|
|
38
51
|
return renderFn(___EmotionJSX(OverlayProvider, null, ___EmotionJSX(ComboBoxField, _extends({}, defaultProps, props), function (item) {
|
39
|
-
return ___EmotionJSX(Item, {
|
52
|
+
return ___EmotionJSX(Item, _extends({}, item, {
|
40
53
|
key: item.id,
|
41
54
|
"data-id": item.name
|
42
|
-
}, item.name);
|
55
|
+
}), item.name);
|
43
56
|
})));
|
44
57
|
};
|
45
58
|
|
@@ -398,6 +411,40 @@ test('should be able to use custom default filtering', /*#__PURE__*/_asyncToGene
|
|
398
411
|
}
|
399
412
|
}, _callee2);
|
400
413
|
})));
|
414
|
+
test('should show in input "textValue" if provided', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
415
|
+
var newItems, input, options;
|
416
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
417
|
+
while (1) {
|
418
|
+
switch (_context3.prev = _context3.next) {
|
419
|
+
case 0:
|
420
|
+
newItems = _mapInstanceProperty(items).call(items, function (item) {
|
421
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
422
|
+
textValue: item.id
|
423
|
+
});
|
424
|
+
});
|
425
|
+
getComponent({
|
426
|
+
items: newItems
|
427
|
+
});
|
428
|
+
input = screen.queryByRole('combobox');
|
429
|
+
userEvent.click(input);
|
430
|
+
_context3.next = 6;
|
431
|
+
return screen.findAllByRole('option');
|
432
|
+
|
433
|
+
case 6:
|
434
|
+
options = _context3.sent;
|
435
|
+
userEvent.click(options[0]);
|
436
|
+
expect(input).toHaveValue(newItems[0].textValue); // Check that on clicking again "textValue" still returning
|
437
|
+
|
438
|
+
userEvent.click(options[0]);
|
439
|
+
expect(input).toHaveValue(newItems[0].textValue);
|
440
|
+
|
441
|
+
case 11:
|
442
|
+
case "end":
|
443
|
+
return _context3.stop();
|
444
|
+
}
|
445
|
+
}
|
446
|
+
}, _callee3);
|
447
|
+
})));
|
401
448
|
describe('loadingState', function () {
|
402
449
|
it('combobox should not render a loader if menu is not open', function () {
|
403
450
|
var _getComponent = getComponent({
|
@@ -716,26 +763,26 @@ test('onSelectionChange works properly with custom value', function () {
|
|
716
763
|
userEvent.type(input, '{selectall}{backspace}{enter}');
|
717
764
|
expect(onSelectionChange).toHaveBeenCalledWith('');
|
718
765
|
});
|
719
|
-
test('should have no accessibility violations', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
766
|
+
test('should have no accessibility violations', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
720
767
|
var _getComponent6, container, results;
|
721
768
|
|
722
|
-
return _regeneratorRuntime.wrap(function
|
769
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
723
770
|
while (1) {
|
724
|
-
switch (
|
771
|
+
switch (_context4.prev = _context4.next) {
|
725
772
|
case 0:
|
726
773
|
jest.useRealTimers();
|
727
774
|
_getComponent6 = getComponent(), container = _getComponent6.container;
|
728
|
-
|
775
|
+
_context4.next = 4;
|
729
776
|
return axe(container);
|
730
777
|
|
731
778
|
case 4:
|
732
|
-
results =
|
779
|
+
results = _context4.sent;
|
733
780
|
expect(results).toHaveNoViolations();
|
734
781
|
|
735
782
|
case 6:
|
736
783
|
case "end":
|
737
|
-
return
|
784
|
+
return _context4.stop();
|
738
785
|
}
|
739
786
|
}
|
740
|
-
},
|
787
|
+
}, _callee4);
|
741
788
|
})));
|
@@ -209,7 +209,10 @@ PasswordField.propTypes = {
|
|
209
209
|
/** The value for the input element (controlled). */
|
210
210
|
value: PropTypes.string,
|
211
211
|
|
212
|
-
/** How the input
|
212
|
+
/** How the input should handle autocompletion according to the browser. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). The `autocomplete` prop is an alias for this. */
|
213
|
+
autoComplete: PropTypes.string,
|
214
|
+
|
215
|
+
/** @ignore Alias for `autoComplete` prop. Exists for backwards-compatibility. */
|
213
216
|
autocomplete: PropTypes.string,
|
214
217
|
|
215
218
|
/** A list of class names to apply to the input element. */
|
@@ -92,7 +92,10 @@ var SearchField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
92
92
|
}))));
|
93
93
|
});
|
94
94
|
SearchField.propTypes = {
|
95
|
-
/**
|
95
|
+
/** How the input should handle autocompletion according to the browser. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). The `autocomplete` prop is an alias for this. */
|
96
|
+
autoComplete: PropTypes.string,
|
97
|
+
|
98
|
+
/** @ignore Alias for `autoComplete` prop. Exists for backwards-compatibility. */
|
96
99
|
autocomplete: PropTypes.string,
|
97
100
|
|
98
101
|
/** The default value (uncontrolled). */
|
@@ -177,7 +177,10 @@ TextAreaField.propTypes = {
|
|
177
177
|
/** The value for the textarea element (controlled). */
|
178
178
|
value: PropTypes.string,
|
179
179
|
|
180
|
-
/** How the
|
180
|
+
/** How the input should handle autocompletion according to the browser. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). The `autocomplete` prop is an alias for this. */
|
181
|
+
autoComplete: PropTypes.string,
|
182
|
+
|
183
|
+
/** @ignore Alias for `autoComplete` prop. Exists for backwards-compatibility. */
|
181
184
|
autocomplete: PropTypes.string,
|
182
185
|
|
183
186
|
/** A list of class names to apply to the textarea element. */
|
@@ -102,7 +102,10 @@ TextField.propTypes = {
|
|
102
102
|
/** The value for the input element (controlled). */
|
103
103
|
value: PropTypes.string,
|
104
104
|
|
105
|
-
/** How the input
|
105
|
+
/** How the input should handle autocompletion according to the browser. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). The `autocomplete` prop is an alias for this. */
|
106
|
+
autoComplete: PropTypes.string,
|
107
|
+
|
108
|
+
/** @ignore Alias for `autoComplete` prop. Exists for backwards-compatibility. */
|
106
109
|
autocomplete: PropTypes.string,
|
107
110
|
|
108
111
|
/** A list of class names to apply to the input element. */
|
@@ -182,7 +182,7 @@ var useField = function useField() {
|
|
182
182
|
});
|
183
183
|
|
184
184
|
var fieldControlProps = _objectSpread(_objectSpread(_objectSpread({
|
185
|
-
|
185
|
+
autoComplete: autocomplete || autoComplete,
|
186
186
|
autoCorrect: autoCorrect,
|
187
187
|
autoFocus: hasAutoFocus,
|
188
188
|
className: classNames,
|
@@ -18,7 +18,7 @@ import useField from './useField';
|
|
18
18
|
import statuses from '../../utils/devUtils/constants/statuses';
|
19
19
|
import { modes as labelModes } from '../../components/Label/constants';
|
20
20
|
var defaultProps = {
|
21
|
-
|
21
|
+
autoComplete: 'off',
|
22
22
|
className: 'test',
|
23
23
|
containerProps: {
|
24
24
|
id: 'test'
|
@@ -71,7 +71,7 @@ test('should return props objects for field components', function () {
|
|
71
71
|
})
|
72
72
|
});
|
73
73
|
expect(fieldControlProps).toEqual({
|
74
|
-
|
74
|
+
autoComplete: defaultProps.autoComplete,
|
75
75
|
autoFocus: defaultProps.hasAutoFocus,
|
76
76
|
className: _concatInstanceProperty(_context = "".concat(defaultProps.className, " is-disabled is-read-only is-")).call(_context, statuses.DEFAULT, " is-tested"),
|
77
77
|
defaultSelected: true,
|
@@ -100,16 +100,33 @@ test('should return props objects for field components', function () {
|
|
100
100
|
isRequired: true
|
101
101
|
});
|
102
102
|
});
|
103
|
+
test('should support autocomplete additionally', function () {
|
104
|
+
var newProps = _objectSpread(_objectSpread({}, defaultProps), {}, {
|
105
|
+
autocomplete: 'new-password'
|
106
|
+
});
|
107
|
+
|
108
|
+
delete newProps.autoComplete;
|
109
|
+
|
110
|
+
var _renderHook2 = renderHook(function () {
|
111
|
+
return useField(newProps);
|
112
|
+
}),
|
113
|
+
result = _renderHook2.result;
|
114
|
+
|
115
|
+
var fieldControlProps = result.current.fieldControlProps;
|
116
|
+
expect(fieldControlProps).toMatchObject({
|
117
|
+
autoComplete: 'new-password'
|
118
|
+
});
|
119
|
+
});
|
103
120
|
test('should return isFloatLabelActive class for container', function () {
|
104
|
-
var
|
121
|
+
var _renderHook3 = renderHook(function (initialProps) {
|
105
122
|
return useField(_objectSpread(_objectSpread({}, initialProps), {}, {
|
106
123
|
placeholder: null
|
107
124
|
}));
|
108
125
|
}, {
|
109
126
|
initialProps: defaultProps
|
110
127
|
}),
|
111
|
-
result =
|
112
|
-
rerender =
|
128
|
+
result = _renderHook3.result,
|
129
|
+
rerender = _renderHook3.rerender; // Does not have the class if the label mode is not set to float
|
113
130
|
|
114
131
|
|
115
132
|
expect(result.current.fieldContainerProps.className).not.toContain('is-float-label-active'); // Has the class if the value is valid and label mode is float
|
@@ -151,13 +168,13 @@ test('should return isFloatLabelActive class for container', function () {
|
|
151
168
|
expect(result.current.fieldContainerProps.className).toContain('is-float-label-active');
|
152
169
|
});
|
153
170
|
test('should return isLeftLabel class for container', function () {
|
154
|
-
var
|
171
|
+
var _renderHook4 = renderHook(function (initialProps) {
|
155
172
|
return useField(initialProps);
|
156
173
|
}, {
|
157
174
|
initialProps: defaultProps
|
158
175
|
}),
|
159
|
-
result =
|
160
|
-
rerender =
|
176
|
+
result = _renderHook4.result,
|
177
|
+
rerender = _renderHook4.rerender; // Does not have the class if the label mode is not set to left
|
161
178
|
|
162
179
|
|
163
180
|
expect(result.current.fieldContainerProps.className).not.toContain('is-left-label'); // Has the class if the value is valid and label mode is left
|
@@ -171,7 +188,7 @@ test('should return hasValue class for container when onChange updates internal
|
|
171
188
|
var onChange = jest.fn();
|
172
189
|
var numCalls = 0;
|
173
190
|
|
174
|
-
var
|
191
|
+
var _renderHook5 = renderHook(function () {
|
175
192
|
return useField(_objectSpread(_objectSpread({}, defaultProps), {}, {
|
176
193
|
defaultValue: null,
|
177
194
|
placeholder: null,
|
@@ -179,7 +196,7 @@ test('should return hasValue class for container when onChange updates internal
|
|
179
196
|
value: ''
|
180
197
|
}));
|
181
198
|
}),
|
182
|
-
result =
|
199
|
+
result = _renderHook5.result; // Empty string is not a valid value
|
183
200
|
|
184
201
|
|
185
202
|
expect(result.current.fieldContainerProps.className).not.toContain('has-value'); // 0 should be a valid value
|