@dhis2-ui/button 9.3.0-alpha.2 → 9.4.0-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/build/cjs/button/__tests__/Button.test.js +11 -0
- package/build/cjs/button/button.js +9 -5
- package/build/cjs/button/button.stories.js +6 -2
- package/build/es/button/__tests__/Button.test.js +11 -0
- package/build/es/button/button.js +10 -5
- package/build/es/button/button.stories.js +6 -2
- package/package.json +6 -6
- package/types/index.d.ts +1 -1
@@ -31,6 +31,17 @@ describe('<Button>', () => {
|
|
31
31
|
});
|
32
32
|
expect(actual.length).toBe(1);
|
33
33
|
});
|
34
|
+
it('has the accessibility attributes', () => {
|
35
|
+
const dataTest = 'button-data-test';
|
36
|
+
const wrapper = (0, _enzyme.mount)( /*#__PURE__*/_react2.default.createElement(_button.Button, {
|
37
|
+
dataTest: dataTest,
|
38
|
+
ariaLabel: "test aria label",
|
39
|
+
title: "title for button"
|
40
|
+
}));
|
41
|
+
const buttonElement = wrapper.find('button').getDOMNode();
|
42
|
+
expect(buttonElement).toHaveAttribute('title', 'title for button');
|
43
|
+
expect(buttonElement).toHaveAttribute('ariaLabel', 'test aria label');
|
44
|
+
});
|
34
45
|
describe('toggle', () => {
|
35
46
|
it('should have class "toggled" if toggled-prop is true', () => {
|
36
47
|
const wrapper = (0, _enzyme.mount)( /*#__PURE__*/_react2.default.createElement(_button.Button, {
|
@@ -25,6 +25,8 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
25
25
|
|
26
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
27
27
|
|
28
|
+
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); }
|
29
|
+
|
28
30
|
const Button = _ref => {
|
29
31
|
let {
|
30
32
|
children,
|
@@ -47,7 +49,8 @@ const Button = _ref => {
|
|
47
49
|
onClick,
|
48
50
|
onFocus,
|
49
51
|
onKeyDown,
|
50
|
-
loading
|
52
|
+
loading,
|
53
|
+
...otherProps
|
51
54
|
} = _ref;
|
52
55
|
const ref = (0, _react.useRef)();
|
53
56
|
(0, _react.useEffect)(() => {
|
@@ -87,7 +90,7 @@ const Button = _ref => {
|
|
87
90
|
toggled,
|
88
91
|
loading: loading
|
89
92
|
});
|
90
|
-
return /*#__PURE__*/_react.default.createElement("button", {
|
93
|
+
return /*#__PURE__*/_react.default.createElement("button", _extends({
|
91
94
|
ref: ref,
|
92
95
|
name: name,
|
93
96
|
"data-test": dataTest,
|
@@ -97,9 +100,10 @@ const Button = _ref => {
|
|
97
100
|
onBlur: handleBlur,
|
98
101
|
onClick: handleClick,
|
99
102
|
onFocus: handleFocus,
|
100
|
-
onKeyDown: handleKeyDown
|
101
|
-
|
102
|
-
|
103
|
+
onKeyDown: handleKeyDown
|
104
|
+
}, otherProps, {
|
105
|
+
className: "jsx-".concat(_buttonStyles.default.__hash) + " " + (otherProps && otherProps.className != null && otherProps.className || buttonClassName || "")
|
106
|
+
}), loading && /*#__PURE__*/_react.default.createElement("span", {
|
103
107
|
className: "jsx-".concat(_buttonStyles.default.__hash) + " " + "loader"
|
104
108
|
}, destructive || primary ? /*#__PURE__*/_react.default.createElement(_loader.CircularLoader, {
|
105
109
|
extrasmall: true,
|
@@ -44,7 +44,9 @@ var _default = {
|
|
44
44
|
args: {
|
45
45
|
children: 'Label me!',
|
46
46
|
value: 'default',
|
47
|
-
onClick: logger
|
47
|
+
onClick: logger,
|
48
|
+
title: 'Button',
|
49
|
+
ariaLabel: 'Button'
|
48
50
|
},
|
49
51
|
argTypes: {
|
50
52
|
primary: { ...buttonVariantArgType
|
@@ -255,7 +257,9 @@ exports.IconOnly = IconOnly;
|
|
255
257
|
IconOnly.args = {
|
256
258
|
icon: DemoIcon24,
|
257
259
|
name: 'Icon only button',
|
258
|
-
children: null
|
260
|
+
children: null,
|
261
|
+
title: 'Icon Button',
|
262
|
+
ariaLabel: 'Icon Button'
|
259
263
|
};
|
260
264
|
const IconSmall = Template.bind({});
|
261
265
|
exports.IconSmall = IconSmall;
|
@@ -23,6 +23,17 @@ describe('<Button>', () => {
|
|
23
23
|
});
|
24
24
|
expect(actual.length).toBe(1);
|
25
25
|
});
|
26
|
+
it('has the accessibility attributes', () => {
|
27
|
+
const dataTest = 'button-data-test';
|
28
|
+
const wrapper = mount( /*#__PURE__*/React.createElement(Button, {
|
29
|
+
dataTest: dataTest,
|
30
|
+
ariaLabel: "test aria label",
|
31
|
+
title: "title for button"
|
32
|
+
}));
|
33
|
+
const buttonElement = wrapper.find('button').getDOMNode();
|
34
|
+
expect(buttonElement).toHaveAttribute('title', 'title for button');
|
35
|
+
expect(buttonElement).toHaveAttribute('ariaLabel', 'test aria label');
|
36
|
+
});
|
26
37
|
describe('toggle', () => {
|
27
38
|
it('should have class "toggled" if toggled-prop is true', () => {
|
28
39
|
const wrapper = mount( /*#__PURE__*/React.createElement(Button, {
|
@@ -1,4 +1,7 @@
|
|
1
1
|
import _JSXStyle from "styled-jsx/style";
|
2
|
+
|
3
|
+
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); }
|
4
|
+
|
2
5
|
import { CircularLoader } from '@dhis2-ui/loader';
|
3
6
|
import { sharedPropTypes } from '@dhis2/ui-constants';
|
4
7
|
import cx from 'classnames';
|
@@ -27,7 +30,8 @@ export const Button = _ref => {
|
|
27
30
|
onClick,
|
28
31
|
onFocus,
|
29
32
|
onKeyDown,
|
30
|
-
loading
|
33
|
+
loading,
|
34
|
+
...otherProps
|
31
35
|
} = _ref;
|
32
36
|
const ref = useRef();
|
33
37
|
useEffect(() => {
|
@@ -67,7 +71,7 @@ export const Button = _ref => {
|
|
67
71
|
toggled,
|
68
72
|
loading: loading
|
69
73
|
});
|
70
|
-
return /*#__PURE__*/React.createElement("button", {
|
74
|
+
return /*#__PURE__*/React.createElement("button", _extends({
|
71
75
|
ref: ref,
|
72
76
|
name: name,
|
73
77
|
"data-test": dataTest,
|
@@ -77,9 +81,10 @@ export const Button = _ref => {
|
|
77
81
|
onBlur: handleBlur,
|
78
82
|
onClick: handleClick,
|
79
83
|
onFocus: handleFocus,
|
80
|
-
onKeyDown: handleKeyDown
|
81
|
-
|
82
|
-
|
84
|
+
onKeyDown: handleKeyDown
|
85
|
+
}, otherProps, {
|
86
|
+
className: "jsx-".concat(styles.__hash) + " " + (otherProps && otherProps.className != null && otherProps.className || buttonClassName || "")
|
87
|
+
}), loading && /*#__PURE__*/React.createElement("span", {
|
83
88
|
className: "jsx-".concat(styles.__hash) + " " + "loader"
|
84
89
|
}, destructive || primary ? /*#__PURE__*/React.createElement(CircularLoader, {
|
85
90
|
extrasmall: true,
|
@@ -32,7 +32,9 @@ export default {
|
|
32
32
|
args: {
|
33
33
|
children: 'Label me!',
|
34
34
|
value: 'default',
|
35
|
-
onClick: logger
|
35
|
+
onClick: logger,
|
36
|
+
title: 'Button',
|
37
|
+
ariaLabel: 'Button'
|
36
38
|
},
|
37
39
|
argTypes: {
|
38
40
|
primary: { ...buttonVariantArgType
|
@@ -222,7 +224,9 @@ export const IconOnly = Template.bind({});
|
|
222
224
|
IconOnly.args = {
|
223
225
|
icon: DemoIcon24,
|
224
226
|
name: 'Icon only button',
|
225
|
-
children: null
|
227
|
+
children: null,
|
228
|
+
title: 'Icon Button',
|
229
|
+
ariaLabel: 'Icon Button'
|
226
230
|
};
|
227
231
|
export const IconSmall = Template.bind({});
|
228
232
|
IconSmall.args = {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dhis2-ui/button",
|
3
|
-
"version": "9.
|
3
|
+
"version": "9.4.0-alpha.1",
|
4
4
|
"description": "UI Button",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -33,11 +33,11 @@
|
|
33
33
|
},
|
34
34
|
"dependencies": {
|
35
35
|
"@dhis2/prop-types": "^3.1.2",
|
36
|
-
"@dhis2-ui/layer": "9.
|
37
|
-
"@dhis2-ui/loader": "9.
|
38
|
-
"@dhis2-ui/popper": "9.
|
39
|
-
"@dhis2/ui-constants": "9.
|
40
|
-
"@dhis2/ui-icons": "9.
|
36
|
+
"@dhis2-ui/layer": "9.4.0-alpha.1",
|
37
|
+
"@dhis2-ui/loader": "9.4.0-alpha.1",
|
38
|
+
"@dhis2-ui/popper": "9.4.0-alpha.1",
|
39
|
+
"@dhis2/ui-constants": "9.4.0-alpha.1",
|
40
|
+
"@dhis2/ui-icons": "9.4.0-alpha.1",
|
41
41
|
"classnames": "^2.3.1",
|
42
42
|
"prop-types": "^15.7.2"
|
43
43
|
},
|
package/types/index.d.ts
CHANGED
@@ -16,7 +16,7 @@ type ButtonOpenEventHandler<
|
|
16
16
|
Event extends React.SyntheticEvent = React.MouseEvent<HTMLButtonElement>
|
17
17
|
> = (arg0: ButtonEventPayload & { open: boolean }, event: Event) => void
|
18
18
|
|
19
|
-
export interface ButtonProps {
|
19
|
+
export interface ButtonProps extends HTMLButtonElement {
|
20
20
|
/**
|
21
21
|
* Component to render inside the button
|
22
22
|
*/
|