@dhis2-ui/select 8.3.0 → 8.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+
5
+ var _react2 = _interopRequireDefault(require("react"));
6
+
7
+ var _multiSelect = require("../multi-select.js");
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ describe('<MultiSelect />', () => {
12
+ it('should call the onKeyDown callback when provided', () => {
13
+ const onKeyDown = jest.fn();
14
+ (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_multiSelect.MultiSelect, {
15
+ placeholder: "placeholder",
16
+ onKeyDown: onKeyDown
17
+ }));
18
+
19
+ _react.fireEvent.keyDown(_react.screen.getByTestId('dhis2-uicore-multiselect-placeholder'), {
20
+ key: 'Enter',
21
+ code: 'Enter',
22
+ charCode: 13
23
+ });
24
+
25
+ expect(onKeyDown).toHaveBeenCalledWith({
26
+ selected: []
27
+ }, expect.objectContaining({}));
28
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
29
+ });
30
+ });
@@ -36,6 +36,7 @@ const MultiSelect = _ref => {
36
36
  inputMaxHeight,
37
37
  onChange,
38
38
  onFocus,
39
+ onKeyDown,
39
40
  onBlur,
40
41
  loading,
41
42
  error,
@@ -87,6 +88,7 @@ const MultiSelect = _ref => {
87
88
  maxHeight: maxHeight,
88
89
  onChange: onChange,
89
90
  onFocus: onFocus,
91
+ onKeyDown: onKeyDown,
90
92
  onBlur: onBlur,
91
93
  error: error,
92
94
  warning: warning,
@@ -146,5 +148,6 @@ MultiSelect.propTypes = {
146
148
  warning: _uiConstants.sharedPropTypes.statusPropType,
147
149
  onBlur: _propTypes2.default.func,
148
150
  onChange: _propTypes2.default.func,
149
- onFocus: _propTypes2.default.func
151
+ onFocus: _propTypes2.default.func,
152
+ onKeyDown: _propTypes2.default.func
150
153
  };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+
5
+ var _react2 = _interopRequireDefault(require("react"));
6
+
7
+ var _multiSelectField = require("../multi-select-field.js");
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ describe('<MultiSelect />', () => {
12
+ it('should call the onKeyDown callback when provided', () => {
13
+ const onKeyDown = jest.fn();
14
+ (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_multiSelectField.MultiSelectField, {
15
+ label: "label",
16
+ placeholder: "placeholder",
17
+ onKeyDown: onKeyDown
18
+ }));
19
+
20
+ _react.fireEvent.keyDown(_react.screen.getByTestId('dhis2-uicore-multiselect-placeholder'), {
21
+ key: 'Enter',
22
+ code: 'Enter',
23
+ charCode: 13
24
+ });
25
+
26
+ expect(onKeyDown).toHaveBeenCalledWith({
27
+ selected: []
28
+ }, expect.objectContaining({}));
29
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
30
+ });
31
+ });
@@ -36,6 +36,7 @@ class MultiSelectField extends _react.default.Component {
36
36
  className,
37
37
  onChange,
38
38
  onFocus,
39
+ onKeyDown,
39
40
  onBlur,
40
41
  required,
41
42
  label,
@@ -86,6 +87,7 @@ class MultiSelectField extends _react.default.Component {
86
87
  inputMaxHeight: inputMaxHeight,
87
88
  onChange: onChange,
88
89
  onFocus: onFocus,
90
+ onKeyDown: onKeyDown,
89
91
  onBlur: onBlur,
90
92
  loading: loading,
91
93
  error: error,
@@ -204,5 +206,8 @@ MultiSelectField.propTypes = {
204
206
  onChange: _propTypes.default.func,
205
207
 
206
208
  /** Called with signature `({ selected: [String] }, event)` */
207
- onFocus: _propTypes.default.func
209
+ onFocus: _propTypes.default.func,
210
+
211
+ /** Called with signature `({ selected: [String] }, event)` */
212
+ onKeyDown: _propTypes.default.func
208
213
  };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+
5
+ var _react2 = _interopRequireDefault(require("react"));
6
+
7
+ var _select = require("../select.js");
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ describe('<Select />', () => {
12
+ it('should call the onKeyDown callback when provided', () => {
13
+ const onKeyDown = jest.fn();
14
+ (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_select.Select, {
15
+ input: /*#__PURE__*/_react2.default.createElement("input", {
16
+ type: "text"
17
+ }),
18
+ menu: /*#__PURE__*/_react2.default.createElement("div", null),
19
+ selected: "",
20
+ onKeyDown: onKeyDown
21
+ }));
22
+
23
+ _react.fireEvent.keyDown(_react.screen.getByRole('textbox'), {
24
+ key: 'Enter',
25
+ code: 'Enter',
26
+ charCode: 13
27
+ });
28
+
29
+ expect(onKeyDown).toHaveBeenCalledWith({
30
+ selected: ''
31
+ }, expect.objectContaining({}));
32
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
33
+ });
34
+ });
@@ -117,7 +117,23 @@ class Select extends _react.Component {
117
117
  });
118
118
 
119
119
  _defineProperty(this, "onKeyDown", e => {
120
- if (this.props.disabled) {
120
+ const {
121
+ onKeyDown,
122
+ disabled,
123
+ selected
124
+ } = this.props;
125
+
126
+ if (disabled) {
127
+ return;
128
+ }
129
+
130
+ if (onKeyDown) {
131
+ onKeyDown({
132
+ selected
133
+ }, e);
134
+ }
135
+
136
+ if (e.defaultPrevented) {
121
137
  return;
122
138
  }
123
139
 
@@ -269,5 +285,6 @@ Select.propTypes = {
269
285
  warning: _uiConstants.sharedPropTypes.statusPropType,
270
286
  onBlur: _propTypes.default.func,
271
287
  onChange: _propTypes.default.func,
272
- onFocus: _propTypes.default.func
288
+ onFocus: _propTypes.default.func,
289
+ onKeyDown: _propTypes.default.func
273
290
  };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+
5
+ var _react2 = _interopRequireDefault(require("react"));
6
+
7
+ var _singleSelect = require("../single-select.js");
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ describe('<SingleSelect />', () => {
12
+ it('should call the onKeyDown callback when provided', () => {
13
+ const onKeyDown = jest.fn();
14
+ (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_singleSelect.SingleSelect, {
15
+ placeholder: "placeholder",
16
+ onKeyDown: onKeyDown
17
+ }));
18
+
19
+ _react.fireEvent.keyDown(_react.screen.getByTestId('dhis2-uicore-singleselect-placeholder'), {
20
+ key: 'Enter',
21
+ code: 'Enter',
22
+ charCode: 13
23
+ });
24
+
25
+ expect(onKeyDown).toHaveBeenCalledWith({
26
+ selected: ''
27
+ }, expect.objectContaining({}));
28
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
29
+ });
30
+ });
@@ -36,6 +36,7 @@ const SingleSelect = _ref => {
36
36
  inputMaxHeight,
37
37
  onChange,
38
38
  onFocus,
39
+ onKeyDown,
39
40
  onBlur,
40
41
  loading,
41
42
  error,
@@ -87,6 +88,7 @@ const SingleSelect = _ref => {
87
88
  maxHeight: maxHeight,
88
89
  onChange: onChange,
89
90
  onFocus: onFocus,
91
+ onKeyDown: onKeyDown,
90
92
  onBlur: onBlur,
91
93
  error: error,
92
94
  warning: warning,
@@ -154,5 +156,6 @@ SingleSelect.propTypes = {
154
156
  warning: _uiConstants.sharedPropTypes.statusPropType,
155
157
  onBlur: _propTypes2.default.func,
156
158
  onChange: _propTypes2.default.func,
157
- onFocus: _propTypes2.default.func
159
+ onFocus: _propTypes2.default.func,
160
+ onKeyDown: _propTypes2.default.func
158
161
  };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+
5
+ var _react2 = _interopRequireDefault(require("react"));
6
+
7
+ var _singleSelectField = require("../single-select-field.js");
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ describe('<SingleSelect />', () => {
12
+ it('should call the onKeyDown callback when provided', () => {
13
+ const onKeyDown = jest.fn();
14
+ (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_singleSelectField.SingleSelectField, {
15
+ label: "label",
16
+ placeholder: "placeholder",
17
+ onKeyDown: onKeyDown
18
+ }));
19
+
20
+ _react.fireEvent.keyDown(_react.screen.getByTestId('dhis2-uicore-singleselect-placeholder'), {
21
+ key: 'Enter',
22
+ code: 'Enter',
23
+ charCode: 13
24
+ });
25
+
26
+ expect(onKeyDown).toHaveBeenCalledWith({
27
+ selected: ''
28
+ }, expect.objectContaining({}));
29
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
30
+ });
31
+ });
@@ -36,6 +36,7 @@ class SingleSelectField extends _react.default.Component {
36
36
  className,
37
37
  onChange,
38
38
  onFocus,
39
+ onKeyDown,
39
40
  onBlur,
40
41
  required,
41
42
  label,
@@ -86,6 +87,7 @@ class SingleSelectField extends _react.default.Component {
86
87
  inputMaxHeight: inputMaxHeight,
87
88
  onChange: onChange,
88
89
  onFocus: onFocus,
90
+ onKeyDown: onKeyDown,
89
91
  onBlur: onBlur,
90
92
  loading: loading,
91
93
  error: error,
@@ -204,5 +206,8 @@ SingleSelectField.propTypes = {
204
206
  onChange: _propTypes.default.func,
205
207
 
206
208
  /** Called with signature `({ selected: string }, event)` */
207
- onFocus: _propTypes.default.func
209
+ onFocus: _propTypes.default.func,
210
+
211
+ /** Called with signature `({ selected: string }, event)` */
212
+ onKeyDown: _propTypes.default.func
208
213
  };
@@ -0,0 +1,21 @@
1
+ import { render, fireEvent, screen } from '@testing-library/react';
2
+ import React from 'react';
3
+ import { MultiSelect } from '../multi-select.js';
4
+ describe('<MultiSelect />', () => {
5
+ it('should call the onKeyDown callback when provided', () => {
6
+ const onKeyDown = jest.fn();
7
+ render( /*#__PURE__*/React.createElement(MultiSelect, {
8
+ placeholder: "placeholder",
9
+ onKeyDown: onKeyDown
10
+ }));
11
+ fireEvent.keyDown(screen.getByTestId('dhis2-uicore-multiselect-placeholder'), {
12
+ key: 'Enter',
13
+ code: 'Enter',
14
+ charCode: 13
15
+ });
16
+ expect(onKeyDown).toHaveBeenCalledWith({
17
+ selected: []
18
+ }, expect.objectContaining({}));
19
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
20
+ });
21
+ });
@@ -18,6 +18,7 @@ const MultiSelect = _ref => {
18
18
  inputMaxHeight,
19
19
  onChange,
20
20
  onFocus,
21
+ onKeyDown,
21
22
  onBlur,
22
23
  loading,
23
24
  error,
@@ -69,6 +70,7 @@ const MultiSelect = _ref => {
69
70
  maxHeight: maxHeight,
70
71
  onChange: onChange,
71
72
  onFocus: onFocus,
73
+ onKeyDown: onKeyDown,
72
74
  onBlur: onBlur,
73
75
  error: error,
74
76
  warning: warning,
@@ -127,6 +129,7 @@ MultiSelect.propTypes = {
127
129
  warning: sharedPropTypes.statusPropType,
128
130
  onBlur: PropTypes.func,
129
131
  onChange: PropTypes.func,
130
- onFocus: PropTypes.func
132
+ onFocus: PropTypes.func,
133
+ onKeyDown: PropTypes.func
131
134
  };
132
135
  export { MultiSelect };
@@ -0,0 +1,22 @@
1
+ import { render, fireEvent, screen } from '@testing-library/react';
2
+ import React from 'react';
3
+ import { MultiSelectField } from '../multi-select-field.js';
4
+ describe('<MultiSelect />', () => {
5
+ it('should call the onKeyDown callback when provided', () => {
6
+ const onKeyDown = jest.fn();
7
+ render( /*#__PURE__*/React.createElement(MultiSelectField, {
8
+ label: "label",
9
+ placeholder: "placeholder",
10
+ onKeyDown: onKeyDown
11
+ }));
12
+ fireEvent.keyDown(screen.getByTestId('dhis2-uicore-multiselect-placeholder'), {
13
+ key: 'Enter',
14
+ code: 'Enter',
15
+ charCode: 13
16
+ });
17
+ expect(onKeyDown).toHaveBeenCalledWith({
18
+ selected: []
19
+ }, expect.objectContaining({}));
20
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
21
+ });
22
+ });
@@ -20,6 +20,7 @@ class MultiSelectField extends React.Component {
20
20
  className,
21
21
  onChange,
22
22
  onFocus,
23
+ onKeyDown,
23
24
  onBlur,
24
25
  required,
25
26
  label,
@@ -70,6 +71,7 @@ class MultiSelectField extends React.Component {
70
71
  inputMaxHeight: inputMaxHeight,
71
72
  onChange: onChange,
72
73
  onFocus: onFocus,
74
+ onKeyDown: onKeyDown,
73
75
  onBlur: onBlur,
74
76
  loading: loading,
75
77
  error: error,
@@ -187,6 +189,9 @@ MultiSelectField.propTypes = {
187
189
  onChange: PropTypes.func,
188
190
 
189
191
  /** Called with signature `({ selected: [String] }, event)` */
190
- onFocus: PropTypes.func
192
+ onFocus: PropTypes.func,
193
+
194
+ /** Called with signature `({ selected: [String] }, event)` */
195
+ onKeyDown: PropTypes.func
191
196
  };
192
197
  export { MultiSelectField };
@@ -0,0 +1,25 @@
1
+ import { render, fireEvent, screen } from '@testing-library/react';
2
+ import React from 'react';
3
+ import { Select } from '../select.js';
4
+ describe('<Select />', () => {
5
+ it('should call the onKeyDown callback when provided', () => {
6
+ const onKeyDown = jest.fn();
7
+ render( /*#__PURE__*/React.createElement(Select, {
8
+ input: /*#__PURE__*/React.createElement("input", {
9
+ type: "text"
10
+ }),
11
+ menu: /*#__PURE__*/React.createElement("div", null),
12
+ selected: "",
13
+ onKeyDown: onKeyDown
14
+ }));
15
+ fireEvent.keyDown(screen.getByRole('textbox'), {
16
+ key: 'Enter',
17
+ code: 'Enter',
18
+ charCode: 13
19
+ });
20
+ expect(onKeyDown).toHaveBeenCalledWith({
21
+ selected: ''
22
+ }, expect.objectContaining({}));
23
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
24
+ });
25
+ });
@@ -97,7 +97,23 @@ export class Select extends Component {
97
97
  });
98
98
 
99
99
  _defineProperty(this, "onKeyDown", e => {
100
- if (this.props.disabled) {
100
+ const {
101
+ onKeyDown,
102
+ disabled,
103
+ selected
104
+ } = this.props;
105
+
106
+ if (disabled) {
107
+ return;
108
+ }
109
+
110
+ if (onKeyDown) {
111
+ onKeyDown({
112
+ selected
113
+ }, e);
114
+ }
115
+
116
+ if (e.defaultPrevented) {
101
117
  return;
102
118
  }
103
119
 
@@ -243,5 +259,6 @@ Select.propTypes = {
243
259
  warning: sharedPropTypes.statusPropType,
244
260
  onBlur: PropTypes.func,
245
261
  onChange: PropTypes.func,
246
- onFocus: PropTypes.func
262
+ onFocus: PropTypes.func,
263
+ onKeyDown: PropTypes.func
247
264
  };
@@ -0,0 +1,21 @@
1
+ import { render, fireEvent, screen } from '@testing-library/react';
2
+ import React from 'react';
3
+ import { SingleSelect } from '../single-select.js';
4
+ describe('<SingleSelect />', () => {
5
+ it('should call the onKeyDown callback when provided', () => {
6
+ const onKeyDown = jest.fn();
7
+ render( /*#__PURE__*/React.createElement(SingleSelect, {
8
+ placeholder: "placeholder",
9
+ onKeyDown: onKeyDown
10
+ }));
11
+ fireEvent.keyDown(screen.getByTestId('dhis2-uicore-singleselect-placeholder'), {
12
+ key: 'Enter',
13
+ code: 'Enter',
14
+ charCode: 13
15
+ });
16
+ expect(onKeyDown).toHaveBeenCalledWith({
17
+ selected: ''
18
+ }, expect.objectContaining({}));
19
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
20
+ });
21
+ });
@@ -18,6 +18,7 @@ const SingleSelect = _ref => {
18
18
  inputMaxHeight,
19
19
  onChange,
20
20
  onFocus,
21
+ onKeyDown,
21
22
  onBlur,
22
23
  loading,
23
24
  error,
@@ -69,6 +70,7 @@ const SingleSelect = _ref => {
69
70
  maxHeight: maxHeight,
70
71
  onChange: onChange,
71
72
  onFocus: onFocus,
73
+ onKeyDown: onKeyDown,
72
74
  onBlur: onBlur,
73
75
  error: error,
74
76
  warning: warning,
@@ -135,6 +137,7 @@ SingleSelect.propTypes = {
135
137
  warning: sharedPropTypes.statusPropType,
136
138
  onBlur: PropTypes.func,
137
139
  onChange: PropTypes.func,
138
- onFocus: PropTypes.func
140
+ onFocus: PropTypes.func,
141
+ onKeyDown: PropTypes.func
139
142
  };
140
143
  export { SingleSelect };
@@ -0,0 +1,22 @@
1
+ import { render, fireEvent, screen } from '@testing-library/react';
2
+ import React from 'react';
3
+ import { SingleSelectField } from '../single-select-field.js';
4
+ describe('<SingleSelect />', () => {
5
+ it('should call the onKeyDown callback when provided', () => {
6
+ const onKeyDown = jest.fn();
7
+ render( /*#__PURE__*/React.createElement(SingleSelectField, {
8
+ label: "label",
9
+ placeholder: "placeholder",
10
+ onKeyDown: onKeyDown
11
+ }));
12
+ fireEvent.keyDown(screen.getByTestId('dhis2-uicore-singleselect-placeholder'), {
13
+ key: 'Enter',
14
+ code: 'Enter',
15
+ charCode: 13
16
+ });
17
+ expect(onKeyDown).toHaveBeenCalledWith({
18
+ selected: ''
19
+ }, expect.objectContaining({}));
20
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
21
+ });
22
+ });
@@ -20,6 +20,7 @@ class SingleSelectField extends React.Component {
20
20
  className,
21
21
  onChange,
22
22
  onFocus,
23
+ onKeyDown,
23
24
  onBlur,
24
25
  required,
25
26
  label,
@@ -70,6 +71,7 @@ class SingleSelectField extends React.Component {
70
71
  inputMaxHeight: inputMaxHeight,
71
72
  onChange: onChange,
72
73
  onFocus: onFocus,
74
+ onKeyDown: onKeyDown,
73
75
  onBlur: onBlur,
74
76
  loading: loading,
75
77
  error: error,
@@ -187,6 +189,9 @@ SingleSelectField.propTypes = {
187
189
  onChange: PropTypes.func,
188
190
 
189
191
  /** Called with signature `({ selected: string }, event)` */
190
- onFocus: PropTypes.func
192
+ onFocus: PropTypes.func,
193
+
194
+ /** Called with signature `({ selected: string }, event)` */
195
+ onKeyDown: PropTypes.func
191
196
  };
192
197
  export { SingleSelectField };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/select",
3
- "version": "8.3.0",
3
+ "version": "8.4.1",
4
4
  "description": "UI Select",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,19 +33,19 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@dhis2/prop-types": "^3.1.2",
36
- "@dhis2-ui/box": "8.3.0",
37
- "@dhis2-ui/button": "8.3.0",
38
- "@dhis2-ui/card": "8.3.0",
39
- "@dhis2-ui/checkbox": "8.3.0",
40
- "@dhis2-ui/chip": "8.3.0",
41
- "@dhis2-ui/field": "8.3.0",
42
- "@dhis2-ui/input": "8.3.0",
43
- "@dhis2-ui/layer": "8.3.0",
44
- "@dhis2-ui/loader": "8.3.0",
45
- "@dhis2-ui/popper": "8.3.0",
46
- "@dhis2-ui/status-icon": "8.3.0",
47
- "@dhis2/ui-constants": "8.3.0",
48
- "@dhis2/ui-icons": "8.3.0",
36
+ "@dhis2-ui/box": "8.4.1",
37
+ "@dhis2-ui/button": "8.4.1",
38
+ "@dhis2-ui/card": "8.4.1",
39
+ "@dhis2-ui/checkbox": "8.4.1",
40
+ "@dhis2-ui/chip": "8.4.1",
41
+ "@dhis2-ui/field": "8.4.1",
42
+ "@dhis2-ui/input": "8.4.1",
43
+ "@dhis2-ui/layer": "8.4.1",
44
+ "@dhis2-ui/loader": "8.4.1",
45
+ "@dhis2-ui/popper": "8.4.1",
46
+ "@dhis2-ui/status-icon": "8.4.1",
47
+ "@dhis2/ui-constants": "8.4.1",
48
+ "@dhis2/ui-icons": "8.4.1",
49
49
  "classnames": "^2.3.1",
50
50
  "prop-types": "^15.7.2"
51
51
  },