@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
|
@@ -23,30 +23,31 @@ var _circle, _Button, _Button2, _Button3, _Button4, _Button5, _Button6, _Button7
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import React from 'react';
|
|
27
26
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
27
|
import { vi } from 'vitest';
|
|
29
28
|
import userEvent from '@testing-library/user-event';
|
|
30
29
|
import '@testing-library/jest-dom';
|
|
31
30
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
32
31
|
import { Button } from '../index';
|
|
32
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
33
33
|
describe('<Button/>', () => {
|
|
34
34
|
var _Button9;
|
|
35
35
|
let consoleWarningMock;
|
|
36
36
|
let consoleErrorMock;
|
|
37
37
|
const iconSelector = 'svg[data-title="myIcon"]';
|
|
38
|
-
const icon =
|
|
38
|
+
const icon = _jsx("svg", {
|
|
39
39
|
"data-title": "myIcon",
|
|
40
40
|
height: "1em",
|
|
41
41
|
width: "1em",
|
|
42
42
|
style: {
|
|
43
43
|
fill: 'currentcolor'
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
},
|
|
45
|
+
children: _circle || (_circle = _jsx("circle", {
|
|
46
|
+
cx: "0.5em",
|
|
47
|
+
cy: "0.5em",
|
|
48
|
+
r: "0.5em"
|
|
49
|
+
}))
|
|
50
|
+
});
|
|
50
51
|
beforeEach(() => {
|
|
51
52
|
// Mocking console to prevent test output pollution
|
|
52
53
|
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
@@ -58,13 +59,17 @@ describe('<Button/>', () => {
|
|
|
58
59
|
});
|
|
59
60
|
it('should render children', () => {
|
|
60
61
|
const children = 'Hello world';
|
|
61
|
-
render(
|
|
62
|
+
render(_jsx(Button, {
|
|
63
|
+
children: children
|
|
64
|
+
}));
|
|
62
65
|
const button = document.querySelector('button');
|
|
63
66
|
expect(button).toBeInTheDocument();
|
|
64
67
|
expect(button).toHaveTextContent(children);
|
|
65
68
|
});
|
|
66
69
|
it('should render a button', async () => {
|
|
67
|
-
render(_Button || (_Button =
|
|
70
|
+
render(_Button || (_Button = _jsx(Button, {
|
|
71
|
+
children: "Hello World"
|
|
72
|
+
})));
|
|
68
73
|
const button = screen.getByRole('button');
|
|
69
74
|
expect(button).toBeInTheDocument();
|
|
70
75
|
expect(button).toHaveAttribute('type', 'button');
|
|
@@ -73,13 +78,14 @@ describe('<Button/>', () => {
|
|
|
73
78
|
it('should provide a focused getter', () => {
|
|
74
79
|
var _componentRef;
|
|
75
80
|
let componentRef;
|
|
76
|
-
render(
|
|
81
|
+
render(_jsx(Button
|
|
77
82
|
//@ts-expect-error TODO this is coming from ReactComponentWrapper
|
|
78
83
|
, {
|
|
79
84
|
ref: component => {
|
|
80
85
|
componentRef = component;
|
|
81
|
-
}
|
|
82
|
-
|
|
86
|
+
},
|
|
87
|
+
children: "Hello"
|
|
88
|
+
}));
|
|
83
89
|
const button = screen.getByRole('button', {
|
|
84
90
|
name: 'Hello'
|
|
85
91
|
});
|
|
@@ -89,13 +95,14 @@ describe('<Button/>', () => {
|
|
|
89
95
|
it('should provide a focus function', () => {
|
|
90
96
|
var _componentRef2;
|
|
91
97
|
let componentRef;
|
|
92
|
-
render(
|
|
98
|
+
render(_jsx(Button
|
|
93
99
|
//@ts-expect-error TODO this is coming from ReactComponentWrapper
|
|
94
100
|
, {
|
|
95
101
|
ref: component => {
|
|
96
102
|
componentRef = component;
|
|
97
|
-
}
|
|
98
|
-
|
|
103
|
+
},
|
|
104
|
+
children: "Hello"
|
|
105
|
+
}));
|
|
99
106
|
const button = screen.getByRole('button', {
|
|
100
107
|
name: 'Hello'
|
|
101
108
|
});
|
|
@@ -103,9 +110,10 @@ describe('<Button/>', () => {
|
|
|
103
110
|
expect(document.activeElement).toBe(button);
|
|
104
111
|
});
|
|
105
112
|
it('should pass the type attribute', () => {
|
|
106
|
-
render(_Button2 || (_Button2 =
|
|
107
|
-
type: "submit"
|
|
108
|
-
|
|
113
|
+
render(_Button2 || (_Button2 = _jsx(Button, {
|
|
114
|
+
type: "submit",
|
|
115
|
+
children: "Hello"
|
|
116
|
+
})));
|
|
109
117
|
const button = screen.getByRole('button', {
|
|
110
118
|
name: 'Hello'
|
|
111
119
|
});
|
|
@@ -114,18 +122,20 @@ describe('<Button/>', () => {
|
|
|
114
122
|
});
|
|
115
123
|
it('should pass the `elementRef` prop', () => {
|
|
116
124
|
const elementRef = vi.fn();
|
|
117
|
-
render(
|
|
118
|
-
elementRef: elementRef
|
|
119
|
-
|
|
125
|
+
render(_jsx(Button, {
|
|
126
|
+
elementRef: elementRef,
|
|
127
|
+
children: "Hello"
|
|
128
|
+
}));
|
|
120
129
|
const button = screen.getByRole('button', {
|
|
121
130
|
name: 'Hello'
|
|
122
131
|
});
|
|
123
132
|
expect(elementRef).toHaveBeenCalledWith(button);
|
|
124
133
|
});
|
|
125
134
|
it('should pass the `as` prop', () => {
|
|
126
|
-
const _render = render(_Button3 || (_Button3 =
|
|
127
|
-
as: "li"
|
|
128
|
-
|
|
135
|
+
const _render = render(_Button3 || (_Button3 = _jsx(Button, {
|
|
136
|
+
as: "li",
|
|
137
|
+
children: "Hello"
|
|
138
|
+
}))),
|
|
129
139
|
container = _render.container;
|
|
130
140
|
const button = container.querySelector('[type="button"]');
|
|
131
141
|
expect(button).toBeInTheDocument();
|
|
@@ -133,45 +143,50 @@ describe('<Button/>', () => {
|
|
|
133
143
|
expect(button.tagName).toBe('LI');
|
|
134
144
|
});
|
|
135
145
|
it('should set the disabled attribute when `interaction` is set to disabled', () => {
|
|
136
|
-
render(_Button4 || (_Button4 =
|
|
137
|
-
interaction: "disabled"
|
|
138
|
-
|
|
146
|
+
render(_Button4 || (_Button4 = _jsx(Button, {
|
|
147
|
+
interaction: "disabled",
|
|
148
|
+
children: "Hello"
|
|
149
|
+
})));
|
|
139
150
|
const button = screen.getByRole('button', {
|
|
140
151
|
name: 'Hello'
|
|
141
152
|
});
|
|
142
153
|
expect(button).toHaveAttribute('disabled');
|
|
143
154
|
});
|
|
144
155
|
it('should set the disabled attribute when `disabled` is set', () => {
|
|
145
|
-
render(_Button5 || (_Button5 =
|
|
146
|
-
disabled: true
|
|
147
|
-
|
|
156
|
+
render(_Button5 || (_Button5 = _jsx(Button, {
|
|
157
|
+
disabled: true,
|
|
158
|
+
children: "Hello"
|
|
159
|
+
})));
|
|
148
160
|
const button = screen.getByRole('button', {
|
|
149
161
|
name: 'Hello'
|
|
150
162
|
});
|
|
151
163
|
expect(button).toHaveAttribute('disabled');
|
|
152
164
|
});
|
|
153
165
|
it('should set the disabled attribute when `interaction` is set to readonly', () => {
|
|
154
|
-
render(_Button6 || (_Button6 =
|
|
155
|
-
interaction: "readonly"
|
|
156
|
-
|
|
166
|
+
render(_Button6 || (_Button6 = _jsx(Button, {
|
|
167
|
+
interaction: "readonly",
|
|
168
|
+
children: "Hello"
|
|
169
|
+
})));
|
|
157
170
|
const button = screen.getByRole('button', {
|
|
158
171
|
name: 'Hello'
|
|
159
172
|
});
|
|
160
173
|
expect(button).toHaveAttribute('disabled');
|
|
161
174
|
});
|
|
162
175
|
it('should set the disabled attribute when `readOnly` is set', () => {
|
|
163
|
-
render(_Button7 || (_Button7 =
|
|
164
|
-
readOnly: true
|
|
165
|
-
|
|
176
|
+
render(_Button7 || (_Button7 = _jsx(Button, {
|
|
177
|
+
readOnly: true,
|
|
178
|
+
children: "Hello"
|
|
179
|
+
})));
|
|
166
180
|
const button = screen.getByRole('button', {
|
|
167
181
|
name: 'Hello'
|
|
168
182
|
});
|
|
169
183
|
expect(button).toHaveAttribute('disabled');
|
|
170
184
|
});
|
|
171
185
|
it('should pass the `href` prop', () => {
|
|
172
|
-
render(_Button8 || (_Button8 =
|
|
173
|
-
href: "#"
|
|
174
|
-
|
|
186
|
+
render(_Button8 || (_Button8 = _jsx(Button, {
|
|
187
|
+
href: "#",
|
|
188
|
+
children: "Hello"
|
|
189
|
+
})));
|
|
175
190
|
const linkButton = screen.getByRole('link', {
|
|
176
191
|
name: 'Hello'
|
|
177
192
|
});
|
|
@@ -179,9 +194,10 @@ describe('<Button/>', () => {
|
|
|
179
194
|
expect(linkButton).toHaveAttribute('href', '#');
|
|
180
195
|
});
|
|
181
196
|
it('should pass the `renderIcon` prop', () => {
|
|
182
|
-
render(_Button9 || (_Button9 =
|
|
183
|
-
renderIcon: icon
|
|
184
|
-
|
|
197
|
+
render(_Button9 || (_Button9 = _jsx(Button, {
|
|
198
|
+
renderIcon: icon,
|
|
199
|
+
children: "Hello"
|
|
200
|
+
})));
|
|
185
201
|
const svgIcon = document.querySelector(iconSelector);
|
|
186
202
|
const button = screen.getByRole('button', {
|
|
187
203
|
name: 'Hello'
|
|
@@ -191,9 +207,10 @@ describe('<Button/>', () => {
|
|
|
191
207
|
});
|
|
192
208
|
it('should pass the `onClick` prop', async () => {
|
|
193
209
|
const onClick = vi.fn();
|
|
194
|
-
render(
|
|
195
|
-
onClick: onClick
|
|
196
|
-
|
|
210
|
+
render(_jsx(Button, {
|
|
211
|
+
onClick: onClick,
|
|
212
|
+
children: "Hello"
|
|
213
|
+
}));
|
|
197
214
|
const button = screen.getByRole('button', {
|
|
198
215
|
name: 'Hello'
|
|
199
216
|
});
|
|
@@ -203,22 +220,27 @@ describe('<Button/>', () => {
|
|
|
203
220
|
});
|
|
204
221
|
});
|
|
205
222
|
it('should render the children as button text', () => {
|
|
206
|
-
render(_Button10 || (_Button10 =
|
|
223
|
+
render(_Button10 || (_Button10 = _jsx(Button, {
|
|
224
|
+
children: "Hello World"
|
|
225
|
+
})));
|
|
207
226
|
const button = screen.getByRole('button');
|
|
208
227
|
expect(button).toBeInTheDocument();
|
|
209
228
|
expect(button).toHaveTextContent('Hello World');
|
|
210
229
|
});
|
|
211
230
|
it('should not error with a null child', () => {
|
|
212
|
-
render(_Button11 || (_Button11 =
|
|
231
|
+
render(_Button11 || (_Button11 = _jsxs(Button, {
|
|
232
|
+
children: ["Hello World", null]
|
|
233
|
+
})));
|
|
213
234
|
const button = screen.getByRole('button', {
|
|
214
235
|
name: 'Hello World'
|
|
215
236
|
});
|
|
216
237
|
expect(button).toBeInTheDocument();
|
|
217
238
|
});
|
|
218
239
|
it('should render a link styled as a button if href is provided', () => {
|
|
219
|
-
render(_Button12 || (_Button12 =
|
|
220
|
-
href: "example.html"
|
|
221
|
-
|
|
240
|
+
render(_Button12 || (_Button12 = _jsx(Button, {
|
|
241
|
+
href: "example.html",
|
|
242
|
+
children: "Hello World"
|
|
243
|
+
})));
|
|
222
244
|
const button = screen.getAllByRole('link', {
|
|
223
245
|
name: 'Hello World'
|
|
224
246
|
});
|
|
@@ -226,18 +248,20 @@ describe('<Button/>', () => {
|
|
|
226
248
|
expect(button[0]).toHaveAttribute('href', 'example.html');
|
|
227
249
|
});
|
|
228
250
|
it('should render as a link when `to` prop is provided', () => {
|
|
229
|
-
const _render2 = render(_Button13 || (_Button13 =
|
|
230
|
-
to: "/example"
|
|
231
|
-
|
|
251
|
+
const _render2 = render(_Button13 || (_Button13 = _jsx(Button, {
|
|
252
|
+
to: "/example",
|
|
253
|
+
children: "Test"
|
|
254
|
+
}))),
|
|
232
255
|
container = _render2.container;
|
|
233
256
|
const linkButton = container.querySelector('a');
|
|
234
257
|
expect(linkButton).toBeInTheDocument();
|
|
235
258
|
expect(linkButton).toHaveAttribute('to', '/example');
|
|
236
259
|
});
|
|
237
260
|
it('should render designated tag if `as` prop is specified', () => {
|
|
238
|
-
const _render3 = render(_Button14 || (_Button14 =
|
|
239
|
-
as: "span"
|
|
240
|
-
|
|
261
|
+
const _render3 = render(_Button14 || (_Button14 = _jsx(Button, {
|
|
262
|
+
as: "span",
|
|
263
|
+
children: "Hello World"
|
|
264
|
+
}))),
|
|
241
265
|
container = _render3.container;
|
|
242
266
|
const button = container.querySelector('[type="button"]');
|
|
243
267
|
expect(button).toBeInTheDocument();
|
|
@@ -246,10 +270,11 @@ describe('<Button/>', () => {
|
|
|
246
270
|
});
|
|
247
271
|
it('should set role="button"', () => {
|
|
248
272
|
const onClick = vi.fn();
|
|
249
|
-
const _render4 = render(
|
|
273
|
+
const _render4 = render(_jsx(Button, {
|
|
250
274
|
as: "span",
|
|
251
|
-
onClick: onClick
|
|
252
|
-
|
|
275
|
+
onClick: onClick,
|
|
276
|
+
children: "Hello World"
|
|
277
|
+
})),
|
|
253
278
|
container = _render4.container;
|
|
254
279
|
const button = container.querySelector('[type="button"]');
|
|
255
280
|
expect(button).toBeInTheDocument();
|
|
@@ -257,29 +282,32 @@ describe('<Button/>', () => {
|
|
|
257
282
|
});
|
|
258
283
|
it('should set tabIndex="0"', () => {
|
|
259
284
|
const onClick = vi.fn();
|
|
260
|
-
render(
|
|
285
|
+
render(_jsx(Button, {
|
|
261
286
|
as: "span",
|
|
262
|
-
onClick: onClick
|
|
263
|
-
|
|
287
|
+
onClick: onClick,
|
|
288
|
+
children: "Hello World"
|
|
289
|
+
}));
|
|
264
290
|
const button = screen.getByRole('button');
|
|
265
291
|
expect(button).toBeInTheDocument();
|
|
266
292
|
expect(button).toHaveAttribute('tabIndex', '0');
|
|
267
293
|
});
|
|
268
294
|
it('should pass down the type prop to the button element', () => {
|
|
269
295
|
const onClick = vi.fn();
|
|
270
|
-
render(
|
|
296
|
+
render(_jsx(Button, {
|
|
271
297
|
type: "submit",
|
|
272
|
-
onClick: onClick
|
|
273
|
-
|
|
298
|
+
onClick: onClick,
|
|
299
|
+
children: "Hello World"
|
|
300
|
+
}));
|
|
274
301
|
const button = screen.getByRole('button');
|
|
275
302
|
expect(button).toBeInTheDocument();
|
|
276
303
|
expect(button).toHaveAttribute('type', 'submit');
|
|
277
304
|
});
|
|
278
305
|
it('focuses with the focus helper', () => {
|
|
279
306
|
const onFocus = vi.fn();
|
|
280
|
-
render(
|
|
281
|
-
onFocus: onFocus
|
|
282
|
-
|
|
307
|
+
render(_jsx(Button, {
|
|
308
|
+
onFocus: onFocus,
|
|
309
|
+
children: "Hello World"
|
|
310
|
+
}));
|
|
283
311
|
const button = screen.getByRole('button');
|
|
284
312
|
button.focus();
|
|
285
313
|
expect(onFocus).toHaveBeenCalled();
|
|
@@ -288,9 +316,10 @@ describe('<Button/>', () => {
|
|
|
288
316
|
describe('onClick', () => {
|
|
289
317
|
it('should call onClick when clicked', async () => {
|
|
290
318
|
const onClick = vi.fn();
|
|
291
|
-
render(
|
|
292
|
-
onClick: onClick
|
|
293
|
-
|
|
319
|
+
render(_jsx(Button, {
|
|
320
|
+
onClick: onClick,
|
|
321
|
+
children: "Hello World"
|
|
322
|
+
}));
|
|
294
323
|
const button = screen.getByRole('button', {
|
|
295
324
|
name: 'Hello World'
|
|
296
325
|
});
|
|
@@ -301,10 +330,11 @@ describe('<Button/>', () => {
|
|
|
301
330
|
});
|
|
302
331
|
it('should not call onClick when button is disabled', async () => {
|
|
303
332
|
const onClick = vi.fn();
|
|
304
|
-
render(
|
|
333
|
+
render(_jsx(Button, {
|
|
305
334
|
disabled: true,
|
|
306
|
-
onClick: onClick
|
|
307
|
-
|
|
335
|
+
onClick: onClick,
|
|
336
|
+
children: "Hello World"
|
|
337
|
+
}));
|
|
308
338
|
const button = screen.getByRole('button', {
|
|
309
339
|
name: 'Hello World'
|
|
310
340
|
});
|
|
@@ -315,10 +345,11 @@ describe('<Button/>', () => {
|
|
|
315
345
|
});
|
|
316
346
|
it('should not call onClick when button is readOnly', async () => {
|
|
317
347
|
const onClick = vi.fn();
|
|
318
|
-
render(
|
|
348
|
+
render(_jsx(Button, {
|
|
319
349
|
readOnly: true,
|
|
320
|
-
onClick: onClick
|
|
321
|
-
|
|
350
|
+
onClick: onClick,
|
|
351
|
+
children: "Hello World"
|
|
352
|
+
}));
|
|
322
353
|
const button = screen.getByRole('button', {
|
|
323
354
|
name: 'Hello World'
|
|
324
355
|
});
|
|
@@ -329,9 +360,10 @@ describe('<Button/>', () => {
|
|
|
329
360
|
});
|
|
330
361
|
it('should not call onClick when button is disabled and an href prop is provided', async () => {
|
|
331
362
|
const onClick = vi.fn();
|
|
332
|
-
render(_Button15 || (_Button15 =
|
|
333
|
-
href: "#"
|
|
334
|
-
|
|
363
|
+
render(_Button15 || (_Button15 = _jsx(Button, {
|
|
364
|
+
href: "#",
|
|
365
|
+
children: "Hello World"
|
|
366
|
+
})));
|
|
335
367
|
const button = screen.getByRole('link', {
|
|
336
368
|
name: 'Hello World'
|
|
337
369
|
});
|
|
@@ -342,11 +374,12 @@ describe('<Button/>', () => {
|
|
|
342
374
|
});
|
|
343
375
|
it('should not call onClick when button is readOnly and an href prop is provided', async () => {
|
|
344
376
|
const onClick = vi.fn();
|
|
345
|
-
render(
|
|
377
|
+
render(_jsx(Button, {
|
|
346
378
|
readOnly: true,
|
|
347
379
|
onClick: onClick,
|
|
348
|
-
href: "#"
|
|
349
|
-
|
|
380
|
+
href: "#",
|
|
381
|
+
children: "Hello World"
|
|
382
|
+
}));
|
|
350
383
|
const button = screen.getByRole('link', {
|
|
351
384
|
name: 'Hello World'
|
|
352
385
|
});
|
|
@@ -357,10 +390,11 @@ describe('<Button/>', () => {
|
|
|
357
390
|
});
|
|
358
391
|
it('should call onClick when space key is pressed if href is provided', async () => {
|
|
359
392
|
const onClick = vi.fn();
|
|
360
|
-
render(
|
|
393
|
+
render(_jsx(Button, {
|
|
361
394
|
onClick: onClick,
|
|
362
|
-
href: "#"
|
|
363
|
-
|
|
395
|
+
href: "#",
|
|
396
|
+
children: "Hello World"
|
|
397
|
+
}));
|
|
364
398
|
const button = screen.getByRole('link', {
|
|
365
399
|
name: 'Hello World'
|
|
366
400
|
});
|
|
@@ -371,10 +405,11 @@ describe('<Button/>', () => {
|
|
|
371
405
|
});
|
|
372
406
|
it('should call onClick when enter key is pressed when not a button or link', async () => {
|
|
373
407
|
const onClick = vi.fn();
|
|
374
|
-
render(
|
|
408
|
+
render(_jsx(Button, {
|
|
375
409
|
as: "span",
|
|
376
|
-
onClick: onClick
|
|
377
|
-
|
|
410
|
+
onClick: onClick,
|
|
411
|
+
children: "Hello World"
|
|
412
|
+
}));
|
|
378
413
|
const button = screen.getByRole('button', {
|
|
379
414
|
name: 'Hello World'
|
|
380
415
|
});
|
|
@@ -385,11 +420,12 @@ describe('<Button/>', () => {
|
|
|
385
420
|
});
|
|
386
421
|
it('should not call onClick when button is disabled and space key is pressed', async () => {
|
|
387
422
|
const onClick = vi.fn();
|
|
388
|
-
render(
|
|
423
|
+
render(_jsx(Button, {
|
|
389
424
|
disabled: true,
|
|
390
425
|
onClick: onClick,
|
|
391
|
-
href: "#"
|
|
392
|
-
|
|
426
|
+
href: "#",
|
|
427
|
+
children: "Hello World"
|
|
428
|
+
}));
|
|
393
429
|
const button = screen.getByRole('link', {
|
|
394
430
|
name: 'Hello World'
|
|
395
431
|
});
|
|
@@ -400,11 +436,12 @@ describe('<Button/>', () => {
|
|
|
400
436
|
});
|
|
401
437
|
it('should not call onClick when button is readOnly and space key is pressed', async () => {
|
|
402
438
|
const onClick = vi.fn();
|
|
403
|
-
render(
|
|
439
|
+
render(_jsx(Button, {
|
|
404
440
|
readOnly: true,
|
|
405
441
|
onClick: onClick,
|
|
406
|
-
href: "#"
|
|
407
|
-
|
|
442
|
+
href: "#",
|
|
443
|
+
children: "Hello World"
|
|
444
|
+
}));
|
|
408
445
|
const button = screen.getByRole('link', {
|
|
409
446
|
name: 'Hello World'
|
|
410
447
|
});
|
|
@@ -417,9 +454,10 @@ describe('<Button/>', () => {
|
|
|
417
454
|
describe('for a11y', () => {
|
|
418
455
|
it('should meet standards when onClick is given', async () => {
|
|
419
456
|
const onClick = vi.fn();
|
|
420
|
-
render(
|
|
421
|
-
onClick: onClick
|
|
422
|
-
|
|
457
|
+
render(_jsx(Button, {
|
|
458
|
+
onClick: onClick,
|
|
459
|
+
children: "Hello World"
|
|
460
|
+
}));
|
|
423
461
|
const button = screen.getByRole('button', {
|
|
424
462
|
name: 'Hello World'
|
|
425
463
|
});
|
|
@@ -431,9 +469,10 @@ describe('<Button/>', () => {
|
|
|
431
469
|
});
|
|
432
470
|
describe('when disabled', () => {
|
|
433
471
|
it('sets the disabled attribute so that the button is not in tab order', () => {
|
|
434
|
-
render(_Button16 || (_Button16 =
|
|
435
|
-
disabled: true
|
|
436
|
-
|
|
472
|
+
render(_Button16 || (_Button16 = _jsx(Button, {
|
|
473
|
+
disabled: true,
|
|
474
|
+
children: "Hello World"
|
|
475
|
+
})));
|
|
437
476
|
const button = screen.getByRole('button', {
|
|
438
477
|
name: 'Hello World'
|
|
439
478
|
});
|
|
@@ -442,9 +481,10 @@ describe('<Button/>', () => {
|
|
|
442
481
|
});
|
|
443
482
|
describe('when readOnly', () => {
|
|
444
483
|
it('sets the disabled attribute so that the button is not in tab order', () => {
|
|
445
|
-
render(_Button17 || (_Button17 =
|
|
446
|
-
readOnly: true
|
|
447
|
-
|
|
484
|
+
render(_Button17 || (_Button17 = _jsx(Button, {
|
|
485
|
+
readOnly: true,
|
|
486
|
+
children: "Hello World"
|
|
487
|
+
})));
|
|
448
488
|
const button = screen.getByRole('button', {
|
|
449
489
|
name: 'Hello World'
|
|
450
490
|
});
|
package/es/Button/index.js
CHANGED
|
@@ -25,13 +25,14 @@ var _dec, _dec2, _class, _Button;
|
|
|
25
25
|
* SOFTWARE.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
import
|
|
28
|
+
import { Component } from 'react';
|
|
29
29
|
import { testable } from '@instructure/ui-testable';
|
|
30
30
|
import { getInteraction, passthroughProps } from '@instructure/ui-react-utils';
|
|
31
31
|
import { withStyle } from '@instructure/emotion';
|
|
32
32
|
import generateComponentTheme from './theme';
|
|
33
33
|
import { BaseButton } from '../BaseButton';
|
|
34
34
|
import { propTypes, allowedProps } from './props';
|
|
35
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
35
36
|
/**
|
|
36
37
|
---
|
|
37
38
|
category: components
|
|
@@ -99,7 +100,10 @@ let Button = (_dec = withStyle(null, generateComponentTheme), _dec2 = testable()
|
|
|
99
100
|
renderIcon,
|
|
100
101
|
themeOverride
|
|
101
102
|
};
|
|
102
|
-
return
|
|
103
|
+
return _jsx(BaseButton, {
|
|
104
|
+
...buttonProps,
|
|
105
|
+
children: children
|
|
106
|
+
});
|
|
103
107
|
}
|
|
104
108
|
}, _Button.displayName = "Button", _Button.componentId = 'Button', _Button.propTypes = propTypes, _Button.allowedProps = allowedProps, _Button.defaultProps = {
|
|
105
109
|
type: 'button',
|
|
@@ -23,12 +23,12 @@ var _CloseButton;
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import React from 'react';
|
|
27
26
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
27
|
import { vi } from 'vitest';
|
|
29
28
|
import userEvent from '@testing-library/user-event';
|
|
30
29
|
import '@testing-library/jest-dom';
|
|
31
30
|
import { CloseButton } from '../index';
|
|
31
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
32
32
|
describe('<CloseButton />', () => {
|
|
33
33
|
let consoleWarningMock;
|
|
34
34
|
beforeEach(() => {
|
|
@@ -39,7 +39,7 @@ describe('<CloseButton />', () => {
|
|
|
39
39
|
consoleWarningMock.mockRestore();
|
|
40
40
|
});
|
|
41
41
|
it('should render with x icon', async () => {
|
|
42
|
-
render(_CloseButton || (_CloseButton =
|
|
42
|
+
render(_CloseButton || (_CloseButton = _jsx(CloseButton, {
|
|
43
43
|
screenReaderLabel: "Close"
|
|
44
44
|
})));
|
|
45
45
|
const button = screen.getByRole('button');
|
|
@@ -51,7 +51,7 @@ describe('<CloseButton />', () => {
|
|
|
51
51
|
});
|
|
52
52
|
it('should pass the `onClick` prop', async () => {
|
|
53
53
|
const onClick = vi.fn();
|
|
54
|
-
render(
|
|
54
|
+
render(_jsx(CloseButton, {
|
|
55
55
|
onClick: onClick,
|
|
56
56
|
screenReaderLabel: "Hello"
|
|
57
57
|
}));
|
package/es/CloseButton/index.js
CHANGED
|
@@ -25,17 +25,17 @@ var _dec, _dec2, _class, _CloseButton;
|
|
|
25
25
|
* SOFTWARE.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
/** @jsx jsx */
|
|
29
28
|
import { Component } from 'react';
|
|
30
29
|
import { IconXSolid } from '@instructure/ui-icons';
|
|
31
30
|
import { ScreenReaderContent } from '@instructure/ui-a11y-content';
|
|
32
31
|
import { testable } from '@instructure/ui-testable';
|
|
33
32
|
import { getInteraction, passthroughProps } from '@instructure/ui-react-utils';
|
|
34
|
-
import { withStyle
|
|
33
|
+
import { withStyle } from '@instructure/emotion';
|
|
35
34
|
import generateStyle from './styles';
|
|
36
35
|
import generateComponentTheme from './theme';
|
|
37
36
|
import { BaseButton } from '../BaseButton';
|
|
38
37
|
import { propTypes, allowedProps } from './props';
|
|
38
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
39
39
|
/**
|
|
40
40
|
---
|
|
41
41
|
category: components
|
|
@@ -85,25 +85,30 @@ let CloseButton = (_dec = withStyle(generateStyle, generateComponentTheme), _dec
|
|
|
85
85
|
tabIndex = _this$props3.tabIndex,
|
|
86
86
|
styles = _this$props3.styles,
|
|
87
87
|
props = _objectWithoutProperties(_this$props3, _excluded);
|
|
88
|
-
return
|
|
88
|
+
return _jsx("span", {
|
|
89
|
+
...passthroughProps(props),
|
|
89
90
|
css: styles === null || styles === void 0 ? void 0 : styles.closeButton,
|
|
90
|
-
ref: el => this.ref = el
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
91
|
+
ref: el => this.ref = el,
|
|
92
|
+
children: _jsx(BaseButton, {
|
|
93
|
+
renderIcon: IconXSolid,
|
|
94
|
+
elementRef: this.handleRef,
|
|
95
|
+
interaction: this.interaction,
|
|
96
|
+
type: type,
|
|
97
|
+
color: this.color,
|
|
98
|
+
size: size,
|
|
99
|
+
onClick: onClick,
|
|
100
|
+
margin: margin,
|
|
101
|
+
withBorder: false,
|
|
102
|
+
withBackground: false,
|
|
103
|
+
as: as,
|
|
104
|
+
href: href,
|
|
105
|
+
cursor: cursor,
|
|
106
|
+
tabIndex: tabIndex,
|
|
107
|
+
children: _jsx(ScreenReaderContent, {
|
|
108
|
+
children: screenReaderLabel
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
});
|
|
107
112
|
}
|
|
108
113
|
}, _CloseButton.displayName = "CloseButton", _CloseButton.componentId = 'CloseButton', _CloseButton.propTypes = propTypes, _CloseButton.allowedProps = allowedProps, _CloseButton.defaultProps = {
|
|
109
114
|
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|