@dhis2-ui/input 8.3.1 → 8.4.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/build/cjs/input/{input.test.js → __tests__/input.test.js} +21 -3
- package/build/cjs/input/input.js +11 -1
- package/build/cjs/input-field/__tests__/input-field.test.js +29 -0
- package/build/cjs/input-field/input-field.js +6 -1
- package/build/es/input/{input.test.js → __tests__/input.test.js} +16 -1
- package/build/es/input/input.js +11 -1
- package/build/es/input-field/__tests__/input-field.test.js +20 -0
- package/build/es/input-field/input-field.js +6 -1
- package/package.json +8 -8
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
3
5
|
var _enzyme = require("enzyme");
|
|
4
6
|
|
|
5
|
-
var
|
|
7
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
6
8
|
|
|
7
|
-
var
|
|
9
|
+
var _input = require("../input.js");
|
|
8
10
|
|
|
9
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
12
|
|
|
@@ -17,10 +19,26 @@ describe('<Input>', () => {
|
|
|
17
19
|
max: '10',
|
|
18
20
|
step: '0.5'
|
|
19
21
|
};
|
|
20
|
-
const wrapper = (0, _enzyme.shallow)( /*#__PURE__*/
|
|
22
|
+
const wrapper = (0, _enzyme.shallow)( /*#__PURE__*/_react2.default.createElement(_input.Input, _extends({
|
|
21
23
|
type: "number"
|
|
22
24
|
}, testProps)));
|
|
23
25
|
const inputEl = wrapper.find('input');
|
|
24
26
|
expect(inputEl.props()).toMatchObject(testProps);
|
|
25
27
|
});
|
|
28
|
+
it('should call the onKeyDown callback when provided', () => {
|
|
29
|
+
const onKeyDown = jest.fn();
|
|
30
|
+
(0, _react.render)( /*#__PURE__*/_react2.default.createElement(_input.Input, {
|
|
31
|
+
name: "foo",
|
|
32
|
+
value: "bar",
|
|
33
|
+
onKeyDown: onKeyDown
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
_react.fireEvent.keyDown(_react.screen.getByRole('textbox'), {});
|
|
37
|
+
|
|
38
|
+
expect(onKeyDown).toHaveBeenCalledWith({
|
|
39
|
+
name: 'foo',
|
|
40
|
+
value: 'bar'
|
|
41
|
+
}, expect.objectContaining({}));
|
|
42
|
+
expect(onKeyDown).toHaveBeenCalledTimes(1);
|
|
43
|
+
});
|
|
26
44
|
});
|
package/build/cjs/input/input.js
CHANGED
|
@@ -51,6 +51,12 @@ class Input extends _react.Component {
|
|
|
51
51
|
this.props.onFocus(this.createHandlerPayload(e), e);
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
+
|
|
55
|
+
_defineProperty(this, "handleKeyDown", e => {
|
|
56
|
+
if (this.props.onKeyDown) {
|
|
57
|
+
this.props.onKeyDown(this.createHandlerPayload(e), e);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
54
60
|
}
|
|
55
61
|
|
|
56
62
|
componentDidMount() {
|
|
@@ -109,6 +115,7 @@ class Input extends _react.Component {
|
|
|
109
115
|
onFocus: this.handleFocus,
|
|
110
116
|
onBlur: this.handleBlur,
|
|
111
117
|
onChange: this.handleChange,
|
|
118
|
+
onKeyDown: this.handleKeyDown,
|
|
112
119
|
className: "jsx-3353877153 " + "jsx-".concat(styles.__hash) + " " + ((0, _classnames.default)({
|
|
113
120
|
dense,
|
|
114
121
|
disabled,
|
|
@@ -198,5 +205,8 @@ Input.propTypes = {
|
|
|
198
205
|
onChange: _propTypes.default.func,
|
|
199
206
|
|
|
200
207
|
/** Called with signature `({ name: string, value: string }, event)` */
|
|
201
|
-
onFocus: _propTypes.default.func
|
|
208
|
+
onFocus: _propTypes.default.func,
|
|
209
|
+
|
|
210
|
+
/** Called with signature `({ name: string, value: string }, event)` */
|
|
211
|
+
onKeyDown: _propTypes.default.func
|
|
202
212
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
6
|
+
|
|
7
|
+
var _inputField = require("../input-field.js");
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
|
|
11
|
+
describe('<Input>', () => {
|
|
12
|
+
it('should call the onKeyDown callback when provided', () => {
|
|
13
|
+
const onKeyDown = jest.fn();
|
|
14
|
+
(0, _react.render)( /*#__PURE__*/_react2.default.createElement(_inputField.InputField, {
|
|
15
|
+
label: "label",
|
|
16
|
+
name: "foo",
|
|
17
|
+
value: "bar",
|
|
18
|
+
onKeyDown: onKeyDown
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
_react.fireEvent.keyDown(_react.screen.getByRole('textbox'), {});
|
|
22
|
+
|
|
23
|
+
expect(onKeyDown).toHaveBeenCalledWith({
|
|
24
|
+
name: 'foo',
|
|
25
|
+
value: 'bar'
|
|
26
|
+
}, expect.objectContaining({}));
|
|
27
|
+
expect(onKeyDown).toHaveBeenCalledTimes(1);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -25,6 +25,7 @@ class InputField extends _react.default.Component {
|
|
|
25
25
|
className,
|
|
26
26
|
onChange,
|
|
27
27
|
onFocus,
|
|
28
|
+
onKeyDown,
|
|
28
29
|
onBlur,
|
|
29
30
|
initialFocus,
|
|
30
31
|
type,
|
|
@@ -67,6 +68,7 @@ class InputField extends _react.default.Component {
|
|
|
67
68
|
minWidth: "72px"
|
|
68
69
|
}, /*#__PURE__*/_react.default.createElement(_input.Input, {
|
|
69
70
|
onFocus: onFocus,
|
|
71
|
+
onKeyDown: onKeyDown,
|
|
70
72
|
onBlur: onBlur,
|
|
71
73
|
onChange: onChange,
|
|
72
74
|
name: name,
|
|
@@ -169,5 +171,8 @@ InputField.propTypes = {
|
|
|
169
171
|
onChange: _propTypes.default.func,
|
|
170
172
|
|
|
171
173
|
/** Called with signature `({ name: string, value: string }, event)` */
|
|
172
|
-
onFocus: _propTypes.default.func
|
|
174
|
+
onFocus: _propTypes.default.func,
|
|
175
|
+
|
|
176
|
+
/** Called with signature `({ name: string, value: string }, event)` */
|
|
177
|
+
onKeyDown: _propTypes.default.func
|
|
173
178
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
|
+
import { render, fireEvent, screen } from '@testing-library/react';
|
|
3
4
|
import { shallow } from 'enzyme';
|
|
4
5
|
import React from 'react';
|
|
5
|
-
import { Input } from '
|
|
6
|
+
import { Input } from '../input.js';
|
|
6
7
|
describe('<Input>', () => {
|
|
7
8
|
it('passes min, max, and step props as attributes to the native <input> element', () => {
|
|
8
9
|
const testProps = {
|
|
@@ -16,4 +17,18 @@ describe('<Input>', () => {
|
|
|
16
17
|
const inputEl = wrapper.find('input');
|
|
17
18
|
expect(inputEl.props()).toMatchObject(testProps);
|
|
18
19
|
});
|
|
20
|
+
it('should call the onKeyDown callback when provided', () => {
|
|
21
|
+
const onKeyDown = jest.fn();
|
|
22
|
+
render( /*#__PURE__*/React.createElement(Input, {
|
|
23
|
+
name: "foo",
|
|
24
|
+
value: "bar",
|
|
25
|
+
onKeyDown: onKeyDown
|
|
26
|
+
}));
|
|
27
|
+
fireEvent.keyDown(screen.getByRole('textbox'), {});
|
|
28
|
+
expect(onKeyDown).toHaveBeenCalledWith({
|
|
29
|
+
name: 'foo',
|
|
30
|
+
value: 'bar'
|
|
31
|
+
}, expect.objectContaining({}));
|
|
32
|
+
expect(onKeyDown).toHaveBeenCalledTimes(1);
|
|
33
|
+
});
|
|
19
34
|
});
|
package/build/es/input/input.js
CHANGED
|
@@ -32,6 +32,12 @@ export class Input extends Component {
|
|
|
32
32
|
this.props.onFocus(this.createHandlerPayload(e), e);
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
|
+
|
|
36
|
+
_defineProperty(this, "handleKeyDown", e => {
|
|
37
|
+
if (this.props.onKeyDown) {
|
|
38
|
+
this.props.onKeyDown(this.createHandlerPayload(e), e);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
componentDidMount() {
|
|
@@ -90,6 +96,7 @@ export class Input extends Component {
|
|
|
90
96
|
onFocus: this.handleFocus,
|
|
91
97
|
onBlur: this.handleBlur,
|
|
92
98
|
onChange: this.handleChange,
|
|
99
|
+
onKeyDown: this.handleKeyDown,
|
|
93
100
|
className: "jsx-3353877153 " + "jsx-".concat(styles.__hash) + " " + (cx({
|
|
94
101
|
dense,
|
|
95
102
|
disabled,
|
|
@@ -177,5 +184,8 @@ Input.propTypes = {
|
|
|
177
184
|
onChange: PropTypes.func,
|
|
178
185
|
|
|
179
186
|
/** Called with signature `({ name: string, value: string }, event)` */
|
|
180
|
-
onFocus: PropTypes.func
|
|
187
|
+
onFocus: PropTypes.func,
|
|
188
|
+
|
|
189
|
+
/** Called with signature `({ name: string, value: string }, event)` */
|
|
190
|
+
onKeyDown: PropTypes.func
|
|
181
191
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { render, fireEvent, screen } from '@testing-library/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { InputField } from '../input-field.js';
|
|
4
|
+
describe('<Input>', () => {
|
|
5
|
+
it('should call the onKeyDown callback when provided', () => {
|
|
6
|
+
const onKeyDown = jest.fn();
|
|
7
|
+
render( /*#__PURE__*/React.createElement(InputField, {
|
|
8
|
+
label: "label",
|
|
9
|
+
name: "foo",
|
|
10
|
+
value: "bar",
|
|
11
|
+
onKeyDown: onKeyDown
|
|
12
|
+
}));
|
|
13
|
+
fireEvent.keyDown(screen.getByRole('textbox'), {});
|
|
14
|
+
expect(onKeyDown).toHaveBeenCalledWith({
|
|
15
|
+
name: 'foo',
|
|
16
|
+
value: 'bar'
|
|
17
|
+
}, expect.objectContaining({}));
|
|
18
|
+
expect(onKeyDown).toHaveBeenCalledTimes(1);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -11,6 +11,7 @@ class InputField extends React.Component {
|
|
|
11
11
|
className,
|
|
12
12
|
onChange,
|
|
13
13
|
onFocus,
|
|
14
|
+
onKeyDown,
|
|
14
15
|
onBlur,
|
|
15
16
|
initialFocus,
|
|
16
17
|
type,
|
|
@@ -53,6 +54,7 @@ class InputField extends React.Component {
|
|
|
53
54
|
minWidth: "72px"
|
|
54
55
|
}, /*#__PURE__*/React.createElement(Input, {
|
|
55
56
|
onFocus: onFocus,
|
|
57
|
+
onKeyDown: onKeyDown,
|
|
56
58
|
onBlur: onBlur,
|
|
57
59
|
onChange: onChange,
|
|
58
60
|
name: name,
|
|
@@ -154,6 +156,9 @@ InputField.propTypes = {
|
|
|
154
156
|
onChange: PropTypes.func,
|
|
155
157
|
|
|
156
158
|
/** Called with signature `({ name: string, value: string }, event)` */
|
|
157
|
-
onFocus: PropTypes.func
|
|
159
|
+
onFocus: PropTypes.func,
|
|
160
|
+
|
|
161
|
+
/** Called with signature `({ name: string, value: string }, event)` */
|
|
162
|
+
onKeyDown: PropTypes.func
|
|
158
163
|
};
|
|
159
164
|
export { InputField };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2-ui/input",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.2",
|
|
4
4
|
"description": "UI Input",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@dhis2/prop-types": "^3.1.2",
|
|
35
|
-
"@dhis2-ui/box": "8.
|
|
36
|
-
"@dhis2-ui/field": "8.
|
|
37
|
-
"@dhis2-ui/input": "8.
|
|
38
|
-
"@dhis2-ui/loader": "8.
|
|
39
|
-
"@dhis2-ui/status-icon": "8.
|
|
40
|
-
"@dhis2/ui-constants": "8.
|
|
41
|
-
"@dhis2/ui-icons": "8.
|
|
35
|
+
"@dhis2-ui/box": "8.4.2",
|
|
36
|
+
"@dhis2-ui/field": "8.4.2",
|
|
37
|
+
"@dhis2-ui/input": "8.4.2",
|
|
38
|
+
"@dhis2-ui/loader": "8.4.2",
|
|
39
|
+
"@dhis2-ui/status-icon": "8.4.2",
|
|
40
|
+
"@dhis2/ui-constants": "8.4.2",
|
|
41
|
+
"@dhis2/ui-icons": "8.4.2",
|
|
42
42
|
"classnames": "^2.3.1",
|
|
43
43
|
"prop-types": "^15.7.2"
|
|
44
44
|
},
|