@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,13 +1,13 @@
|
|
|
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");
|
|
10
9
|
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
10
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
11
11
|
var _BaseButton, _BaseButton2, _BaseButton3, _BaseButton4, _BaseButton5, _svg, _BaseButton6, _BaseButton7, _BaseButton8, _BaseButton9, _BaseButton10, _BaseButton11;
|
|
12
12
|
/*
|
|
13
13
|
* The MIT License (MIT)
|
|
@@ -45,39 +45,46 @@ describe('<BaseButton/>', () => {
|
|
|
45
45
|
consoleErrorMock.mockRestore();
|
|
46
46
|
});
|
|
47
47
|
it('should render a button and the children as button text', () => {
|
|
48
|
-
(0,
|
|
48
|
+
(0, _react.render)(_BaseButton || (_BaseButton = (0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
49
|
+
children: "Hello World"
|
|
50
|
+
})));
|
|
49
51
|
const button = document.querySelector('button');
|
|
50
52
|
expect(button).toBeInTheDocument();
|
|
51
53
|
expect(button).toHaveTextContent('Hello World');
|
|
52
54
|
});
|
|
53
55
|
it('should not error with a null child', () => {
|
|
54
|
-
(0,
|
|
56
|
+
(0, _react.render)(_BaseButton2 || (_BaseButton2 = (0, _jsxRuntime.jsxs)(_index.BaseButton, {
|
|
57
|
+
children: ["Hello World", null]
|
|
58
|
+
})));
|
|
55
59
|
const button = document.querySelector('button');
|
|
56
60
|
expect(button).toBeInTheDocument();
|
|
57
61
|
expect(button).toHaveTextContent('Hello World');
|
|
58
62
|
});
|
|
59
63
|
it('should render a link styled as a button if href is provided', () => {
|
|
60
|
-
(0,
|
|
61
|
-
href: "example.html"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
(0, _react.render)(_BaseButton3 || (_BaseButton3 = (0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
65
|
+
href: "example.html",
|
|
66
|
+
children: "Hello World"
|
|
67
|
+
})));
|
|
68
|
+
const linkButton = _react.screen.getByRole('link', {
|
|
64
69
|
name: 'Hello World'
|
|
65
70
|
});
|
|
66
71
|
expect(linkButton).toBeInTheDocument();
|
|
67
72
|
expect(linkButton).toHaveAttribute('href', 'example.html');
|
|
68
73
|
});
|
|
69
74
|
it('should render as a link when `to` prop is provided', () => {
|
|
70
|
-
const _render = (0,
|
|
71
|
-
to: "/example"
|
|
72
|
-
|
|
75
|
+
const _render = (0, _react.render)(_BaseButton4 || (_BaseButton4 = (0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
76
|
+
to: "/example",
|
|
77
|
+
children: "Test"
|
|
78
|
+
}))),
|
|
73
79
|
container = _render.container;
|
|
74
80
|
const linkButton = container.querySelector('a');
|
|
75
81
|
expect(linkButton.getAttribute('to')).toBe('/example');
|
|
76
82
|
});
|
|
77
83
|
it('should render designated tag if `as` prop is specified', () => {
|
|
78
|
-
const _render2 = (0,
|
|
79
|
-
as: "span"
|
|
80
|
-
|
|
84
|
+
const _render2 = (0, _react.render)(_BaseButton5 || (_BaseButton5 = (0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
85
|
+
as: "span",
|
|
86
|
+
children: "Hello World"
|
|
87
|
+
}))),
|
|
81
88
|
container = _render2.container;
|
|
82
89
|
const button = container.querySelector('[type="button"]');
|
|
83
90
|
expect(button).toBeInTheDocument();
|
|
@@ -86,10 +93,11 @@ describe('<BaseButton/>', () => {
|
|
|
86
93
|
});
|
|
87
94
|
it('should set role="button"', () => {
|
|
88
95
|
const onClick = _vitest.vi.fn();
|
|
89
|
-
const _render3 = (0,
|
|
96
|
+
const _render3 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
90
97
|
as: "span",
|
|
91
|
-
onClick: onClick
|
|
92
|
-
|
|
98
|
+
onClick: onClick,
|
|
99
|
+
children: "Hello World"
|
|
100
|
+
})),
|
|
93
101
|
container = _render3.container;
|
|
94
102
|
const button = container.querySelector('span[type="button"]');
|
|
95
103
|
expect(button).toBeInTheDocument();
|
|
@@ -97,11 +105,12 @@ describe('<BaseButton/>', () => {
|
|
|
97
105
|
});
|
|
98
106
|
it('should set tabIndex="0"', () => {
|
|
99
107
|
const onClick = _vitest.vi.fn();
|
|
100
|
-
(0,
|
|
108
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
101
109
|
as: "span",
|
|
102
|
-
onClick: onClick
|
|
103
|
-
|
|
104
|
-
|
|
110
|
+
onClick: onClick,
|
|
111
|
+
children: "Hello World"
|
|
112
|
+
}));
|
|
113
|
+
const button = _react.screen.getByRole('button', {
|
|
105
114
|
name: 'Hello World'
|
|
106
115
|
});
|
|
107
116
|
expect(button).toBeInTheDocument();
|
|
@@ -109,19 +118,23 @@ describe('<BaseButton/>', () => {
|
|
|
109
118
|
});
|
|
110
119
|
it('should not set tabIndex="0" when the element has it by default', () => {
|
|
111
120
|
const onClick = _vitest.vi.fn();
|
|
112
|
-
(0,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
(0, _react.render)((0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
122
|
+
children: [(0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
123
|
+
as: "button",
|
|
124
|
+
onClick: onClick,
|
|
125
|
+
children: "Hello Button"
|
|
126
|
+
}), (0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
127
|
+
onClick: onClick,
|
|
128
|
+
href: "example.html",
|
|
129
|
+
children: "Hello link"
|
|
130
|
+
})]
|
|
131
|
+
}));
|
|
132
|
+
const button = _react.screen.getByRole('button', {
|
|
120
133
|
name: 'Hello Button'
|
|
121
134
|
});
|
|
122
135
|
expect(button).toBeInTheDocument();
|
|
123
136
|
expect(button).not.toHaveAttribute('tabIndex');
|
|
124
|
-
const link =
|
|
137
|
+
const link = _react.screen.getByRole('link', {
|
|
125
138
|
name: 'Hello link'
|
|
126
139
|
});
|
|
127
140
|
expect(link).toBeInTheDocument();
|
|
@@ -129,31 +142,37 @@ describe('<BaseButton/>', () => {
|
|
|
129
142
|
});
|
|
130
143
|
it('should pass down the type prop to the button element', async () => {
|
|
131
144
|
const onClick = _vitest.vi.fn();
|
|
132
|
-
(0,
|
|
145
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
133
146
|
type: "submit",
|
|
134
|
-
onClick: onClick
|
|
135
|
-
|
|
136
|
-
|
|
147
|
+
onClick: onClick,
|
|
148
|
+
children: "Hello World"
|
|
149
|
+
}));
|
|
150
|
+
const button = _react.screen.getByRole('button', {
|
|
137
151
|
name: 'Hello World'
|
|
138
152
|
});
|
|
139
153
|
expect(button).toBeInTheDocument();
|
|
140
154
|
expect(button).toHaveAttribute('type', 'submit');
|
|
141
155
|
});
|
|
142
156
|
it('should pass down an icon via the icon property', () => {
|
|
143
|
-
const SomeIcon = () => _svg || (_svg =
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
157
|
+
const SomeIcon = () => _svg || (_svg = (0, _jsxRuntime.jsx)("svg", {
|
|
158
|
+
children: (0, _jsxRuntime.jsx)("circle", {
|
|
159
|
+
cx: "25",
|
|
160
|
+
cy: "75",
|
|
161
|
+
r: "20"
|
|
162
|
+
})
|
|
163
|
+
}));
|
|
164
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
165
|
+
renderIcon: SomeIcon,
|
|
166
|
+
children: "Hello World"
|
|
167
|
+
}));
|
|
151
168
|
const icon = document.querySelector('svg');
|
|
152
169
|
expect(icon).toBeInTheDocument();
|
|
153
170
|
});
|
|
154
171
|
it('focuses with the focus helper', async () => {
|
|
155
|
-
(0,
|
|
156
|
-
|
|
172
|
+
(0, _react.render)(_BaseButton6 || (_BaseButton6 = (0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
173
|
+
children: "Hello World"
|
|
174
|
+
})));
|
|
175
|
+
const button = _react.screen.getByRole('button', {
|
|
157
176
|
name: 'Hello World'
|
|
158
177
|
});
|
|
159
178
|
button.focus();
|
|
@@ -161,10 +180,11 @@ describe('<BaseButton/>', () => {
|
|
|
161
180
|
});
|
|
162
181
|
it('should provide an elementRef prop', async () => {
|
|
163
182
|
const elementRef = _vitest.vi.fn();
|
|
164
|
-
(0,
|
|
165
|
-
elementRef: elementRef
|
|
166
|
-
|
|
167
|
-
|
|
183
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
184
|
+
elementRef: elementRef,
|
|
185
|
+
children: "Hello World"
|
|
186
|
+
}));
|
|
187
|
+
const button = _react.screen.getByRole('button', {
|
|
168
188
|
name: 'Hello World'
|
|
169
189
|
});
|
|
170
190
|
expect(elementRef).toBeCalledWith(button);
|
|
@@ -172,174 +192,188 @@ describe('<BaseButton/>', () => {
|
|
|
172
192
|
describe('onClick', () => {
|
|
173
193
|
it('should call onClick when clicked', async () => {
|
|
174
194
|
const onClick = _vitest.vi.fn();
|
|
175
|
-
(0,
|
|
176
|
-
onClick: onClick
|
|
177
|
-
|
|
178
|
-
|
|
195
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
196
|
+
onClick: onClick,
|
|
197
|
+
children: "Hello World"
|
|
198
|
+
}));
|
|
199
|
+
const button = _react.screen.getByRole('button', {
|
|
179
200
|
name: 'Hello World'
|
|
180
201
|
});
|
|
181
202
|
await _userEvent.default.click(button);
|
|
182
|
-
await (0,
|
|
203
|
+
await (0, _react.waitFor)(() => {
|
|
183
204
|
expect(onClick).toHaveBeenCalledTimes(1);
|
|
184
205
|
});
|
|
185
206
|
});
|
|
186
207
|
it('should not call onClick when interaction is "disabled"', async () => {
|
|
187
208
|
const onClick = _vitest.vi.fn();
|
|
188
|
-
(0,
|
|
209
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
189
210
|
interaction: "disabled",
|
|
190
|
-
onClick: onClick
|
|
191
|
-
|
|
192
|
-
|
|
211
|
+
onClick: onClick,
|
|
212
|
+
children: "Hello World"
|
|
213
|
+
}));
|
|
214
|
+
const button = _react.screen.getByRole('button', {
|
|
193
215
|
name: 'Hello World'
|
|
194
216
|
});
|
|
195
217
|
await _userEvent.default.click(button);
|
|
196
|
-
await (0,
|
|
218
|
+
await (0, _react.waitFor)(() => {
|
|
197
219
|
expect(onClick).not.toHaveBeenCalled();
|
|
198
220
|
});
|
|
199
221
|
});
|
|
200
222
|
it('should not call onClick when disabled is set"', async () => {
|
|
201
223
|
const onClick = _vitest.vi.fn();
|
|
202
|
-
(0,
|
|
224
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
203
225
|
disabled: true,
|
|
204
|
-
onClick: onClick
|
|
205
|
-
|
|
206
|
-
|
|
226
|
+
onClick: onClick,
|
|
227
|
+
children: "Hello World"
|
|
228
|
+
}));
|
|
229
|
+
const button = _react.screen.getByRole('button', {
|
|
207
230
|
name: 'Hello World'
|
|
208
231
|
});
|
|
209
232
|
await _userEvent.default.click(button);
|
|
210
|
-
await (0,
|
|
233
|
+
await (0, _react.waitFor)(() => {
|
|
211
234
|
expect(onClick).not.toHaveBeenCalled();
|
|
212
235
|
});
|
|
213
236
|
});
|
|
214
237
|
it('should not call onClick when interaction is "readonly"', async () => {
|
|
215
238
|
const onClick = _vitest.vi.fn();
|
|
216
|
-
(0,
|
|
239
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
217
240
|
interaction: "readonly",
|
|
218
|
-
onClick: onClick
|
|
219
|
-
|
|
220
|
-
|
|
241
|
+
onClick: onClick,
|
|
242
|
+
children: "Hello World"
|
|
243
|
+
}));
|
|
244
|
+
const button = _react.screen.getByRole('button', {
|
|
221
245
|
name: 'Hello World'
|
|
222
246
|
});
|
|
223
247
|
await _userEvent.default.click(button);
|
|
224
|
-
await (0,
|
|
248
|
+
await (0, _react.waitFor)(() => {
|
|
225
249
|
expect(onClick).not.toHaveBeenCalled();
|
|
226
250
|
});
|
|
227
251
|
});
|
|
228
252
|
it('should not call onClick when readOnly is set', async () => {
|
|
229
253
|
const onClick = _vitest.vi.fn();
|
|
230
|
-
(0,
|
|
254
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
231
255
|
readOnly: true,
|
|
232
|
-
onClick: onClick
|
|
233
|
-
|
|
234
|
-
|
|
256
|
+
onClick: onClick,
|
|
257
|
+
children: "Hello World"
|
|
258
|
+
}));
|
|
259
|
+
const button = _react.screen.getByRole('button', {
|
|
235
260
|
name: 'Hello World'
|
|
236
261
|
});
|
|
237
262
|
await _userEvent.default.click(button);
|
|
238
|
-
await (0,
|
|
263
|
+
await (0, _react.waitFor)(() => {
|
|
239
264
|
expect(onClick).not.toHaveBeenCalled();
|
|
240
265
|
});
|
|
241
266
|
});
|
|
242
267
|
it('should not call onClick when button is disabled and an href prop is provided', async () => {
|
|
243
268
|
const onClick = _vitest.vi.fn();
|
|
244
|
-
(0,
|
|
245
|
-
href: "#"
|
|
246
|
-
|
|
247
|
-
|
|
269
|
+
(0, _react.render)(_BaseButton7 || (_BaseButton7 = (0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
270
|
+
href: "#",
|
|
271
|
+
children: "Hello World"
|
|
272
|
+
})));
|
|
273
|
+
const button = _react.screen.getByRole('link', {
|
|
248
274
|
name: 'Hello World'
|
|
249
275
|
});
|
|
250
276
|
await _userEvent.default.click(button);
|
|
251
|
-
await (0,
|
|
277
|
+
await (0, _react.waitFor)(() => {
|
|
252
278
|
expect(onClick).not.toHaveBeenCalled();
|
|
253
279
|
});
|
|
254
280
|
});
|
|
255
281
|
it('should not call onClick when interaction is "readonly" and an href prop is provided', async () => {
|
|
256
282
|
const onClick = _vitest.vi.fn();
|
|
257
|
-
(0,
|
|
283
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
258
284
|
interaction: "readonly",
|
|
259
285
|
onClick: onClick,
|
|
260
|
-
href: "#"
|
|
261
|
-
|
|
262
|
-
|
|
286
|
+
href: "#",
|
|
287
|
+
children: "Hello World"
|
|
288
|
+
}));
|
|
289
|
+
const button = _react.screen.getByRole('link', {
|
|
263
290
|
name: 'Hello World'
|
|
264
291
|
});
|
|
265
292
|
await _userEvent.default.click(button);
|
|
266
|
-
await (0,
|
|
293
|
+
await (0, _react.waitFor)(() => {
|
|
267
294
|
expect(onClick).not.toHaveBeenCalled();
|
|
268
295
|
});
|
|
269
296
|
});
|
|
270
297
|
it('should call onClick when space key is pressed if href is provided', async () => {
|
|
271
298
|
const onClick = _vitest.vi.fn();
|
|
272
|
-
(0,
|
|
299
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
273
300
|
onClick: onClick,
|
|
274
|
-
href: "#"
|
|
275
|
-
|
|
276
|
-
|
|
301
|
+
href: "#",
|
|
302
|
+
children: "Hello World"
|
|
303
|
+
}));
|
|
304
|
+
const button = _react.screen.getByRole('link', {
|
|
277
305
|
name: 'Hello World'
|
|
278
306
|
});
|
|
279
307
|
await _userEvent.default.type(button, '{space}');
|
|
280
|
-
await (0,
|
|
308
|
+
await (0, _react.waitFor)(() => {
|
|
281
309
|
expect(onClick).toHaveBeenCalled();
|
|
282
310
|
});
|
|
283
311
|
});
|
|
284
312
|
it('should call onClick when enter key is pressed when not a button or link', async () => {
|
|
285
313
|
const onClick = _vitest.vi.fn();
|
|
286
|
-
(0,
|
|
314
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
287
315
|
as: "span",
|
|
288
|
-
onClick: onClick
|
|
289
|
-
|
|
290
|
-
|
|
316
|
+
onClick: onClick,
|
|
317
|
+
children: "Hello World"
|
|
318
|
+
}));
|
|
319
|
+
const button = _react.screen.getByRole('button', {
|
|
291
320
|
name: 'Hello World'
|
|
292
321
|
});
|
|
293
322
|
await _userEvent.default.type(button, '{enter}');
|
|
294
|
-
await (0,
|
|
323
|
+
await (0, _react.waitFor)(() => {
|
|
295
324
|
expect(onClick).toHaveBeenCalled();
|
|
296
325
|
});
|
|
297
326
|
});
|
|
298
327
|
it('should not call onClick when interaction is "disabled" and space key is pressed', async () => {
|
|
299
328
|
const onClick = _vitest.vi.fn();
|
|
300
|
-
(0,
|
|
329
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
301
330
|
interaction: "disabled",
|
|
302
331
|
onClick: onClick,
|
|
303
|
-
href: "#"
|
|
304
|
-
|
|
305
|
-
|
|
332
|
+
href: "#",
|
|
333
|
+
children: "Hello World"
|
|
334
|
+
}));
|
|
335
|
+
const button = _react.screen.getByRole('link', {
|
|
306
336
|
name: 'Hello World'
|
|
307
337
|
});
|
|
308
338
|
await _userEvent.default.type(button, '{space}');
|
|
309
|
-
await (0,
|
|
339
|
+
await (0, _react.waitFor)(() => {
|
|
310
340
|
expect(onClick).not.toHaveBeenCalled();
|
|
311
341
|
});
|
|
312
342
|
});
|
|
313
343
|
it('should not call onClick when interaction is "readonly" and space key is pressed', async () => {
|
|
314
344
|
const onClick = _vitest.vi.fn();
|
|
315
|
-
(0,
|
|
345
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
316
346
|
interaction: "readonly",
|
|
317
347
|
onClick: onClick,
|
|
318
|
-
href: "#"
|
|
319
|
-
|
|
320
|
-
|
|
348
|
+
href: "#",
|
|
349
|
+
children: "Hello World"
|
|
350
|
+
}));
|
|
351
|
+
const button = _react.screen.getByRole('link', {
|
|
321
352
|
name: 'Hello World'
|
|
322
353
|
});
|
|
323
354
|
await _userEvent.default.type(button, '{space}');
|
|
324
|
-
await (0,
|
|
355
|
+
await (0, _react.waitFor)(() => {
|
|
325
356
|
expect(onClick).not.toHaveBeenCalled();
|
|
326
357
|
});
|
|
327
358
|
});
|
|
328
359
|
});
|
|
329
360
|
describe('when passing down props to View', () => {
|
|
330
361
|
it("passes cursor='pointer' to View by default", async () => {
|
|
331
|
-
(0,
|
|
332
|
-
|
|
362
|
+
(0, _react.render)(_BaseButton8 || (_BaseButton8 = (0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
363
|
+
children: "Hello World"
|
|
364
|
+
})));
|
|
365
|
+
const button = _react.screen.getByRole('button', {
|
|
333
366
|
name: 'Hello World'
|
|
334
367
|
});
|
|
335
368
|
const style = window.getComputedStyle(button);
|
|
336
369
|
expect(style.cursor).toBe('pointer');
|
|
337
370
|
});
|
|
338
371
|
it("passes cursor='not-allowed' to View when disabled", async () => {
|
|
339
|
-
(0,
|
|
340
|
-
interaction: "disabled"
|
|
341
|
-
|
|
342
|
-
|
|
372
|
+
(0, _react.render)(_BaseButton9 || (_BaseButton9 = (0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
373
|
+
interaction: "disabled",
|
|
374
|
+
children: "Hello World"
|
|
375
|
+
})));
|
|
376
|
+
const button = _react.screen.getByRole('button', {
|
|
343
377
|
name: 'Hello World'
|
|
344
378
|
});
|
|
345
379
|
const style = window.getComputedStyle(button);
|
|
@@ -349,24 +383,26 @@ describe('<BaseButton/>', () => {
|
|
|
349
383
|
describe('for a11y', () => {
|
|
350
384
|
it('should meet standards when onClick is given', async () => {
|
|
351
385
|
const onClick = _vitest.vi.fn();
|
|
352
|
-
(0,
|
|
353
|
-
onClick: onClick
|
|
354
|
-
|
|
355
|
-
|
|
386
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
387
|
+
onClick: onClick,
|
|
388
|
+
children: "Hello World"
|
|
389
|
+
}));
|
|
390
|
+
const button = _react.screen.getByRole('button', {
|
|
356
391
|
name: 'Hello World'
|
|
357
392
|
});
|
|
358
393
|
await _userEvent.default.click(button);
|
|
359
|
-
await (0,
|
|
394
|
+
await (0, _react.waitFor)(async () => {
|
|
360
395
|
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(button);
|
|
361
396
|
expect(axeCheck).toBe(true);
|
|
362
397
|
});
|
|
363
398
|
});
|
|
364
399
|
describe('when disabled', () => {
|
|
365
400
|
it('sets the disabled attribute so that the button is not in tab order', () => {
|
|
366
|
-
(0,
|
|
367
|
-
interaction: "disabled"
|
|
368
|
-
|
|
369
|
-
|
|
401
|
+
(0, _react.render)(_BaseButton10 || (_BaseButton10 = (0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
402
|
+
interaction: "disabled",
|
|
403
|
+
children: "Hello World"
|
|
404
|
+
})));
|
|
405
|
+
const button = _react.screen.getByRole('button', {
|
|
370
406
|
name: 'Hello World'
|
|
371
407
|
});
|
|
372
408
|
expect(button).toHaveAttribute('disabled');
|
|
@@ -374,10 +410,11 @@ describe('<BaseButton/>', () => {
|
|
|
374
410
|
});
|
|
375
411
|
describe('when readonly', () => {
|
|
376
412
|
it('sets the disabled attribute so that the button is not in tab order', async () => {
|
|
377
|
-
(0,
|
|
378
|
-
interaction: "readonly"
|
|
379
|
-
|
|
380
|
-
|
|
413
|
+
(0, _react.render)(_BaseButton11 || (_BaseButton11 = (0, _jsxRuntime.jsx)(_index.BaseButton, {
|
|
414
|
+
interaction: "readonly",
|
|
415
|
+
children: "Hello World"
|
|
416
|
+
})));
|
|
417
|
+
const button = _react.screen.getByRole('button', {
|
|
381
418
|
name: 'Hello World'
|
|
382
419
|
});
|
|
383
420
|
expect(button).toHaveAttribute('disabled');
|
package/lib/BaseButton/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.BaseButton = void 0;
|
|
9
8
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
|
-
var _react =
|
|
9
|
+
var _react = require("react");
|
|
11
10
|
var _keycode = _interopRequireDefault(require("keycode"));
|
|
12
11
|
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
13
12
|
var _getElementType = require("@instructure/ui-react-utils/lib/getElementType.js");
|
|
@@ -21,6 +20,7 @@ var _emotion = require("@instructure/emotion");
|
|
|
21
20
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
22
21
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
23
22
|
var _props = require("./props");
|
|
23
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
24
24
|
const _excluded = ["type", "size", "elementRef", "as", "href", "color", "focusColor", "textAlign", "shape", "display", "withBackground", "withBorder", "isCondensed", "margin", "cursor", "onClick", "renderIcon", "tabIndex", "styles", "makeStyles"];
|
|
25
25
|
var _dec, _dec2, _class, _BaseButton;
|
|
26
26
|
/*
|
|
@@ -46,7 +46,6 @@ var _dec, _dec2, _class, _BaseButton;
|
|
|
46
46
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
47
47
|
* SOFTWARE.
|
|
48
48
|
*/
|
|
49
|
-
/** @jsx jsx */
|
|
50
49
|
/**
|
|
51
50
|
---
|
|
52
51
|
category: components/utilities
|
|
@@ -169,28 +168,32 @@ let BaseButton = exports.BaseButton = (_dec = (0, _emotion.withStyle)(_styles.de
|
|
|
169
168
|
renderIcon = _this$props6.renderIcon,
|
|
170
169
|
children = _this$props6.children,
|
|
171
170
|
styles = _this$props6.styles;
|
|
172
|
-
const wrappedChildren = (0,
|
|
173
|
-
css: styles === null || styles === void 0 ? void 0 : styles.children
|
|
174
|
-
|
|
171
|
+
const wrappedChildren = (0, _jsxRuntime.jsx)("span", {
|
|
172
|
+
css: styles === null || styles === void 0 ? void 0 : styles.children,
|
|
173
|
+
children: children
|
|
174
|
+
});
|
|
175
175
|
if (!renderIcon) {
|
|
176
176
|
return wrappedChildren;
|
|
177
177
|
}
|
|
178
178
|
const hasOnlyIconVisible = this.hasOnlyIconVisible;
|
|
179
|
-
const wrappedIcon = (0,
|
|
180
|
-
css: styles === null || styles === void 0 ? void 0 : styles.iconSVG
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
179
|
+
const wrappedIcon = (0, _jsxRuntime.jsx)("span", {
|
|
180
|
+
css: styles === null || styles === void 0 ? void 0 : styles.iconSVG,
|
|
181
|
+
children: (0, _callRenderProp.callRenderProp)(renderIcon)
|
|
182
|
+
});
|
|
183
|
+
const flexChildren = hasOnlyIconVisible ? (0, _jsxRuntime.jsxs)("span", {
|
|
184
|
+
css: styles === null || styles === void 0 ? void 0 : styles.iconOnly,
|
|
185
|
+
children: [wrappedIcon, children]
|
|
186
|
+
}) : [(0, _jsxRuntime.jsx)("span", {
|
|
187
|
+
css: styles === null || styles === void 0 ? void 0 : styles.iconWrapper,
|
|
188
|
+
children: wrappedIcon
|
|
189
|
+
}, "icon"), (0, _jsxRuntime.jsx)("span", {
|
|
190
|
+
css: styles === null || styles === void 0 ? void 0 : styles.childrenWrapper,
|
|
191
|
+
children: wrappedChildren
|
|
192
|
+
}, "children")];
|
|
193
|
+
return (0, _jsxRuntime.jsx)("span", {
|
|
194
|
+
css: styles === null || styles === void 0 ? void 0 : styles.childrenLayout,
|
|
195
|
+
children: flexChildren
|
|
196
|
+
});
|
|
194
197
|
}
|
|
195
198
|
render() {
|
|
196
199
|
var _styles$content;
|
|
@@ -235,7 +238,8 @@ let BaseButton = exports.BaseButton = (_dec = (0, _emotion.withStyle)(_styles.de
|
|
|
235
238
|
if (onClick && as && needsZeroTabIndex) {
|
|
236
239
|
tabIndexValue = tabIndex || 0;
|
|
237
240
|
}
|
|
238
|
-
return (0,
|
|
241
|
+
return (0, _jsxRuntime.jsx)(_View.View, {
|
|
242
|
+
...(0, _passthroughProps.passthroughProps)(props),
|
|
239
243
|
as: elementType,
|
|
240
244
|
focusColor: this.focusColor,
|
|
241
245
|
position: "relative",
|
|
@@ -256,10 +260,12 @@ let BaseButton = exports.BaseButton = (_dec = (0, _emotion.withStyle)(_styles.de
|
|
|
256
260
|
tabIndex: tabIndexValue,
|
|
257
261
|
disabled: isDisabled || isReadOnly,
|
|
258
262
|
css: isEnabled ? styles === null || styles === void 0 ? void 0 : styles.baseButton : null,
|
|
259
|
-
focusRingBorderRadius: String(styles === null || styles === void 0 ? void 0 : (_styles$content = styles.content) === null || _styles$content === void 0 ? void 0 : _styles$content.borderRadius)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
+
focusRingBorderRadius: String(styles === null || styles === void 0 ? void 0 : (_styles$content = styles.content) === null || _styles$content === void 0 ? void 0 : _styles$content.borderRadius),
|
|
264
|
+
children: (0, _jsxRuntime.jsx)("span", {
|
|
265
|
+
css: styles === null || styles === void 0 ? void 0 : styles.content,
|
|
266
|
+
children: this.renderChildren()
|
|
267
|
+
})
|
|
268
|
+
});
|
|
263
269
|
}
|
|
264
270
|
}, _BaseButton.displayName = "BaseButton", _BaseButton.componentId = 'BaseButton', _BaseButton.propTypes = _props.propTypes, _BaseButton.allowedProps = _props.allowedProps, _BaseButton.defaultProps = {
|
|
265
271
|
type: 'button',
|