@dhis2-ui/radio 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,34 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+
5
+ var _react2 = _interopRequireDefault(require("react"));
6
+
7
+ var _radio = require("../radio.js");
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ describe('<Radio />', () => {
12
+ it('should call the onKeyDown callback when provided', () => {
13
+ const onKeyDown = jest.fn();
14
+ (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_radio.Radio, {
15
+ name: "foo",
16
+ value: "bar",
17
+ checked: false,
18
+ onKeyDown: onKeyDown
19
+ }));
20
+
21
+ _react.fireEvent.keyDown(_react.screen.getByRole('radio'), {
22
+ key: 'Enter',
23
+ code: 'Enter',
24
+ charCode: 13
25
+ });
26
+
27
+ expect(onKeyDown).toHaveBeenCalledWith({
28
+ name: 'foo',
29
+ value: 'bar',
30
+ checked: true
31
+ }, expect.objectContaining({}));
32
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
33
+ });
34
+ });
@@ -48,6 +48,12 @@ class Radio extends _react.Component {
48
48
  this.props.onFocus(this.createHandlerPayload(), e);
49
49
  }
50
50
  });
51
+
52
+ _defineProperty(this, "handleKeyDown", e => {
53
+ if (this.props.onKeyDown) {
54
+ this.props.onKeyDown(this.createHandlerPayload(), e);
55
+ }
56
+ });
51
57
  }
52
58
 
53
59
  componentDidMount() {
@@ -102,6 +108,7 @@ class Radio extends _react.Component {
102
108
  tabIndex: tabIndex,
103
109
  onChange: this.handleChange,
104
110
  onFocus: this.handleFocus,
111
+ onKeyDown: this.handleKeyDown,
105
112
  onBlur: this.handleBlur,
106
113
  className: _style.default.dynamic([["2846929804", [_uiConstants.colors.grey900, _uiConstants.theme.disabled, label ? '5px' : 0, _uiConstants.theme.focus]]])
107
114
  }), /*#__PURE__*/_react.default.createElement("div", {
@@ -156,5 +163,8 @@ Radio.propTypes = {
156
163
  onChange: _propTypes.default.func,
157
164
 
158
165
  /** Called with the signature `({ name: string, value: string, checked: bool }, event)` */
159
- onFocus: _propTypes.default.func
166
+ onFocus: _propTypes.default.func,
167
+
168
+ /** Called with the signature `({ name: string, value: string, checked: bool }, event)` */
169
+ onKeyDown: _propTypes.default.func
160
170
  };
@@ -0,0 +1,25 @@
1
+ import { render, fireEvent, screen } from '@testing-library/react';
2
+ import React from 'react';
3
+ import { Radio } from '../radio.js';
4
+ describe('<Radio />', () => {
5
+ it('should call the onKeyDown callback when provided', () => {
6
+ const onKeyDown = jest.fn();
7
+ render( /*#__PURE__*/React.createElement(Radio, {
8
+ name: "foo",
9
+ value: "bar",
10
+ checked: false,
11
+ onKeyDown: onKeyDown
12
+ }));
13
+ fireEvent.keyDown(screen.getByRole('radio'), {
14
+ key: 'Enter',
15
+ code: 'Enter',
16
+ charCode: 13
17
+ });
18
+ expect(onKeyDown).toHaveBeenCalledWith({
19
+ name: 'foo',
20
+ value: 'bar',
21
+ checked: true
22
+ }, expect.objectContaining({}));
23
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
24
+ });
25
+ });
package/build/es/radio.js CHANGED
@@ -31,6 +31,12 @@ class Radio extends Component {
31
31
  this.props.onFocus(this.createHandlerPayload(), e);
32
32
  }
33
33
  });
34
+
35
+ _defineProperty(this, "handleKeyDown", e => {
36
+ if (this.props.onKeyDown) {
37
+ this.props.onKeyDown(this.createHandlerPayload(), e);
38
+ }
39
+ });
34
40
  }
35
41
 
36
42
  componentDidMount() {
@@ -85,6 +91,7 @@ class Radio extends Component {
85
91
  tabIndex: tabIndex,
86
92
  onChange: this.handleChange,
87
93
  onFocus: this.handleFocus,
94
+ onKeyDown: this.handleKeyDown,
88
95
  onBlur: this.handleBlur,
89
96
  className: _JSXStyle.dynamic([["2846929804", [colors.grey900, theme.disabled, label ? '5px' : 0, theme.focus]]])
90
97
  }), /*#__PURE__*/React.createElement("div", {
@@ -138,6 +145,9 @@ Radio.propTypes = {
138
145
  onChange: PropTypes.func,
139
146
 
140
147
  /** Called with the signature `({ name: string, value: string, checked: bool }, event)` */
141
- onFocus: PropTypes.func
148
+ onFocus: PropTypes.func,
149
+
150
+ /** Called with the signature `({ name: string, value: string, checked: bool }, event)` */
151
+ onKeyDown: PropTypes.func
142
152
  };
143
153
  export { Radio };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/radio",
3
- "version": "8.3.0",
3
+ "version": "8.4.1",
4
4
  "description": "UI Radio",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@dhis2/prop-types": "^3.1.2",
35
- "@dhis2/ui-constants": "8.3.0",
35
+ "@dhis2/ui-constants": "8.4.1",
36
36
  "classnames": "^2.3.1",
37
37
  "prop-types": "^15.7.2"
38
38
  },