@instructure/ui-buttons 10.16.1-snapshot-0 → 10.16.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.
- package/CHANGELOG.md +1 -1
- package/es/BaseButton/__new-tests__/BaseButton.test.js +123 -86
- package/es/BaseButton/index.js +33 -26
- package/es/Button/__new-tests__/Button.test.js +145 -105
- package/es/Button/index.js +6 -2
- package/es/CloseButton/__new-tests__/CloseButton.test.js +3 -3
- package/es/CloseButton/index.js +25 -20
- package/es/CondensedButton/__new-tests__/CondensedButton.test.js +60 -45
- package/es/CondensedButton/index.js +7 -4
- package/es/IconButton/__new-tests__/IconButton.test.js +25 -23
- package/es/IconButton/index.js +9 -4
- package/es/ToggleButton/__new-tests__/ToggleButton.test.js +19 -18
- package/es/ToggleButton/index.js +19 -15
- package/lib/BaseButton/__new-tests__/BaseButton.test.js +159 -122
- package/lib/BaseButton/index.js +32 -26
- package/lib/Button/__new-tests__/Button.test.js +187 -147
- package/lib/Button/index.js +6 -3
- package/lib/CloseButton/__new-tests__/CloseButton.test.js +7 -7
- package/lib/CloseButton/index.js +24 -19
- package/lib/CondensedButton/__new-tests__/CondensedButton.test.js +73 -58
- package/lib/CondensedButton/index.js +7 -5
- package/lib/IconButton/__new-tests__/IconButton.test.js +39 -37
- package/lib/IconButton/index.js +9 -5
- package/lib/ToggleButton/__new-tests__/ToggleButton.test.js +31 -30
- package/lib/ToggleButton/index.js +19 -16
- package/package.json +20 -20
- package/src/BaseButton/__new-tests__/BaseButton.test.tsx +0 -1
- package/src/BaseButton/index.tsx +2 -3
- package/src/Button/__new-tests__/Button.test.tsx +0 -1
- package/src/Button/index.tsx +1 -1
- package/src/CloseButton/__new-tests__/CloseButton.test.tsx +0 -1
- package/src/CloseButton/index.tsx +1 -2
- package/src/CondensedButton/__new-tests__/CondensedButton.test.tsx +0 -1
- package/src/CondensedButton/index.tsx +1 -1
- package/src/IconButton/__new-tests__/IconButton.test.tsx +0 -1
- package/src/IconButton/index.tsx +1 -1
- package/src/IconButton/props.ts +1 -1
- package/src/ToggleButton/__new-tests__/ToggleButton.test.tsx +0 -1
- package/src/ToggleButton/index.tsx +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/BaseButton/__new-tests__/BaseButton.test.d.ts.map +1 -1
- package/types/BaseButton/index.d.ts +4 -6
- package/types/BaseButton/index.d.ts.map +1 -1
- package/types/Button/__new-tests__/Button.test.d.ts.map +1 -1
- package/types/Button/index.d.ts +2 -2
- package/types/Button/index.d.ts.map +1 -1
- package/types/CloseButton/__new-tests__/CloseButton.test.d.ts.map +1 -1
- package/types/CloseButton/index.d.ts +1 -3
- package/types/CloseButton/index.d.ts.map +1 -1
- package/types/CondensedButton/__new-tests__/CondensedButton.test.d.ts.map +1 -1
- package/types/CondensedButton/index.d.ts +2 -2
- package/types/CondensedButton/index.d.ts.map +1 -1
- package/types/IconButton/__new-tests__/IconButton.test.d.ts.map +1 -1
- package/types/IconButton/index.d.ts +4 -4
- package/types/IconButton/index.d.ts.map +1 -1
- package/types/IconButton/props.d.ts +1 -1
- package/types/IconButton/props.d.ts.map +1 -1
- package/types/ToggleButton/__new-tests__/ToggleButton.test.d.ts.map +1 -1
- package/types/ToggleButton/index.d.ts +2 -2
- package/types/ToggleButton/index.d.ts.map +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _react =
|
|
5
|
-
var _react2 = require("@testing-library/react");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
6
5
|
var _vitest = require("vitest");
|
|
7
6
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
8
7
|
require("@testing-library/jest-dom");
|
|
9
8
|
var _index = require("../index");
|
|
9
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
10
|
var _CloseButton;
|
|
11
11
|
/*
|
|
12
12
|
* The MIT License (MIT)
|
|
@@ -41,10 +41,10 @@ describe('<CloseButton />', () => {
|
|
|
41
41
|
consoleWarningMock.mockRestore();
|
|
42
42
|
});
|
|
43
43
|
it('should render with x icon', async () => {
|
|
44
|
-
(0,
|
|
44
|
+
(0, _react.render)(_CloseButton || (_CloseButton = (0, _jsxRuntime.jsx)(_index.CloseButton, {
|
|
45
45
|
screenReaderLabel: "Close"
|
|
46
46
|
})));
|
|
47
|
-
const button =
|
|
47
|
+
const button = _react.screen.getByRole('button');
|
|
48
48
|
const icon = document.querySelector('svg');
|
|
49
49
|
expect(icon).toBeInTheDocument();
|
|
50
50
|
expect(icon).toHaveAttribute('name', 'IconX');
|
|
@@ -53,13 +53,13 @@ describe('<CloseButton />', () => {
|
|
|
53
53
|
});
|
|
54
54
|
it('should pass the `onClick` prop', async () => {
|
|
55
55
|
const onClick = _vitest.vi.fn();
|
|
56
|
-
(0,
|
|
56
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.CloseButton, {
|
|
57
57
|
onClick: onClick,
|
|
58
58
|
screenReaderLabel: "Hello"
|
|
59
59
|
}));
|
|
60
|
-
const button =
|
|
60
|
+
const button = _react.screen.getByRole('button');
|
|
61
61
|
await _userEvent.default.click(button);
|
|
62
|
-
await (0,
|
|
62
|
+
await (0, _react.waitFor)(() => {
|
|
63
63
|
expect(onClick).toHaveBeenCalledTimes(1);
|
|
64
64
|
});
|
|
65
65
|
});
|
package/lib/CloseButton/index.js
CHANGED
|
@@ -17,6 +17,7 @@ var _styles = _interopRequireDefault(require("./styles"));
|
|
|
17
17
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
18
18
|
var _BaseButton = require("../BaseButton");
|
|
19
19
|
var _props = require("./props");
|
|
20
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
20
21
|
const _excluded = ["screenReaderLabel", "elementRef", "size", "onClick", "margin", "placement", "offset", "type", "as", "href", "cursor", "tabIndex", "styles"];
|
|
21
22
|
var _dec, _dec2, _class, _CloseButton;
|
|
22
23
|
/*
|
|
@@ -42,7 +43,6 @@ var _dec, _dec2, _class, _CloseButton;
|
|
|
42
43
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
43
44
|
* SOFTWARE.
|
|
44
45
|
*/
|
|
45
|
-
/** @jsx jsx */
|
|
46
46
|
/**
|
|
47
47
|
---
|
|
48
48
|
category: components
|
|
@@ -92,25 +92,30 @@ let CloseButton = exports.CloseButton = (_dec = (0, _emotion.withStyle)(_styles.
|
|
|
92
92
|
tabIndex = _this$props3.tabIndex,
|
|
93
93
|
styles = _this$props3.styles,
|
|
94
94
|
props = (0, _objectWithoutProperties2.default)(_this$props3, _excluded);
|
|
95
|
-
return (0,
|
|
95
|
+
return (0, _jsxRuntime.jsx)("span", {
|
|
96
|
+
...(0, _passthroughProps.passthroughProps)(props),
|
|
96
97
|
css: styles === null || styles === void 0 ? void 0 : styles.closeButton,
|
|
97
|
-
ref: el => this.ref = el
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
98
|
+
ref: el => this.ref = el,
|
|
99
|
+
children: (0, _jsxRuntime.jsx)(_BaseButton.BaseButton, {
|
|
100
|
+
renderIcon: _IconXSolid.IconXSolid,
|
|
101
|
+
elementRef: this.handleRef,
|
|
102
|
+
interaction: this.interaction,
|
|
103
|
+
type: type,
|
|
104
|
+
color: this.color,
|
|
105
|
+
size: size,
|
|
106
|
+
onClick: onClick,
|
|
107
|
+
margin: margin,
|
|
108
|
+
withBorder: false,
|
|
109
|
+
withBackground: false,
|
|
110
|
+
as: as,
|
|
111
|
+
href: href,
|
|
112
|
+
cursor: cursor,
|
|
113
|
+
tabIndex: tabIndex,
|
|
114
|
+
children: (0, _jsxRuntime.jsx)(_ScreenReaderContent.ScreenReaderContent, {
|
|
115
|
+
children: screenReaderLabel
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
});
|
|
114
119
|
}
|
|
115
120
|
}, _CloseButton.displayName = "CloseButton", _CloseButton.componentId = 'CloseButton', _CloseButton.propTypes = _props.propTypes, _CloseButton.allowedProps = _props.allowedProps, _CloseButton.defaultProps = {
|
|
116
121
|
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _react =
|
|
5
|
-
var _react2 = require("@testing-library/react");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
6
5
|
var _vitest = require("vitest");
|
|
7
6
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
8
7
|
require("@testing-library/jest-dom");
|
|
9
8
|
var _index = require("../index");
|
|
9
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
10
|
var _circle, _CondensedButton, _CondensedButton2, _CondensedButton3, _CondensedButton4, _CondensedButton5, _CondensedButton6, _CondensedButton7;
|
|
11
11
|
/*
|
|
12
12
|
* The MIT License (MIT)
|
|
@@ -33,22 +33,25 @@ var _circle, _CondensedButton, _CondensedButton2, _CondensedButton3, _CondensedB
|
|
|
33
33
|
*/
|
|
34
34
|
describe('<CondensedButton/>', () => {
|
|
35
35
|
var _CondensedButton8;
|
|
36
|
-
const icon =
|
|
36
|
+
const icon = (0, _jsxRuntime.jsx)("svg", {
|
|
37
37
|
"data-title": "myIcon",
|
|
38
38
|
height: "1em",
|
|
39
39
|
width: "1em",
|
|
40
40
|
style: {
|
|
41
41
|
fill: 'currentcolor'
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
},
|
|
43
|
+
children: _circle || (_circle = (0, _jsxRuntime.jsx)("circle", {
|
|
44
|
+
cx: "0.5em",
|
|
45
|
+
cy: "0.5em",
|
|
46
|
+
r: "0.5em"
|
|
47
|
+
}))
|
|
48
|
+
});
|
|
48
49
|
const iconSelector = 'svg[data-title="myIcon"]';
|
|
49
50
|
it('should render children', () => {
|
|
50
51
|
const children = 'Hello world';
|
|
51
|
-
(0,
|
|
52
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
53
|
+
children: children
|
|
54
|
+
}));
|
|
52
55
|
const button = document.querySelector('button');
|
|
53
56
|
expect(button).toBeInTheDocument();
|
|
54
57
|
expect(button).toHaveTextContent(children);
|
|
@@ -56,12 +59,13 @@ describe('<CondensedButton/>', () => {
|
|
|
56
59
|
it('should provide a focused getter', () => {
|
|
57
60
|
var _componentRef;
|
|
58
61
|
let componentRef;
|
|
59
|
-
(0,
|
|
62
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
60
63
|
ref: component => {
|
|
61
64
|
componentRef = component;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
},
|
|
66
|
+
children: "Hello"
|
|
67
|
+
}));
|
|
68
|
+
const button = _react.screen.getByRole('button', {
|
|
65
69
|
name: 'Hello'
|
|
66
70
|
});
|
|
67
71
|
button.focus();
|
|
@@ -70,22 +74,24 @@ describe('<CondensedButton/>', () => {
|
|
|
70
74
|
it('should provide a focus function', () => {
|
|
71
75
|
var _componentRef2;
|
|
72
76
|
let componentRef;
|
|
73
|
-
(0,
|
|
77
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
74
78
|
ref: component => {
|
|
75
79
|
componentRef = component;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
},
|
|
81
|
+
children: "Hello"
|
|
82
|
+
}));
|
|
83
|
+
const button = _react.screen.getByRole('button', {
|
|
79
84
|
name: 'Hello'
|
|
80
85
|
});
|
|
81
86
|
(_componentRef2 = componentRef) === null || _componentRef2 === void 0 ? void 0 : _componentRef2.focus();
|
|
82
87
|
expect(document.activeElement).toBe(button);
|
|
83
88
|
});
|
|
84
89
|
it('should pass the type attribute', () => {
|
|
85
|
-
(0,
|
|
86
|
-
type: "submit"
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
(0, _react.render)(_CondensedButton || (_CondensedButton = (0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
91
|
+
type: "submit",
|
|
92
|
+
children: "Hello"
|
|
93
|
+
})));
|
|
94
|
+
const button = _react.screen.getByRole('button', {
|
|
89
95
|
name: 'Hello'
|
|
90
96
|
});
|
|
91
97
|
expect(button).toBeInTheDocument();
|
|
@@ -93,18 +99,20 @@ describe('<CondensedButton/>', () => {
|
|
|
93
99
|
});
|
|
94
100
|
it('should pass the `elementRef` prop', async () => {
|
|
95
101
|
const elementRef = _vitest.vi.fn();
|
|
96
|
-
(0,
|
|
97
|
-
elementRef: elementRef
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
103
|
+
elementRef: elementRef,
|
|
104
|
+
children: "Hello"
|
|
105
|
+
}));
|
|
106
|
+
const button = _react.screen.getByRole('button', {
|
|
100
107
|
name: 'Hello'
|
|
101
108
|
});
|
|
102
109
|
expect(elementRef).toHaveBeenCalledWith(button);
|
|
103
110
|
});
|
|
104
111
|
it('should pass the `as` prop', () => {
|
|
105
|
-
const _render = (0,
|
|
106
|
-
as: "li"
|
|
107
|
-
|
|
112
|
+
const _render = (0, _react.render)(_CondensedButton2 || (_CondensedButton2 = (0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
113
|
+
as: "li",
|
|
114
|
+
children: "Hello"
|
|
115
|
+
}))),
|
|
108
116
|
container = _render.container;
|
|
109
117
|
const button = container.querySelector('[type="button"]');
|
|
110
118
|
expect(button).toBeInTheDocument();
|
|
@@ -112,57 +120,63 @@ describe('<CondensedButton/>', () => {
|
|
|
112
120
|
expect(button.tagName).toBe('LI');
|
|
113
121
|
});
|
|
114
122
|
it('should set the disabled attribute when `interaction` is set to disabled', () => {
|
|
115
|
-
(0,
|
|
116
|
-
interaction: "disabled"
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
(0, _react.render)(_CondensedButton3 || (_CondensedButton3 = (0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
124
|
+
interaction: "disabled",
|
|
125
|
+
children: "Hello"
|
|
126
|
+
})));
|
|
127
|
+
const button = _react.screen.getByRole('button', {
|
|
119
128
|
name: 'Hello'
|
|
120
129
|
});
|
|
121
130
|
expect(button).toHaveAttribute('disabled');
|
|
122
131
|
});
|
|
123
132
|
it('should set the disabled attribute when `disabled` is set', () => {
|
|
124
|
-
(0,
|
|
125
|
-
disabled: true
|
|
126
|
-
|
|
127
|
-
|
|
133
|
+
(0, _react.render)(_CondensedButton4 || (_CondensedButton4 = (0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
134
|
+
disabled: true,
|
|
135
|
+
children: "Hello"
|
|
136
|
+
})));
|
|
137
|
+
const button = _react.screen.getByRole('button', {
|
|
128
138
|
name: 'Hello'
|
|
129
139
|
});
|
|
130
140
|
expect(button).toHaveAttribute('disabled');
|
|
131
141
|
});
|
|
132
142
|
it('should set the disabled attribute when `interaction` is set to readonly', () => {
|
|
133
|
-
(0,
|
|
134
|
-
interaction: "readonly"
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
(0, _react.render)(_CondensedButton5 || (_CondensedButton5 = (0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
144
|
+
interaction: "readonly",
|
|
145
|
+
children: "Hello"
|
|
146
|
+
})));
|
|
147
|
+
const button = _react.screen.getByRole('button', {
|
|
137
148
|
name: 'Hello'
|
|
138
149
|
});
|
|
139
150
|
expect(button).toHaveAttribute('disabled');
|
|
140
151
|
});
|
|
141
152
|
it('should set the disabled attribute when `readOnly` is set', () => {
|
|
142
|
-
(0,
|
|
143
|
-
readOnly: true
|
|
144
|
-
|
|
145
|
-
|
|
153
|
+
(0, _react.render)(_CondensedButton6 || (_CondensedButton6 = (0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
154
|
+
readOnly: true,
|
|
155
|
+
children: "Hello"
|
|
156
|
+
})));
|
|
157
|
+
const button = _react.screen.getByRole('button', {
|
|
146
158
|
name: 'Hello'
|
|
147
159
|
});
|
|
148
160
|
expect(button).toHaveAttribute('disabled');
|
|
149
161
|
});
|
|
150
162
|
it('should pass the `href` prop', () => {
|
|
151
|
-
(0,
|
|
152
|
-
href: "#"
|
|
153
|
-
|
|
154
|
-
|
|
163
|
+
(0, _react.render)(_CondensedButton7 || (_CondensedButton7 = (0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
164
|
+
href: "#",
|
|
165
|
+
children: "Hello"
|
|
166
|
+
})));
|
|
167
|
+
const linkButton = _react.screen.getByRole('link', {
|
|
155
168
|
name: 'Hello'
|
|
156
169
|
});
|
|
157
170
|
expect(linkButton).toBeInTheDocument();
|
|
158
171
|
expect(linkButton).toHaveAttribute('href', '#');
|
|
159
172
|
});
|
|
160
173
|
it('should pass the `renderIcon` prop', async () => {
|
|
161
|
-
(0,
|
|
162
|
-
renderIcon: icon
|
|
163
|
-
|
|
174
|
+
(0, _react.render)(_CondensedButton8 || (_CondensedButton8 = (0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
175
|
+
renderIcon: icon,
|
|
176
|
+
children: "Hello"
|
|
177
|
+
})));
|
|
164
178
|
const svgIcon = document.querySelector(iconSelector);
|
|
165
|
-
const button =
|
|
179
|
+
const button = _react.screen.getByRole('button', {
|
|
166
180
|
name: 'Hello'
|
|
167
181
|
});
|
|
168
182
|
expect(button).toBeInTheDocument();
|
|
@@ -170,14 +184,15 @@ describe('<CondensedButton/>', () => {
|
|
|
170
184
|
});
|
|
171
185
|
it('should pass the `onClick` prop', async () => {
|
|
172
186
|
const onClick = _vitest.vi.fn();
|
|
173
|
-
(0,
|
|
174
|
-
onClick: onClick
|
|
175
|
-
|
|
176
|
-
|
|
187
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.CondensedButton, {
|
|
188
|
+
onClick: onClick,
|
|
189
|
+
children: "Hello"
|
|
190
|
+
}));
|
|
191
|
+
const button = _react.screen.getByRole('button', {
|
|
177
192
|
name: 'Hello'
|
|
178
193
|
});
|
|
179
194
|
await _userEvent.default.click(button);
|
|
180
|
-
await (0,
|
|
195
|
+
await (0, _react.waitFor)(() => {
|
|
181
196
|
expect(onClick).toHaveBeenCalledTimes(1);
|
|
182
197
|
});
|
|
183
198
|
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = exports.CondensedButton = void 0;
|
|
9
8
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
|
-
var _react =
|
|
9
|
+
var _react = require("react");
|
|
11
10
|
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
12
11
|
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
13
12
|
var _emotion = require("@instructure/emotion");
|
|
14
13
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
15
14
|
var _BaseButton = require("../BaseButton");
|
|
16
15
|
var _props = require("./props");
|
|
16
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
17
17
|
const _excluded = ["children", "type", "size", "elementRef", "as", "interaction", "color", "margin", "cursor", "href", "renderIcon"];
|
|
18
18
|
var _dec, _dec2, _class, _CondensedButton;
|
|
19
19
|
/*
|
|
@@ -79,7 +79,8 @@ let CondensedButton = exports.CondensedButton = (_dec = (0, _emotion.withStyle)(
|
|
|
79
79
|
renderIcon = _this$props.renderIcon,
|
|
80
80
|
props = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
|
|
81
81
|
const themeOverride = this.props.themeOverride;
|
|
82
|
-
return
|
|
82
|
+
return (0, _jsxRuntime.jsx)(_BaseButton.BaseButton, {
|
|
83
|
+
...(0, _passthroughProps.passthroughProps)(props),
|
|
83
84
|
isCondensed: true,
|
|
84
85
|
withBackground: false,
|
|
85
86
|
withBorder: false,
|
|
@@ -96,8 +97,9 @@ let CondensedButton = exports.CondensedButton = (_dec = (0, _emotion.withStyle)(
|
|
|
96
97
|
themeOverride: themeOverride,
|
|
97
98
|
ref: component => {
|
|
98
99
|
this._baseButton = component;
|
|
99
|
-
}
|
|
100
|
-
|
|
100
|
+
},
|
|
101
|
+
children: children
|
|
102
|
+
});
|
|
101
103
|
}
|
|
102
104
|
}, _CondensedButton.displayName = "CondensedButton", _CondensedButton.componentId = 'CondensedButton', _CondensedButton.propTypes = _props.propTypes, _CondensedButton.allowedProps = _props.allowedProps, _CondensedButton.defaultProps = {
|
|
103
105
|
type: 'button',
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _react =
|
|
5
|
-
var _react2 = require("@testing-library/react");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
6
5
|
var _vitest = require("vitest");
|
|
7
6
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
8
7
|
require("@testing-library/jest-dom");
|
|
9
8
|
var _index = require("../index");
|
|
9
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
10
|
var _circle;
|
|
11
11
|
/*
|
|
12
12
|
* The MIT License (MIT)
|
|
@@ -33,99 +33,101 @@ var _circle;
|
|
|
33
33
|
*/
|
|
34
34
|
describe('<IconButton/>', () => {
|
|
35
35
|
var _IconButton, _IconButton2, _IconButton3, _IconButton4, _IconButton5, _IconButton6, _IconButton7, _IconButton8, _IconButton9;
|
|
36
|
-
const icon =
|
|
36
|
+
const icon = (0, _jsxRuntime.jsx)("svg", {
|
|
37
37
|
"data-title": "myIcon",
|
|
38
38
|
height: "1em",
|
|
39
39
|
width: "1em",
|
|
40
40
|
style: {
|
|
41
41
|
fill: 'currentcolor'
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
},
|
|
43
|
+
children: _circle || (_circle = (0, _jsxRuntime.jsx)("circle", {
|
|
44
|
+
cx: "0.5em",
|
|
45
|
+
cy: "0.5em",
|
|
46
|
+
r: "0.5em"
|
|
47
|
+
}))
|
|
48
|
+
});
|
|
48
49
|
const iconSelector = 'svg[data-title="myIcon"]';
|
|
49
50
|
it('should render an icon when provided as the `children` prop', () => {
|
|
50
|
-
(0,
|
|
51
|
-
screenReaderLabel: "some action"
|
|
52
|
-
|
|
51
|
+
(0, _react.render)(_IconButton || (_IconButton = (0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
52
|
+
screenReaderLabel: "some action",
|
|
53
|
+
children: icon
|
|
54
|
+
})));
|
|
53
55
|
const svgIcon = document.querySelector(iconSelector);
|
|
54
|
-
const button =
|
|
56
|
+
const button = _react.screen.getByRole('button');
|
|
55
57
|
expect(button).toBeInTheDocument();
|
|
56
58
|
expect(svgIcon).toBeInTheDocument();
|
|
57
59
|
expect(button).toHaveTextContent('some action');
|
|
58
60
|
});
|
|
59
61
|
it('should render an icon when provided as the `renderIcon` prop', () => {
|
|
60
|
-
(0,
|
|
62
|
+
(0, _react.render)(_IconButton2 || (_IconButton2 = (0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
61
63
|
screenReaderLabel: "some action",
|
|
62
64
|
renderIcon: icon
|
|
63
65
|
})));
|
|
64
66
|
const svgIcon = document.querySelector(iconSelector);
|
|
65
|
-
const button =
|
|
67
|
+
const button = _react.screen.getByRole('button');
|
|
66
68
|
expect(button).toBeInTheDocument();
|
|
67
69
|
expect(svgIcon).toBeInTheDocument();
|
|
68
70
|
});
|
|
69
71
|
it('should provide a focused getter', () => {
|
|
70
72
|
var _componentRef;
|
|
71
73
|
let componentRef;
|
|
72
|
-
(0,
|
|
74
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
73
75
|
screenReaderLabel: "some action",
|
|
74
76
|
renderIcon: icon,
|
|
75
77
|
ref: component => {
|
|
76
78
|
componentRef = component;
|
|
77
79
|
}
|
|
78
80
|
}));
|
|
79
|
-
const button =
|
|
81
|
+
const button = _react.screen.getByRole('button');
|
|
80
82
|
button.focus();
|
|
81
83
|
expect((_componentRef = componentRef) === null || _componentRef === void 0 ? void 0 : _componentRef.focused).toBe(true);
|
|
82
84
|
});
|
|
83
85
|
it('should provide a focus function', () => {
|
|
84
86
|
var _componentRef2;
|
|
85
87
|
let componentRef;
|
|
86
|
-
(0,
|
|
88
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
87
89
|
screenReaderLabel: "some action",
|
|
88
90
|
renderIcon: icon,
|
|
89
91
|
ref: component => {
|
|
90
92
|
componentRef = component;
|
|
91
93
|
}
|
|
92
94
|
}));
|
|
93
|
-
const button =
|
|
95
|
+
const button = _react.screen.getByRole('button');
|
|
94
96
|
(_componentRef2 = componentRef) === null || _componentRef2 === void 0 ? void 0 : _componentRef2.focus();
|
|
95
97
|
expect(document.activeElement).toBe(button);
|
|
96
98
|
});
|
|
97
99
|
it('should pass the `href` prop', () => {
|
|
98
|
-
(0,
|
|
100
|
+
(0, _react.render)(_IconButton3 || (_IconButton3 = (0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
99
101
|
screenReaderLabel: "some action",
|
|
100
102
|
renderIcon: icon,
|
|
101
103
|
href: "#"
|
|
102
104
|
})));
|
|
103
|
-
const linkButton =
|
|
105
|
+
const linkButton = _react.screen.getByRole('link');
|
|
104
106
|
expect(linkButton).toBeInTheDocument();
|
|
105
107
|
expect(linkButton).toHaveAttribute('href', '#');
|
|
106
108
|
});
|
|
107
109
|
it('should pass the `type` prop', () => {
|
|
108
|
-
(0,
|
|
110
|
+
(0, _react.render)(_IconButton4 || (_IconButton4 = (0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
109
111
|
screenReaderLabel: "some action",
|
|
110
112
|
renderIcon: icon,
|
|
111
113
|
type: "reset"
|
|
112
114
|
})));
|
|
113
|
-
const button =
|
|
115
|
+
const button = _react.screen.getByRole('button');
|
|
114
116
|
expect(button).toBeInTheDocument();
|
|
115
117
|
expect(button).toHaveAttribute('type', 'reset');
|
|
116
118
|
});
|
|
117
119
|
it('should pass the `elementRef` prop', () => {
|
|
118
120
|
const elementRef = _vitest.vi.fn();
|
|
119
|
-
(0,
|
|
121
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
120
122
|
screenReaderLabel: "some action",
|
|
121
123
|
renderIcon: icon,
|
|
122
124
|
elementRef: elementRef
|
|
123
125
|
}));
|
|
124
|
-
const button =
|
|
126
|
+
const button = _react.screen.getByRole('button');
|
|
125
127
|
expect(elementRef).toHaveBeenCalledWith(button);
|
|
126
128
|
});
|
|
127
129
|
it('should pass the `as` prop', () => {
|
|
128
|
-
const _render = (0,
|
|
130
|
+
const _render = (0, _react.render)(_IconButton5 || (_IconButton5 = (0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
129
131
|
screenReaderLabel: "some action",
|
|
130
132
|
renderIcon: icon,
|
|
131
133
|
as: "li"
|
|
@@ -137,51 +139,51 @@ describe('<IconButton/>', () => {
|
|
|
137
139
|
expect(button.tagName).toBe('LI');
|
|
138
140
|
});
|
|
139
141
|
it('should set the disabled attribute when `interaction` is set to disabled', () => {
|
|
140
|
-
(0,
|
|
142
|
+
(0, _react.render)(_IconButton6 || (_IconButton6 = (0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
141
143
|
screenReaderLabel: "some action",
|
|
142
144
|
renderIcon: icon,
|
|
143
145
|
interaction: "disabled"
|
|
144
146
|
})));
|
|
145
|
-
const button =
|
|
147
|
+
const button = _react.screen.getByRole('button');
|
|
146
148
|
expect(button).toHaveAttribute('disabled');
|
|
147
149
|
});
|
|
148
150
|
it('should set the disabled attribute when `disabled` is set', () => {
|
|
149
|
-
(0,
|
|
151
|
+
(0, _react.render)(_IconButton7 || (_IconButton7 = (0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
150
152
|
screenReaderLabel: "some action",
|
|
151
153
|
renderIcon: icon,
|
|
152
154
|
disabled: true
|
|
153
155
|
})));
|
|
154
|
-
const button =
|
|
156
|
+
const button = _react.screen.getByRole('button');
|
|
155
157
|
expect(button).toHaveAttribute('disabled');
|
|
156
158
|
});
|
|
157
159
|
it('should set the disabled attribute when `interaction` is set to readonly', () => {
|
|
158
|
-
(0,
|
|
160
|
+
(0, _react.render)(_IconButton8 || (_IconButton8 = (0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
159
161
|
screenReaderLabel: "some action",
|
|
160
162
|
renderIcon: icon,
|
|
161
163
|
interaction: "readonly"
|
|
162
164
|
})));
|
|
163
|
-
const button =
|
|
165
|
+
const button = _react.screen.getByRole('button');
|
|
164
166
|
expect(button).toHaveAttribute('disabled');
|
|
165
167
|
});
|
|
166
168
|
it('should set the disabled attribute when `readOnly` is set', () => {
|
|
167
|
-
(0,
|
|
169
|
+
(0, _react.render)(_IconButton9 || (_IconButton9 = (0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
168
170
|
screenReaderLabel: "some action",
|
|
169
171
|
renderIcon: icon,
|
|
170
172
|
readOnly: true
|
|
171
173
|
})));
|
|
172
|
-
const button =
|
|
174
|
+
const button = _react.screen.getByRole('button');
|
|
173
175
|
expect(button).toHaveAttribute('disabled');
|
|
174
176
|
});
|
|
175
177
|
it('should pass the `onClick` prop', async () => {
|
|
176
178
|
const onClick = _vitest.vi.fn();
|
|
177
|
-
(0,
|
|
179
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.IconButton, {
|
|
178
180
|
screenReaderLabel: "some action",
|
|
179
181
|
renderIcon: icon,
|
|
180
182
|
onClick: onClick
|
|
181
183
|
}));
|
|
182
|
-
const button =
|
|
184
|
+
const button = _react.screen.getByRole('button');
|
|
183
185
|
await _userEvent.default.click(button);
|
|
184
|
-
await (0,
|
|
186
|
+
await (0, _react.waitFor)(() => {
|
|
185
187
|
expect(onClick).toHaveBeenCalledTimes(1);
|
|
186
188
|
});
|
|
187
189
|
});
|
package/lib/IconButton/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = exports.IconButton = void 0;
|
|
9
8
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
|
-
var _react =
|
|
9
|
+
var _react = require("react");
|
|
11
10
|
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
12
11
|
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
13
12
|
var _ScreenReaderContent = require("@instructure/ui-a11y-content/lib/ScreenReaderContent");
|
|
@@ -15,6 +14,7 @@ var _emotion = require("@instructure/emotion");
|
|
|
15
14
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
16
15
|
var _BaseButton = require("../BaseButton");
|
|
17
16
|
var _props = require("./props");
|
|
17
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
18
18
|
const _excluded = ["children", "renderIcon", "screenReaderLabel", "type", "size", "elementRef", "as", "interaction", "color", "focusColor", "shape", "withBackground", "withBorder", "margin", "cursor", "href"];
|
|
19
19
|
var _dec, _dec2, _class, _IconButton;
|
|
20
20
|
/*
|
|
@@ -85,7 +85,8 @@ let IconButton = exports.IconButton = (_dec = (0, _emotion.withStyle)(null, _the
|
|
|
85
85
|
href = _this$props.href,
|
|
86
86
|
props = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
|
|
87
87
|
const themeOverride = this.props.themeOverride;
|
|
88
|
-
return
|
|
88
|
+
return (0, _jsxRuntime.jsx)(_BaseButton.BaseButton, {
|
|
89
|
+
...(0, _passthroughProps.passthroughProps)(props),
|
|
89
90
|
type: type,
|
|
90
91
|
size: size,
|
|
91
92
|
elementRef: this.handleRef,
|
|
@@ -103,8 +104,11 @@ let IconButton = exports.IconButton = (_dec = (0, _emotion.withStyle)(null, _the
|
|
|
103
104
|
themeOverride: themeOverride,
|
|
104
105
|
ref: component => {
|
|
105
106
|
this._baseButton = component;
|
|
106
|
-
}
|
|
107
|
-
|
|
107
|
+
},
|
|
108
|
+
children: (0, _jsxRuntime.jsx)(_ScreenReaderContent.ScreenReaderContent, {
|
|
109
|
+
children: screenReaderLabel
|
|
110
|
+
})
|
|
111
|
+
});
|
|
108
112
|
}
|
|
109
113
|
}, _IconButton.displayName = "IconButton", _IconButton.componentId = 'IconButton', _IconButton.propTypes = _props.propTypes, _IconButton.allowedProps = _props.allowedProps, _IconButton.defaultProps = {
|
|
110
114
|
type: 'button',
|