@pingux/astro 2.93.0-alpha.0 → 2.93.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.
Files changed (33) hide show
  1. package/lib/cjs/components/SelectField/Select.styles.d.ts +2 -0
  2. package/lib/cjs/components/SelectField/SelectField.d.ts +4 -0
  3. package/lib/cjs/components/SelectField/SelectField.js +18 -91
  4. package/lib/cjs/components/SelectField/SelectField.stories.d.ts +50 -0
  5. package/lib/cjs/components/SelectField/SelectField.stories.js +4 -1
  6. package/lib/cjs/components/SelectField/SelectField.test.d.ts +1 -0
  7. package/lib/cjs/components/SelectField/SelectField.test.js +20 -4
  8. package/lib/cjs/components/SelectField/index.d.ts +1 -0
  9. package/lib/cjs/components/SelectFieldBase/SelectFieldBase.d.ts +11 -0
  10. package/lib/cjs/components/SelectFieldBase/SelectFieldBase.js +26 -83
  11. package/lib/cjs/components/SelectFieldBase/SelectFieldBase.test.d.ts +1 -0
  12. package/lib/cjs/components/SelectFieldBase/SelectFieldBase.test.js +10 -4
  13. package/lib/cjs/components/SelectFieldBase/index.d.ts +1 -0
  14. package/lib/cjs/components/TextAreaField/TextAreaField.test.js +10 -9
  15. package/lib/cjs/hooks/useSelectField/useSelectField.d.ts +12 -7
  16. package/lib/cjs/types/TextAreaField.d.ts +2 -13
  17. package/lib/cjs/types/arrayField.d.ts +1 -2
  18. package/lib/cjs/types/selectField.d.ts +23 -0
  19. package/lib/cjs/types/selectField.js +6 -0
  20. package/lib/cjs/types/shared/dom.d.ts +1 -0
  21. package/lib/cjs/types/shared/fieldProps.d.ts +12 -0
  22. package/lib/cjs/types/shared/fieldProps.js +6 -0
  23. package/lib/cjs/types/textField.d.ts +2 -11
  24. package/lib/components/SelectField/Select.styles.js +1 -0
  25. package/lib/components/SelectField/SelectField.js +19 -92
  26. package/lib/components/SelectField/SelectField.stories.js +4 -1
  27. package/lib/components/SelectField/SelectField.test.js +20 -4
  28. package/lib/components/SelectFieldBase/SelectFieldBase.js +27 -84
  29. package/lib/components/SelectFieldBase/SelectFieldBase.test.js +10 -4
  30. package/lib/components/TextAreaField/TextAreaField.test.js +10 -9
  31. package/lib/types/selectField.js +1 -0
  32. package/lib/types/shared/fieldProps.js +1 -0
  33. package/package.json +1 -1
@@ -0,0 +1,2 @@
1
+ import { ThemeUICSSObject } from 'theme-ui';
2
+ export declare const select: ThemeUICSSObject;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { SelectFieldProps } from '../../types/selectField';
3
+ declare const SelectField: React.ForwardRefExoticComponent<SelectFieldProps<object> & React.RefAttributes<HTMLSelectElement>>;
4
+ export default SelectField;
@@ -19,10 +19,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/he
19
19
  var _objectDestructuringEmpty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectDestructuringEmpty"));
20
20
  var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
21
21
  var _react = _interopRequireWildcard(require("react"));
22
- var _propTypes = _interopRequireDefault(require("prop-types"));
23
22
  var _hooks = require("../../hooks");
24
- var _ariaAttributes = require("../../utils/docUtils/ariaAttributes");
25
- var _fieldAttributes = require("../../utils/docUtils/fieldAttributes");
26
23
  var _statusProp = require("../../utils/docUtils/statusProp");
27
24
  var _SelectFieldBase = _interopRequireDefault(require("../SelectFieldBase"));
28
25
  var _react2 = require("@emotion/react");
@@ -31,100 +28,30 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
31
28
  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; }
32
29
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
33
30
  var SelectField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
34
- var status = props.status;
31
+ /* istanbul ignore next */
32
+ var status = props.status,
33
+ _props$placeholder = props.placeholder,
34
+ placeholder = _props$placeholder === void 0 ? 'Select' : _props$placeholder,
35
+ _props$align = props.align,
36
+ align = _props$align === void 0 ? 'start' : _props$align,
37
+ _props$direction = props.direction,
38
+ direction = _props$direction === void 0 ? 'bottom' : _props$direction,
39
+ _props$scrollBoxProps = props.scrollBoxProps,
40
+ scrollBoxProps = _props$scrollBoxProps === void 0 ? {
41
+ margin: '300px'
42
+ } : _props$scrollBoxProps;
35
43
  (0, _hooks.usePropWarning)(props, 'disabled', 'isDisabled');
36
44
  var _useSelectField = (0, _hooks.useSelectField)(props, ref),
37
45
  selectFieldProps = (0, _extends2["default"])({}, ((0, _objectDestructuringEmpty2["default"])(_useSelectField), _useSelectField));
38
- return (0, _react2.jsx)(_SelectFieldBase["default"], (0, _extends2["default"])({}, props, selectFieldProps, {
46
+ return (0, _react2.jsx)(_SelectFieldBase["default"], (0, _extends2["default"])({
47
+ placeholder: placeholder,
48
+ align: align,
49
+ direction: direction,
50
+ scrollBoxProps: scrollBoxProps
51
+ }, props, selectFieldProps, {
39
52
  "aria-invalid": status === 'error' && true
40
53
  }));
41
54
  });
42
- SelectField.propTypes = _objectSpread(_objectSpread(_objectSpread({
43
- /** Alignment of the popover menu relative to the trigger. */
44
- align: _propTypes["default"].oneOf(['start', 'end', 'middle']),
45
- /** Where the popover menu opens relative to its trigger. */
46
- direction: _propTypes["default"].oneOf(['top', 'right', 'bottom', 'left']),
47
- /** The initial selected key in the collection (uncontrolled). */
48
- defaultSelectedKey: _propTypes["default"].string,
49
- /** Default text rendered if no option is selected. Deprecated. */
50
- defaultText: _propTypes["default"].string,
51
- /** Array of keys to disable within the options list. */
52
- disabledKeys: _propTypes["default"].arrayOf(_propTypes["default"].string),
53
- /** Whether the collection allows empty selection. */
54
- hasNoEmptySelection: _propTypes["default"].bool,
55
- /** Whether the field has a status indicator. */
56
- hasNoStatusIndicator: _propTypes["default"].bool,
57
- /** Text rendered below the input. */
58
- helperText: _propTypes["default"].node,
59
- /** If present this prop will cause a help hint to render in the label of the field. */
60
- hintText: _propTypes["default"].string,
61
- /** Sets the default open state of the menu. */
62
- isDefaultOpen: _propTypes["default"].bool,
63
- /** Whether the input is disabled. */
64
- isDisabled: _propTypes["default"].bool,
65
- /** Whether the items are currently loading. */
66
- isLoading: _propTypes["default"].bool,
67
- /** @ignore Whether the menu should automatically flip direction when space is limited. */
68
- isNotFlippable: _propTypes["default"].bool,
69
- /** Sets the open state of the menu. */
70
- isOpen: _propTypes["default"].bool,
71
- /** @ignore Whether the input can be selected but not changed by the user. */
72
- isReadOnly: _propTypes["default"].bool,
73
- /** Whether user input is required on the input before form submission. */
74
- isRequired: _propTypes["default"].bool,
75
- /**
76
- * *For performance reasons, use this prop instead of Array.map when iteratively rendering Items*.
77
- * For use with [dynamic collections](https://react-spectrum.adobe.com/react-stately/collections.html#dynamic-collections).
78
- */
79
- items: _propTypes["default"].arrayOf(_propTypes["default"].shape({})),
80
- /** The label for the select element. */
81
- label: _propTypes["default"].node,
82
- /** The name for the select element, used when submitting a form. */
83
- name: _propTypes["default"].string,
84
- /** Temporary text that occupies the text input when it is empty. */
85
- placeholder: _propTypes["default"].string,
86
- /** The currently selected key in the collection (controlled). */
87
- selectedKey: _propTypes["default"].string,
88
- /** Determines the textarea status indicator and helper text styling. Eg. float. */
89
- labelMode: _propTypes["default"].string,
90
- /**
91
- * Handler that is called when more items should be loaded, e.g. while scrolling near the bottom.
92
- *
93
- * () => any
94
- */
95
- onLoadMore: _propTypes["default"].func,
96
- /**
97
- * Method that is called when the open state of the menu changes.
98
- *
99
- * (isOpen: boolean) => void
100
- */
101
- onOpenChange: _propTypes["default"].func,
102
- /**
103
- * Handler that is called when the selection changes.
104
- *
105
- * (key: Key) => any
106
- */
107
- onSelectionChange: _propTypes["default"].func
108
- }, _fieldAttributes.inputFieldAttributesBasePropTypes), {}, {
109
- /** Provides a way to insert markup in specified places. */
110
- slots: _propTypes["default"].shape({
111
- /** The given node will be inserted before the text in field container. */
112
- leftOfData: _propTypes["default"].node,
113
- /** The given node will be inserted into the field container. */
114
- inContainer: _propTypes["default"].node
115
- }),
116
- /**
117
- * Props object passed along to `useSelect` from React Aria, `useSelectState` from React Stately,
118
- * and/or the visible button representation for the select input.
119
- */
120
- controlProps: _propTypes["default"].shape({}),
121
- /** Props object that is spread directly into the ScrollBox element. */
122
- // /** Props object that is spread directly into the ScrollBox element. */
123
- /** @ignore */
124
- scrollBoxProps: _propTypes["default"].shape({
125
- maxHeight: _propTypes["default"].string
126
- })
127
- }, _statusProp.statusPropTypes), _ariaAttributes.ariaAttributesBasePropTypes);
128
55
  SelectField.defaultProps = _objectSpread({
129
56
  placeholder: 'Select',
130
57
  align: 'start',
@@ -0,0 +1,50 @@
1
+ import React, { Key } from 'react';
2
+ export type SelectItemProps = {
3
+ name?: string;
4
+ id?: string;
5
+ key?: Key;
6
+ };
7
+ export type SelectSectionProps = {
8
+ name?: string;
9
+ key?: string;
10
+ children?: SelectItemProps[];
11
+ };
12
+ declare const _default: {
13
+ title: string;
14
+ component: React.ForwardRefExoticComponent<import("../../types/selectField").SelectFieldProps<object> & React.RefAttributes<HTMLSelectElement>>;
15
+ parameters: {
16
+ docs: {
17
+ page: () => React.JSX.Element;
18
+ source: {
19
+ type: string;
20
+ };
21
+ };
22
+ };
23
+ argTypes: any;
24
+ args: {
25
+ label: string;
26
+ labelMode: string;
27
+ };
28
+ };
29
+ export default _default;
30
+ export declare const Default: (args: any) => React.JSX.Element;
31
+ export declare const WithSections: (args: any) => React.JSX.Element;
32
+ export declare const WithCustomHeight: (args: any) => React.JSX.Element;
33
+ export declare const FloatLabel: () => React.JSX.Element;
34
+ export declare const Controlled: () => React.JSX.Element;
35
+ export declare const WithNoneOption: () => React.JSX.Element;
36
+ export declare const WithSlots: () => React.JSX.Element;
37
+ export declare const DisabledField: () => React.JSX.Element;
38
+ export declare const DisabledOptions: () => React.JSX.Element;
39
+ export declare const NoOptionsAvailable: () => React.JSX.Element;
40
+ export declare const HelperText: () => React.JSX.Element;
41
+ export declare const DynamicItems: {
42
+ (): React.JSX.Element;
43
+ parameters: {
44
+ docs: {
45
+ storyDescription: string;
46
+ };
47
+ };
48
+ };
49
+ export declare const AsyncLoading: () => React.JSX.Element;
50
+ export declare const WithoutStatusIndicator: () => React.JSX.Element;
@@ -351,7 +351,10 @@ var HelperText = function HelperText() {
351
351
  }, "Yellow"));
352
352
  };
353
353
  exports.HelperText = HelperText;
354
- var options = (0, _map["default"])(_context = (0, _fill["default"])(_context2 = new Array(200)).call(_context2)).call(_context, function (_, i) {
354
+ var options = (0, _map["default"])(_context = (0, _fill["default"])(_context2 = new Array(200)).call(_context2, {
355
+ key: 'string',
356
+ name: 'string'
357
+ })).call(_context, function (_, i) {
355
358
  return {
356
359
  key: "option-".concat(i),
357
360
  name: "Option ".concat(i)
@@ -20,7 +20,7 @@ var items = [{
20
20
  var withSection = [{
21
21
  name: 'Animals',
22
22
  key: 'Animals',
23
- kids: [{
23
+ children: [{
24
24
  name: 'Aardvark'
25
25
  }, {
26
26
  name: 'Kangaroo'
@@ -30,7 +30,7 @@ var withSection = [{
30
30
  }, {
31
31
  name: 'People',
32
32
  key: 'People',
33
- kids: [{
33
+ children: [{
34
34
  name: 'Michael'
35
35
  }, {
36
36
  name: 'Dwight'
@@ -40,7 +40,7 @@ var withSection = [{
40
40
  }, {
41
41
  name: null,
42
42
  key: 'Fruit',
43
- kids: [{
43
+ children: [{
44
44
  name: 'Apple'
45
45
  }, {
46
46
  name: 'Strawberry'
@@ -81,7 +81,7 @@ var getComponentWithSections = function getComponentWithSections() {
81
81
  }), function (section) {
82
82
  return (0, _react2.jsx)(_index.Section, {
83
83
  key: section.key,
84
- items: section.kids,
84
+ items: section.children,
85
85
  title: section.name
86
86
  }, function (item) {
87
87
  return (0, _react2.jsx)(_index.Item, {
@@ -155,4 +155,20 @@ test('a blank title does not render', function () {
155
155
  var button = _testWrapper.screen.getByRole('button');
156
156
  _userEvent["default"].click(button);
157
157
  expect(_testWrapper.screen.queryByText('Fruit')).not.toBeInTheDocument();
158
+ });
159
+ test('renders placeholder text', function () {
160
+ var placeholderText = 'Select an option';
161
+ getComponent({
162
+ placeholder: placeholderText
163
+ });
164
+ var placeholder = _testWrapper.screen.getByText(placeholderText);
165
+ expect(placeholder).toBeInTheDocument();
166
+ });
167
+ test('renders default placeholder text', function () {
168
+ var placeholderText = 'Select';
169
+ getComponent({
170
+ placeholder: placeholderText
171
+ });
172
+ var placeholder = _testWrapper.screen.getByText(placeholderText);
173
+ expect(placeholder).toBeInTheDocument();
158
174
  });
@@ -0,0 +1 @@
1
+ export { default } from './SelectField';
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { SelectFieldBaseProps } from '../../types/selectField';
3
+ /**
4
+ * Select field (dropdown) that does not rely on native browser or mobile implementations.
5
+ *
6
+ * Utilizes [useSelect](https://react-spectrum.adobe.com/react-aria/useSelect.html) from React Aria
7
+ * and [useSelectState](https://react-spectrum.adobe.com/react-stately/useSelectState.html) from
8
+ * React Stately.
9
+ */
10
+ declare const SelectFieldBase: React.ForwardRefExoticComponent<SelectFieldBaseProps & React.RefAttributes<HTMLSelectElement>>;
11
+ export default SelectFieldBase;
@@ -15,19 +15,16 @@ _Object$defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  exports["default"] = void 0;
18
- var _values = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/values"));
19
18
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
20
19
  var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
21
20
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
22
21
  var _react = _interopRequireWildcard(require("react"));
23
22
  var _reactAria = require("react-aria");
24
- var _propTypes = _interopRequireDefault(require("prop-types"));
25
23
  var _uuid = require("uuid");
26
24
  var _useGetTheme2 = _interopRequireDefault(require("../../hooks/useGetTheme"));
27
25
  var _labelModes = require("../../utils/devUtils/constants/labelModes");
28
26
  var _pendoID = require("../../utils/devUtils/constants/pendoID");
29
27
  var _ariaAttributes = require("../../utils/docUtils/ariaAttributes");
30
- var _statusProp = require("../../utils/docUtils/statusProp");
31
28
  var _Box = _interopRequireDefault(require("../Box"));
32
29
  var _Button = _interopRequireDefault(require("../Button"));
33
30
  var _FieldHelperText = _interopRequireDefault(require("../FieldHelperText"));
@@ -48,33 +45,34 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "functi
48
45
  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; }
49
46
  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; }
50
47
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
51
- var SelectFieldBase = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
52
- var columnStyleProps = _ref.columnStyleProps,
53
- defaultText = _ref.defaultText,
54
- fieldContainerProps = _ref.fieldContainerProps,
55
- fieldControlInputProps = _ref.fieldControlInputProps,
56
- fieldControlWrapperProps = _ref.fieldControlWrapperProps,
57
- fieldLabelProps = _ref.fieldLabelProps,
58
- helperText = _ref.helperText,
59
- isLoadingInitial = _ref.isLoadingInitial,
60
- label = _ref.label,
61
- labelMode = _ref.labelMode,
62
- name = _ref.name,
63
- overlay = _ref.overlay,
64
- placeholder = _ref.placeholder,
65
- slots = _ref.slots,
66
- state = _ref.state,
67
- status = _ref.status,
68
- trigger = _ref.trigger,
69
- triggerProps = _ref.triggerProps,
70
- triggerRef = _ref.triggerRef,
71
- valueProps = _ref.valueProps,
72
- others = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
48
+ var SelectFieldBase = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
49
+ var columnStyleProps = props.columnStyleProps,
50
+ defaultText = props.defaultText,
51
+ fieldContainerProps = props.fieldContainerProps,
52
+ fieldControlInputProps = props.fieldControlInputProps,
53
+ fieldControlWrapperProps = props.fieldControlWrapperProps,
54
+ fieldLabelProps = props.fieldLabelProps,
55
+ helperText = props.helperText,
56
+ isLoadingInitial = props.isLoadingInitial,
57
+ label = props.label,
58
+ labelMode = props.labelMode,
59
+ name = props.name,
60
+ overlay = props.overlay,
61
+ placeholder = props.placeholder,
62
+ slots = props.slots,
63
+ state = props.state,
64
+ status = props.status,
65
+ trigger = props.trigger,
66
+ triggerProps = props.triggerProps,
67
+ triggerRef = props.triggerRef,
68
+ valueProps = props.valueProps,
69
+ others = (0, _objectWithoutProperties2["default"])(props, _excluded);
73
70
  var _getAriaAttributeProp = (0, _ariaAttributes.getAriaAttributeProps)(others),
74
71
  ariaProps = _getAriaAttributeProp.ariaProps;
75
72
  var _useGetTheme = (0, _useGetTheme2["default"])(),
76
73
  icons = _useGetTheme.icons;
77
- var MenuDown = icons.MenuDown;
74
+ var MenuDown = icons.MenuDown,
75
+ MenuUp = icons.MenuUp;
78
76
  var helperTextId = (0, _react.useMemo)(function () {
79
77
  return (0, _uuid.v4)();
80
78
  }, []);
@@ -98,14 +96,11 @@ var SelectFieldBase = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
98
96
  "aria-hidden": "true",
99
97
  variant: "forms.select.arrow"
100
98
  }, (0, _react2.jsx)(_Icon["default"], {
101
- icon: MenuDown,
99
+ icon: state.isOpen ? MenuUp : MenuDown,
102
100
  title: {
103
101
  name: 'Menu down'
104
102
  },
105
- size: "md",
106
- sx: state.isOpen ? {
107
- transform: 'rotate(180deg)'
108
- } : null
103
+ size: "md"
109
104
  }))), slots === null || slots === void 0 ? void 0 : slots.inContainer);
110
105
  return (0, _react2.jsx)(_Box["default"], (0, _extends2["default"])({
111
106
  ref: ref,
@@ -123,57 +118,5 @@ var SelectFieldBase = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
123
118
  id: helperTextId
124
119
  }, helperText));
125
120
  });
126
- SelectFieldBase.propTypes = _objectSpread(_objectSpread({
127
- /** Default text rendered if no option is selected. Deprecated. */
128
- defaultText: _propTypes["default"].string,
129
- /** Text rendered below the input. */
130
- helperText: _propTypes["default"].node,
131
- /** The label for the select element. */
132
- label: _propTypes["default"].node,
133
- /** Determines the textarea status indicator and helper text styling. Eg. float. */
134
- labelMode: _propTypes["default"].oneOf((0, _values["default"])(_labelModes.modes)),
135
- /** The name for the select element, used when submitting a form. */
136
- name: _propTypes["default"].string,
137
- /** Temporary text that occupies the text input when it is empty. */
138
- placeholder: _propTypes["default"].string,
139
- /** Determines whether to use column styles. */
140
- columnStyleProps: _propTypes["default"].oneOfType([_propTypes["default"].bool, _propTypes["default"].shape({})]),
141
- /** Determines props that applied to root container. */
142
- fieldContainerProps: _propTypes["default"].shape({
143
- sx: _propTypes["default"].shape({})
144
- }),
145
- /** Determines props that applied to control field. */
146
- fieldControlInputProps: _propTypes["default"].shape({
147
- className: _propTypes["default"].string
148
- }),
149
- /** Determines props that applied to label of field. */
150
- fieldLabelProps: _propTypes["default"].shape({}),
151
- /** Determines whether elements are loading and whether they haven't already appeared in list. */
152
- isLoadingInitial: _propTypes["default"].bool,
153
- /** Container for list with options */
154
- overlay: _propTypes["default"].node,
155
- /** State returned by useSelectState */
156
- state: _propTypes["default"].shape({
157
- isOpen: _propTypes["default"].bool,
158
- selectedItem: _propTypes["default"].shape({
159
- rendered: _propTypes["default"].node
160
- })
161
- }),
162
- /** Provides a way to insert markup in specified places. */
163
- slots: _propTypes["default"].shape({
164
- /** The given node will be inserted before the text in field container. */
165
- leftOfData: _propTypes["default"].node,
166
- /** The given node will be inserted into the field container. */
167
- inContainer: _propTypes["default"].node
168
- }),
169
- /** Control for interaction with SelectField */
170
- trigger: _propTypes["default"].node,
171
- /** Props for the popup trigger element. */
172
- triggerProps: _propTypes["default"].shape({}),
173
- /** Determines ref that applied to control */
174
- triggerRef: _propTypes["default"].shape({}),
175
- /** Props for the element representing the selected value. */
176
- valueProps: _propTypes["default"].shape({})
177
- }, _statusProp.statusPropTypes), _ariaAttributes.ariaAttributesBasePropTypes);
178
121
  var _default = SelectFieldBase;
179
122
  exports["default"] = _default;
@@ -81,7 +81,8 @@ beforeAll(function () {
81
81
  return 1024;
82
82
  });
83
83
  jest.spyOn(window, 'requestAnimationFrame').mockImplementation(function (cb) {
84
- return cb();
84
+ cb(0);
85
+ return 0;
85
86
  });
86
87
  jest.useFakeTimers();
87
88
  });
@@ -165,7 +166,9 @@ test('clicking on the visible button opens the popuplist', function () {
165
166
  var button = _testWrapper.screen.getByRole('button');
166
167
  expect(_testWrapper.screen.queryByRole('listbox')).not.toBeInTheDocument();
167
168
  expect(_testWrapper.screen.queryByRole('option')).not.toBeInTheDocument();
168
- _userEvent["default"].click(button);
169
+ if (button) {
170
+ _userEvent["default"].click(button);
171
+ }
169
172
  expect(_testWrapper.screen.queryByRole('listbox')).toBeInTheDocument();
170
173
  expect(_testWrapper.screen.queryAllByRole('option')).toHaveLength(3);
171
174
  });
@@ -181,7 +184,7 @@ test('clicking on an option then renders its text in the button', function () {
181
184
  _userEvent["default"].click(button);
182
185
  var options = _testWrapper.screen.queryAllByRole('option');
183
186
  _userEvent["default"].click(options[0]);
184
- expect(button).toHaveTextContent(options[0].textContent);
187
+ expect(button).toHaveTextContent(items[0].name);
185
188
  });
186
189
  test('hovering an option applies correct styles', function () {
187
190
  getComponent();
@@ -306,7 +309,10 @@ test('two listbox can not be open at the same time', function () {
306
309
  test('Item accepts a data-id and the data-id can be found in the DOM', function () {
307
310
  getComponent();
308
311
  var button = _testWrapper.screen.queryByRole('button');
309
- _userEvent["default"].click(button);
312
+ expect(button).toBeInTheDocument();
313
+ if (button) {
314
+ _userEvent["default"].click(button);
315
+ }
310
316
  var options = _testWrapper.screen.queryAllByRole('option');
311
317
  expect(options).toHaveLength(items.length);
312
318
  expect(options[0]).toHaveAttribute('data-id', items[0].name);
@@ -0,0 +1 @@
1
+ export { default } from './SelectFieldBase';
@@ -18,6 +18,7 @@ var defaultProps = {
18
18
  'data-testid': testId,
19
19
  label: 'testLabel'
20
20
  };
21
+ var label = defaultProps.label;
21
22
  var getComponent = function getComponent() {
22
23
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
23
24
  return (0, _testWrapper.render)((0, _react3.jsx)(_["default"], (0, _extends2["default"])({}, defaultProps, props)));
@@ -34,12 +35,12 @@ test('disabled prop disables input', function () {
34
35
  getComponent({
35
36
  isDisabled: true
36
37
  });
37
- var textArea = _testWrapper.screen.getByLabelText(defaultProps.label);
38
+ var textArea = _testWrapper.screen.getByLabelText(label);
38
39
  expect(textArea).toBeDisabled();
39
40
  });
40
41
  test('text area field has focus', function () {
41
42
  getComponent();
42
- var textArea = _testWrapper.screen.getByLabelText(defaultProps.label);
43
+ var textArea = _testWrapper.screen.getByLabelText(label);
43
44
  _userEvent["default"].tab();
44
45
  expect(textArea).toHaveFocus();
45
46
  expect(textArea).toHaveClass('is-focused');
@@ -48,8 +49,8 @@ test('disabled prop disables text field label', function () {
48
49
  getComponent({
49
50
  isDisabled: true
50
51
  });
51
- var label = _testWrapper.screen.getByText(defaultProps.label);
52
- expect(label).toHaveClass('is-disabled');
52
+ var labelDom = _testWrapper.screen.getByText(label);
53
+ expect(labelDom).toHaveClass('is-disabled');
53
54
  });
54
55
  test('text area field with helper text', function () {
55
56
  var helperText = 'helper text';
@@ -66,8 +67,8 @@ test('float label prop adds float label class', function () {
66
67
  helperText: helperText,
67
68
  labelMode: labelMode
68
69
  });
69
- var label = _testWrapper.screen.getByText(defaultProps.label);
70
- expect(label).toHaveClass('is-float-label');
70
+ var labelDom = _testWrapper.screen.getByText(label);
71
+ expect(labelDom).toHaveClass('is-float-label');
71
72
  });
72
73
  test('mousemove calls resize event', function () {
73
74
  var labelMode = 'float';
@@ -77,7 +78,7 @@ test('mousemove calls resize event', function () {
77
78
  labelMode: labelMode,
78
79
  resizeCallback: mockfunction
79
80
  });
80
- var textArea = _testWrapper.screen.getByLabelText(defaultProps.label);
81
+ var textArea = _testWrapper.screen.getByLabelText(label);
81
82
  _react2.fireEvent.mouseMove(textArea);
82
83
  _react2.fireEvent.mouseMove(textArea);
83
84
  expect(mockfunction).toHaveBeenCalledTimes(2);
@@ -92,7 +93,7 @@ test('label will receive gridRow attribute if it will be higher than textarea',
92
93
  }
93
94
  });
94
95
  getComponent();
95
- expect(_testWrapper.screen.getByText(defaultProps.label)).toHaveStyle('grid-row: 1/5');
96
+ expect(_testWrapper.screen.getByText(label)).toHaveStyle('grid-row: 1/5');
96
97
  (0, _defineProperty["default"])(HTMLElement.prototype, 'offsetHeight', originalOffsetHeight);
97
98
  });
98
99
  test('form wrapper will have default max label column width when no custom width set', function () {
@@ -108,7 +109,7 @@ test('passing read only prop applys the is-read-only class to the textarea', fun
108
109
  getComponent({
109
110
  isReadOnly: isReadOnly
110
111
  });
111
- var textArea = _testWrapper.screen.getByLabelText(defaultProps.label);
112
+ var textArea = _testWrapper.screen.getByLabelText(label);
112
113
  expect(textArea).toHaveClass('is-read-only');
113
114
  });
114
115
  test('form wrapper will have a max label column width when custom width set', function () {
@@ -4,16 +4,18 @@ import { AriaSelectOptions } from '@react-aria/select';
4
4
  import { SelectState } from '@react-stately/select';
5
5
  import type { CollectionChildren } from '@react-types/shared';
6
6
  import { LabelProps as ThemeUILabelProps } from 'theme-ui';
7
- import { Axis, BoxProps, FocusableElement, LabelModeProps, ListBoxProps, PlacementAxis, ReactRef, StyleProps } from '../../types';
7
+ import { Axis, BoxProps, FocusableElement, LabelModeProps, ListBoxProps, PlacementAxis, ReactButtonRef, ReactRef, StyleProps } from '../../types';
8
8
  import { FieldControlInputProps } from '../useField/useField';
9
- interface UseSelectFieldProps<T> extends AriaSelectOptions<T> {
10
- children: CollectionChildren<T>;
9
+ export interface UseSelectFieldProps<T> extends AriaSelectOptions<T> {
10
+ children?: CollectionChildren<T>;
11
11
  align?: PlacementAxis;
12
12
  defaultSelectedKey?: string;
13
13
  defaultText?: string;
14
14
  direction?: Axis;
15
15
  disabledKeys?: Iterable<Key>;
16
16
  hasNoEmptySelection?: boolean;
17
+ hasNoStatusIndicator?: boolean;
18
+ helperText?: string;
17
19
  isDefaultOpen?: boolean;
18
20
  isDisabled?: boolean;
19
21
  isLoading?: boolean;
@@ -30,14 +32,17 @@ interface UseSelectFieldProps<T> extends AriaSelectOptions<T> {
30
32
  onLoadMore?: () => unknown;
31
33
  onOpenChange?: (isOpen: boolean) => unknown;
32
34
  onSelectionChange?: (key: Key) => unknown;
33
- controlProps?: React.HTMLAttributes<Element>;
35
+ controlProps?: ControlProps;
34
36
  scrollBoxProps?: BoxProps;
35
37
  listBoxProps?: ListBoxProps;
36
38
  labelProps?: ThemeUILabelProps;
37
39
  containerProps?: BoxProps;
38
- labelMode: LabelModeProps;
40
+ labelMode?: LabelModeProps;
39
41
  }
40
- interface UseSelectFieldReturnProps<T> {
42
+ interface ControlProps extends React.HTMLAttributes<Element> {
43
+ 'data-testid'?: string;
44
+ }
45
+ export interface UseSelectFieldReturnProps<T> {
41
46
  columnStyleProps: StyleProps;
42
47
  fieldContainerProps: BoxProps;
43
48
  fieldControlInputProps: FieldControlInputProps;
@@ -49,7 +54,7 @@ interface UseSelectFieldReturnProps<T> {
49
54
  popoverRef: ReactRef;
50
55
  state: SelectState<T>;
51
56
  triggerProps: AriaButtonProps<'button'>;
52
- triggerRef: ReactRef;
57
+ triggerRef: ReactButtonRef;
53
58
  valueProps: DOMAttributes<FocusableElement>;
54
59
  }
55
60
  declare const useSelectField: <T extends object>(props: UseSelectFieldProps<T>, ref: ReactRef) => UseSelectFieldReturnProps<T>;
@@ -1,17 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
+ import { SharedFieldProps } from './shared/fieldProps';
2
3
  import { TestingAttributes } from './shared/test';
3
- import { Status } from './item';
4
- import { LabelModeProps } from './label';
5
4
  import { ValidPositiveInteger } from './shared';
6
- export interface TextAreaFieldProps extends TestingAttributes {
7
- /** The rendered label for the field. */
8
- label: string;
9
- /** Text rendered below the textarea. */
10
- helperText?: string;
11
- /** If present this prop will cause a help hint to render in the label of the field. */
12
- hintText?: string;
13
- /** A string designating whether or not the label is a float label. */
14
- labelMode?: LabelModeProps;
5
+ export interface TextAreaFieldProps extends TestingAttributes, SharedFieldProps {
15
6
  /** Whether the textarea is unable to be resized. */
16
7
  isUnresizable?: boolean;
17
8
  /**
@@ -52,6 +43,4 @@ export interface TextAreaFieldProps extends TestingAttributes {
52
43
  /** The given node will be inserted into the field container. */
53
44
  inContainer: ReactNode;
54
45
  };
55
- /** Status of the textarea field */
56
- status?: Status;
57
46
  }
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { ThemeUICSSObject } from 'theme-ui';
3
3
  import { LabelProps, Status, ValidPositiveInteger } from '.';
4
- type RenderFieldFunction = (id: string, fieldValue: string, onFieldValueChange: (e: React.ChangeEvent, fieldId: string) => void, onFieldDelete: (fieldId: string) => void, isDisabled: boolean, otherFieldProps?: Record<string, string>) => React.ReactNode;
4
+ export type RenderFieldFunction = (id: string, fieldValue: string, onFieldValueChange: (e: React.ChangeEvent, fieldId: string) => void, onFieldDelete: (fieldId: string) => void, isDisabled: boolean, otherFieldProps?: Record<string, string>) => React.ReactNode;
5
5
  export interface FieldValue {
6
6
  id: string;
7
7
  value?: string;
@@ -48,4 +48,3 @@ export interface ArrayFieldDeleteButtonProps {
48
48
  isDisabled?: boolean;
49
49
  onDelete?: (id?: number) => void;
50
50
  }
51
- export {};
@@ -0,0 +1,23 @@
1
+ /// <reference types="react" />
2
+ import { UseSelectFieldProps, UseSelectFieldReturnProps } from '../hooks/useSelectField/useSelectField';
3
+ import { SharedFieldProps } from './shared/fieldProps';
4
+ import { Status } from './item';
5
+ import { StyleProps } from './shared';
6
+ export interface SelectFieldProps<T> extends Omit<StyleProps, 'direction'>, UseSelectFieldProps<T> {
7
+ status?: Status;
8
+ slots?: {
9
+ leftOfData?: React.ReactNode;
10
+ inContainer?: React.ReactNode;
11
+ };
12
+ 'data-testid'?: string;
13
+ }
14
+ export interface SelectFieldBaseProps extends UseSelectFieldReturnProps<object>, SharedFieldProps {
15
+ slots?: {
16
+ inContainer?: React.ReactNode;
17
+ leftOfData?: React.ReactNode;
18
+ };
19
+ name?: string;
20
+ placeholder?: string;
21
+ trigger?: React.ReactNode;
22
+ defaultText?: string;
23
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
+ _Object$defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
@@ -8,3 +8,4 @@ export interface DOMAttributes<T = FocusableElement> extends AriaAttributes, Rea
8
8
  className?: string | undefined;
9
9
  }
10
10
  export type ReactRef = React.Ref<HTMLElement>;
11
+ export type ReactButtonRef = React.Ref<HTMLButtonElement>;
@@ -0,0 +1,12 @@
1
+ import { Status } from '../item';
2
+ import { LabelModeProps } from '../label';
3
+ export interface SharedFieldProps {
4
+ status?: Status;
5
+ label?: string;
6
+ /** Text rendered below the textarea. */
7
+ helperText?: string;
8
+ /** If present this prop will cause a help hint to render in the label of the field. */
9
+ hintText?: string;
10
+ /** A string designating whether or not the label is a float label. */
11
+ labelMode?: LabelModeProps;
12
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
+ _Object$defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
@@ -1,16 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { ThemeUICSSObject } from 'theme-ui';
3
3
  import { ContainerProps, ControlProps } from '../hooks/useField/useField';
4
+ import { SharedFieldProps } from './shared/fieldProps';
4
5
  import { HelpHintProps } from './helpHint';
5
- import { Status } from './item';
6
- import { LabelModeProps } from './label';
7
6
  import { AriaRole, StyleProps, ValidPositiveInteger } from './shared';
8
- export interface TextFieldProps extends StyleProps {
9
- helperText?: string;
10
- /** The rendered label for the field. */
11
- label?: React.ReactNode;
12
- /** A string designating whether or not the label is a float label. */
13
- labelMode?: LabelModeProps;
7
+ export interface TextFieldProps extends StyleProps, SharedFieldProps {
14
8
  /** The unique identifier for the input element. */
15
9
  id?: string;
16
10
  /** The name for the input element. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname). */
@@ -21,8 +15,6 @@ export interface TextFieldProps extends StyleProps {
21
15
  defaultValue?: string;
22
16
  /** Whether the input element is automatically focused when loaded onto the page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautofocus). */
23
17
  hasAutoFocus?: boolean;
24
- /** If present this prop will cause a help hint to render in the label of the field. */
25
- hintText?: string;
26
18
  /** Whether the field has a status indicator. */
27
19
  hasNoStatusIndicator?: boolean;
28
20
  helpHintProps?: HelpHintProps;
@@ -54,7 +46,6 @@ export interface TextFieldProps extends StyleProps {
54
46
  type?: string;
55
47
  /** Props object that is spread directly into the input wrapper element. */
56
48
  wrapperProps?: Record<string, unknown>;
57
- status?: Status;
58
49
  variant?: string;
59
50
  controlProps?: ControlProps;
60
51
  containerProps?: ContainerProps;
@@ -10,6 +10,7 @@ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
10
10
  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; }
11
11
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
12
12
  // Styles for default select and variants go here.
13
+
13
14
  import { text } from '../../styles/variants';
14
15
  import { defaultFocus, input } from '../Input/Input.styles';
15
16
  var activeFloatLabel = {
@@ -12,108 +12,35 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
12
12
  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; }
13
13
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
14
14
  import React, { forwardRef } from 'react';
15
- import PropTypes from 'prop-types';
16
15
  import { usePropWarning, useSelectField } from '../../hooks';
17
- import { ariaAttributesBasePropTypes } from '../../utils/docUtils/ariaAttributes';
18
- import { inputFieldAttributesBasePropTypes } from '../../utils/docUtils/fieldAttributes';
19
- import { statusDefaultProp, statusPropTypes } from '../../utils/docUtils/statusProp';
16
+ import { statusDefaultProp } from '../../utils/docUtils/statusProp';
20
17
  import SelectFieldBase from '../SelectFieldBase';
21
18
  import { jsx as ___EmotionJSX } from "@emotion/react";
22
19
  var SelectField = /*#__PURE__*/forwardRef(function (props, ref) {
23
- var status = props.status;
20
+ /* istanbul ignore next */
21
+ var status = props.status,
22
+ _props$placeholder = props.placeholder,
23
+ placeholder = _props$placeholder === void 0 ? 'Select' : _props$placeholder,
24
+ _props$align = props.align,
25
+ align = _props$align === void 0 ? 'start' : _props$align,
26
+ _props$direction = props.direction,
27
+ direction = _props$direction === void 0 ? 'bottom' : _props$direction,
28
+ _props$scrollBoxProps = props.scrollBoxProps,
29
+ scrollBoxProps = _props$scrollBoxProps === void 0 ? {
30
+ margin: '300px'
31
+ } : _props$scrollBoxProps;
24
32
  usePropWarning(props, 'disabled', 'isDisabled');
25
33
  var _useSelectField = useSelectField(props, ref),
26
34
  selectFieldProps = _extends({}, (_objectDestructuringEmpty(_useSelectField), _useSelectField));
27
- return ___EmotionJSX(SelectFieldBase, _extends({}, props, selectFieldProps, {
35
+ return ___EmotionJSX(SelectFieldBase, _extends({
36
+ placeholder: placeholder,
37
+ align: align,
38
+ direction: direction,
39
+ scrollBoxProps: scrollBoxProps
40
+ }, props, selectFieldProps, {
28
41
  "aria-invalid": status === 'error' && true
29
42
  }));
30
43
  });
31
- SelectField.propTypes = _objectSpread(_objectSpread(_objectSpread({
32
- /** Alignment of the popover menu relative to the trigger. */
33
- align: PropTypes.oneOf(['start', 'end', 'middle']),
34
- /** Where the popover menu opens relative to its trigger. */
35
- direction: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
36
- /** The initial selected key in the collection (uncontrolled). */
37
- defaultSelectedKey: PropTypes.string,
38
- /** Default text rendered if no option is selected. Deprecated. */
39
- defaultText: PropTypes.string,
40
- /** Array of keys to disable within the options list. */
41
- disabledKeys: PropTypes.arrayOf(PropTypes.string),
42
- /** Whether the collection allows empty selection. */
43
- hasNoEmptySelection: PropTypes.bool,
44
- /** Whether the field has a status indicator. */
45
- hasNoStatusIndicator: PropTypes.bool,
46
- /** Text rendered below the input. */
47
- helperText: PropTypes.node,
48
- /** If present this prop will cause a help hint to render in the label of the field. */
49
- hintText: PropTypes.string,
50
- /** Sets the default open state of the menu. */
51
- isDefaultOpen: PropTypes.bool,
52
- /** Whether the input is disabled. */
53
- isDisabled: PropTypes.bool,
54
- /** Whether the items are currently loading. */
55
- isLoading: PropTypes.bool,
56
- /** @ignore Whether the menu should automatically flip direction when space is limited. */
57
- isNotFlippable: PropTypes.bool,
58
- /** Sets the open state of the menu. */
59
- isOpen: PropTypes.bool,
60
- /** @ignore Whether the input can be selected but not changed by the user. */
61
- isReadOnly: PropTypes.bool,
62
- /** Whether user input is required on the input before form submission. */
63
- isRequired: PropTypes.bool,
64
- /**
65
- * *For performance reasons, use this prop instead of Array.map when iteratively rendering Items*.
66
- * For use with [dynamic collections](https://react-spectrum.adobe.com/react-stately/collections.html#dynamic-collections).
67
- */
68
- items: PropTypes.arrayOf(PropTypes.shape({})),
69
- /** The label for the select element. */
70
- label: PropTypes.node,
71
- /** The name for the select element, used when submitting a form. */
72
- name: PropTypes.string,
73
- /** Temporary text that occupies the text input when it is empty. */
74
- placeholder: PropTypes.string,
75
- /** The currently selected key in the collection (controlled). */
76
- selectedKey: PropTypes.string,
77
- /** Determines the textarea status indicator and helper text styling. Eg. float. */
78
- labelMode: PropTypes.string,
79
- /**
80
- * Handler that is called when more items should be loaded, e.g. while scrolling near the bottom.
81
- *
82
- * () => any
83
- */
84
- onLoadMore: PropTypes.func,
85
- /**
86
- * Method that is called when the open state of the menu changes.
87
- *
88
- * (isOpen: boolean) => void
89
- */
90
- onOpenChange: PropTypes.func,
91
- /**
92
- * Handler that is called when the selection changes.
93
- *
94
- * (key: Key) => any
95
- */
96
- onSelectionChange: PropTypes.func
97
- }, inputFieldAttributesBasePropTypes), {}, {
98
- /** Provides a way to insert markup in specified places. */
99
- slots: PropTypes.shape({
100
- /** The given node will be inserted before the text in field container. */
101
- leftOfData: PropTypes.node,
102
- /** The given node will be inserted into the field container. */
103
- inContainer: PropTypes.node
104
- }),
105
- /**
106
- * Props object passed along to `useSelect` from React Aria, `useSelectState` from React Stately,
107
- * and/or the visible button representation for the select input.
108
- */
109
- controlProps: PropTypes.shape({}),
110
- /** Props object that is spread directly into the ScrollBox element. */
111
- // /** Props object that is spread directly into the ScrollBox element. */
112
- /** @ignore */
113
- scrollBoxProps: PropTypes.shape({
114
- maxHeight: PropTypes.string
115
- })
116
- }, statusPropTypes), ariaAttributesBasePropTypes);
117
44
  SelectField.defaultProps = _objectSpread({
118
45
  placeholder: 'Select',
119
46
  align: 'start',
@@ -328,7 +328,10 @@ export var HelperText = function HelperText() {
328
328
  key: "yellow"
329
329
  }, "Yellow"));
330
330
  };
331
- var options = _mapInstanceProperty(_context = _fillInstanceProperty(_context2 = new Array(200)).call(_context2)).call(_context, function (_, i) {
331
+ var options = _mapInstanceProperty(_context = _fillInstanceProperty(_context2 = new Array(200)).call(_context2, {
332
+ key: 'string',
333
+ name: 'string'
334
+ })).call(_context, function (_, i) {
332
335
  return {
333
336
  key: "option-".concat(i),
334
337
  name: "Option ".concat(i)
@@ -17,7 +17,7 @@ var items = [{
17
17
  var withSection = [{
18
18
  name: 'Animals',
19
19
  key: 'Animals',
20
- kids: [{
20
+ children: [{
21
21
  name: 'Aardvark'
22
22
  }, {
23
23
  name: 'Kangaroo'
@@ -27,7 +27,7 @@ var withSection = [{
27
27
  }, {
28
28
  name: 'People',
29
29
  key: 'People',
30
- kids: [{
30
+ children: [{
31
31
  name: 'Michael'
32
32
  }, {
33
33
  name: 'Dwight'
@@ -37,7 +37,7 @@ var withSection = [{
37
37
  }, {
38
38
  name: null,
39
39
  key: 'Fruit',
40
- kids: [{
40
+ children: [{
41
41
  name: 'Apple'
42
42
  }, {
43
43
  name: 'Strawberry'
@@ -78,7 +78,7 @@ var getComponentWithSections = function getComponentWithSections() {
78
78
  }), function (section) {
79
79
  return ___EmotionJSX(Section, {
80
80
  key: section.key,
81
- items: section.kids,
81
+ items: section.children,
82
82
  title: section.name
83
83
  }, function (item) {
84
84
  return ___EmotionJSX(Item, {
@@ -152,4 +152,20 @@ test('a blank title does not render', function () {
152
152
  var button = screen.getByRole('button');
153
153
  userEvent.click(button);
154
154
  expect(screen.queryByText('Fruit')).not.toBeInTheDocument();
155
+ });
156
+ test('renders placeholder text', function () {
157
+ var placeholderText = 'Select an option';
158
+ getComponent({
159
+ placeholder: placeholderText
160
+ });
161
+ var placeholder = screen.getByText(placeholderText);
162
+ expect(placeholder).toBeInTheDocument();
163
+ });
164
+ test('renders default placeholder text', function () {
165
+ var placeholderText = 'Select';
166
+ getComponent({
167
+ placeholder: placeholderText
168
+ });
169
+ var placeholder = screen.getByText(placeholderText);
170
+ expect(placeholder).toBeInTheDocument();
155
171
  });
@@ -10,18 +10,15 @@ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
10
10
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
11
11
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
12
12
  var _excluded = ["columnStyleProps", "defaultText", "fieldContainerProps", "fieldControlInputProps", "fieldControlWrapperProps", "fieldLabelProps", "helperText", "isLoadingInitial", "label", "labelMode", "name", "overlay", "placeholder", "slots", "state", "status", "trigger", "triggerProps", "triggerRef", "valueProps"];
13
- import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
14
13
  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; }
15
14
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
16
15
  import React, { forwardRef, useMemo } from 'react';
17
16
  import { HiddenSelect } from 'react-aria';
18
- import PropTypes from 'prop-types';
19
17
  import { v4 as uuid } from 'uuid';
20
18
  import useGetTheme from '../../hooks/useGetTheme';
21
19
  import { modes } from '../../utils/devUtils/constants/labelModes';
22
20
  import { getPendoID } from '../../utils/devUtils/constants/pendoID';
23
- import { ariaAttributesBasePropTypes, getAriaAttributeProps } from '../../utils/docUtils/ariaAttributes';
24
- import { statusPropTypes } from '../../utils/docUtils/statusProp';
21
+ import { getAriaAttributeProps } from '../../utils/docUtils/ariaAttributes';
25
22
  import Box from '../Box';
26
23
  import Button from '../Button';
27
24
  import FieldHelperText from '../FieldHelperText';
@@ -38,33 +35,34 @@ import Text from '../Text';
38
35
  * React Stately.
39
36
  */
40
37
  import { jsx as ___EmotionJSX } from "@emotion/react";
41
- var SelectFieldBase = /*#__PURE__*/forwardRef(function (_ref, ref) {
42
- var columnStyleProps = _ref.columnStyleProps,
43
- defaultText = _ref.defaultText,
44
- fieldContainerProps = _ref.fieldContainerProps,
45
- fieldControlInputProps = _ref.fieldControlInputProps,
46
- fieldControlWrapperProps = _ref.fieldControlWrapperProps,
47
- fieldLabelProps = _ref.fieldLabelProps,
48
- helperText = _ref.helperText,
49
- isLoadingInitial = _ref.isLoadingInitial,
50
- label = _ref.label,
51
- labelMode = _ref.labelMode,
52
- name = _ref.name,
53
- overlay = _ref.overlay,
54
- placeholder = _ref.placeholder,
55
- slots = _ref.slots,
56
- state = _ref.state,
57
- status = _ref.status,
58
- trigger = _ref.trigger,
59
- triggerProps = _ref.triggerProps,
60
- triggerRef = _ref.triggerRef,
61
- valueProps = _ref.valueProps,
62
- others = _objectWithoutProperties(_ref, _excluded);
38
+ var SelectFieldBase = /*#__PURE__*/forwardRef(function (props, ref) {
39
+ var columnStyleProps = props.columnStyleProps,
40
+ defaultText = props.defaultText,
41
+ fieldContainerProps = props.fieldContainerProps,
42
+ fieldControlInputProps = props.fieldControlInputProps,
43
+ fieldControlWrapperProps = props.fieldControlWrapperProps,
44
+ fieldLabelProps = props.fieldLabelProps,
45
+ helperText = props.helperText,
46
+ isLoadingInitial = props.isLoadingInitial,
47
+ label = props.label,
48
+ labelMode = props.labelMode,
49
+ name = props.name,
50
+ overlay = props.overlay,
51
+ placeholder = props.placeholder,
52
+ slots = props.slots,
53
+ state = props.state,
54
+ status = props.status,
55
+ trigger = props.trigger,
56
+ triggerProps = props.triggerProps,
57
+ triggerRef = props.triggerRef,
58
+ valueProps = props.valueProps,
59
+ others = _objectWithoutProperties(props, _excluded);
63
60
  var _getAriaAttributeProp = getAriaAttributeProps(others),
64
61
  ariaProps = _getAriaAttributeProp.ariaProps;
65
62
  var _useGetTheme = useGetTheme(),
66
63
  icons = _useGetTheme.icons;
67
- var MenuDown = icons.MenuDown;
64
+ var MenuDown = icons.MenuDown,
65
+ MenuUp = icons.MenuUp;
68
66
  var helperTextId = useMemo(function () {
69
67
  return uuid();
70
68
  }, []);
@@ -88,14 +86,11 @@ var SelectFieldBase = /*#__PURE__*/forwardRef(function (_ref, ref) {
88
86
  "aria-hidden": "true",
89
87
  variant: "forms.select.arrow"
90
88
  }, ___EmotionJSX(Icon, {
91
- icon: MenuDown,
89
+ icon: state.isOpen ? MenuUp : MenuDown,
92
90
  title: {
93
91
  name: 'Menu down'
94
92
  },
95
- size: "md",
96
- sx: state.isOpen ? {
97
- transform: 'rotate(180deg)'
98
- } : null
93
+ size: "md"
99
94
  }))), slots === null || slots === void 0 ? void 0 : slots.inContainer);
100
95
  return ___EmotionJSX(Box, _extends({
101
96
  ref: ref,
@@ -113,56 +108,4 @@ var SelectFieldBase = /*#__PURE__*/forwardRef(function (_ref, ref) {
113
108
  id: helperTextId
114
109
  }, helperText));
115
110
  });
116
- SelectFieldBase.propTypes = _objectSpread(_objectSpread({
117
- /** Default text rendered if no option is selected. Deprecated. */
118
- defaultText: PropTypes.string,
119
- /** Text rendered below the input. */
120
- helperText: PropTypes.node,
121
- /** The label for the select element. */
122
- label: PropTypes.node,
123
- /** Determines the textarea status indicator and helper text styling. Eg. float. */
124
- labelMode: PropTypes.oneOf(_Object$values(modes)),
125
- /** The name for the select element, used when submitting a form. */
126
- name: PropTypes.string,
127
- /** Temporary text that occupies the text input when it is empty. */
128
- placeholder: PropTypes.string,
129
- /** Determines whether to use column styles. */
130
- columnStyleProps: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({})]),
131
- /** Determines props that applied to root container. */
132
- fieldContainerProps: PropTypes.shape({
133
- sx: PropTypes.shape({})
134
- }),
135
- /** Determines props that applied to control field. */
136
- fieldControlInputProps: PropTypes.shape({
137
- className: PropTypes.string
138
- }),
139
- /** Determines props that applied to label of field. */
140
- fieldLabelProps: PropTypes.shape({}),
141
- /** Determines whether elements are loading and whether they haven't already appeared in list. */
142
- isLoadingInitial: PropTypes.bool,
143
- /** Container for list with options */
144
- overlay: PropTypes.node,
145
- /** State returned by useSelectState */
146
- state: PropTypes.shape({
147
- isOpen: PropTypes.bool,
148
- selectedItem: PropTypes.shape({
149
- rendered: PropTypes.node
150
- })
151
- }),
152
- /** Provides a way to insert markup in specified places. */
153
- slots: PropTypes.shape({
154
- /** The given node will be inserted before the text in field container. */
155
- leftOfData: PropTypes.node,
156
- /** The given node will be inserted into the field container. */
157
- inContainer: PropTypes.node
158
- }),
159
- /** Control for interaction with SelectField */
160
- trigger: PropTypes.node,
161
- /** Props for the popup trigger element. */
162
- triggerProps: PropTypes.shape({}),
163
- /** Determines ref that applied to control */
164
- triggerRef: PropTypes.shape({}),
165
- /** Props for the element representing the selected value. */
166
- valueProps: PropTypes.shape({})
167
- }, statusPropTypes), ariaAttributesBasePropTypes);
168
111
  export default SelectFieldBase;
@@ -74,7 +74,8 @@ beforeAll(function () {
74
74
  return 1024;
75
75
  });
76
76
  jest.spyOn(window, 'requestAnimationFrame').mockImplementation(function (cb) {
77
- return cb();
77
+ cb(0);
78
+ return 0;
78
79
  });
79
80
  jest.useFakeTimers();
80
81
  });
@@ -158,7 +159,9 @@ test('clicking on the visible button opens the popuplist', function () {
158
159
  var button = screen.getByRole('button');
159
160
  expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
160
161
  expect(screen.queryByRole('option')).not.toBeInTheDocument();
161
- userEvent.click(button);
162
+ if (button) {
163
+ userEvent.click(button);
164
+ }
162
165
  expect(screen.queryByRole('listbox')).toBeInTheDocument();
163
166
  expect(screen.queryAllByRole('option')).toHaveLength(3);
164
167
  });
@@ -174,7 +177,7 @@ test('clicking on an option then renders its text in the button', function () {
174
177
  userEvent.click(button);
175
178
  var options = screen.queryAllByRole('option');
176
179
  userEvent.click(options[0]);
177
- expect(button).toHaveTextContent(options[0].textContent);
180
+ expect(button).toHaveTextContent(items[0].name);
178
181
  });
179
182
  test('hovering an option applies correct styles', function () {
180
183
  getComponent();
@@ -299,7 +302,10 @@ test('two listbox can not be open at the same time', function () {
299
302
  test('Item accepts a data-id and the data-id can be found in the DOM', function () {
300
303
  getComponent();
301
304
  var button = screen.queryByRole('button');
302
- userEvent.click(button);
305
+ expect(button).toBeInTheDocument();
306
+ if (button) {
307
+ userEvent.click(button);
308
+ }
303
309
  var options = screen.queryAllByRole('option');
304
310
  expect(options).toHaveLength(items.length);
305
311
  expect(options[0]).toHaveAttribute('data-id', items[0].name);
@@ -15,6 +15,7 @@ var defaultProps = {
15
15
  'data-testid': testId,
16
16
  label: 'testLabel'
17
17
  };
18
+ var label = defaultProps.label;
18
19
  var getComponent = function getComponent() {
19
20
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
20
21
  return render(___EmotionJSX(TextAreaField, _extends({}, defaultProps, props)));
@@ -31,12 +32,12 @@ test('disabled prop disables input', function () {
31
32
  getComponent({
32
33
  isDisabled: true
33
34
  });
34
- var textArea = screen.getByLabelText(defaultProps.label);
35
+ var textArea = screen.getByLabelText(label);
35
36
  expect(textArea).toBeDisabled();
36
37
  });
37
38
  test('text area field has focus', function () {
38
39
  getComponent();
39
- var textArea = screen.getByLabelText(defaultProps.label);
40
+ var textArea = screen.getByLabelText(label);
40
41
  userEvent.tab();
41
42
  expect(textArea).toHaveFocus();
42
43
  expect(textArea).toHaveClass('is-focused');
@@ -45,8 +46,8 @@ test('disabled prop disables text field label', function () {
45
46
  getComponent({
46
47
  isDisabled: true
47
48
  });
48
- var label = screen.getByText(defaultProps.label);
49
- expect(label).toHaveClass('is-disabled');
49
+ var labelDom = screen.getByText(label);
50
+ expect(labelDom).toHaveClass('is-disabled');
50
51
  });
51
52
  test('text area field with helper text', function () {
52
53
  var helperText = 'helper text';
@@ -63,8 +64,8 @@ test('float label prop adds float label class', function () {
63
64
  helperText: helperText,
64
65
  labelMode: labelMode
65
66
  });
66
- var label = screen.getByText(defaultProps.label);
67
- expect(label).toHaveClass('is-float-label');
67
+ var labelDom = screen.getByText(label);
68
+ expect(labelDom).toHaveClass('is-float-label');
68
69
  });
69
70
  test('mousemove calls resize event', function () {
70
71
  var labelMode = 'float';
@@ -74,7 +75,7 @@ test('mousemove calls resize event', function () {
74
75
  labelMode: labelMode,
75
76
  resizeCallback: mockfunction
76
77
  });
77
- var textArea = screen.getByLabelText(defaultProps.label);
78
+ var textArea = screen.getByLabelText(label);
78
79
  fireEvent.mouseMove(textArea);
79
80
  fireEvent.mouseMove(textArea);
80
81
  expect(mockfunction).toHaveBeenCalledTimes(2);
@@ -89,7 +90,7 @@ test('label will receive gridRow attribute if it will be higher than textarea',
89
90
  }
90
91
  });
91
92
  getComponent();
92
- expect(screen.getByText(defaultProps.label)).toHaveStyle('grid-row: 1/5');
93
+ expect(screen.getByText(label)).toHaveStyle('grid-row: 1/5');
93
94
  _Object$defineProperty(HTMLElement.prototype, 'offsetHeight', originalOffsetHeight);
94
95
  });
95
96
  test('form wrapper will have default max label column width when no custom width set', function () {
@@ -105,7 +106,7 @@ test('passing read only prop applys the is-read-only class to the textarea', fun
105
106
  getComponent({
106
107
  isReadOnly: isReadOnly
107
108
  });
108
- var textArea = screen.getByLabelText(defaultProps.label);
109
+ var textArea = screen.getByLabelText(label);
109
110
  expect(textArea).toHaveClass('is-read-only');
110
111
  });
111
112
  test('form wrapper will have a max label column width when custom width set', function () {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pingux/astro",
3
- "version": "2.93.0-alpha.0",
3
+ "version": "2.93.0-alpha.2",
4
4
  "description": "React component library for Ping Identity's design system",
5
5
  "repository": {
6
6
  "type": "git",