@instructure/ui-buttons 10.16.0 → 10.16.1-pr-snapshot-1744893671793
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 +8 -0
- 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
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.16.1-pr-snapshot-1744893671793](https://github.com/instructure/instructure-ui/compare/v10.16.0...v10.16.1-pr-snapshot-1744893671793) (2025-04-17)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-buttons
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [10.16.0](https://github.com/instructure/instructure-ui/compare/v10.15.2...v10.16.0) (2025-04-11)
|
|
7
15
|
|
|
8
16
|
|
|
@@ -23,13 +23,13 @@ var _BaseButton, _BaseButton2, _BaseButton3, _BaseButton4, _BaseButton5, _svg, _
|
|
|
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 { BaseButton } from '../index';
|
|
32
31
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
32
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
33
33
|
describe('<BaseButton/>', () => {
|
|
34
34
|
let consoleWarningMock;
|
|
35
35
|
let consoleErrorMock;
|
|
@@ -43,21 +43,26 @@ describe('<BaseButton/>', () => {
|
|
|
43
43
|
consoleErrorMock.mockRestore();
|
|
44
44
|
});
|
|
45
45
|
it('should render a button and the children as button text', () => {
|
|
46
|
-
render(_BaseButton || (_BaseButton =
|
|
46
|
+
render(_BaseButton || (_BaseButton = _jsx(BaseButton, {
|
|
47
|
+
children: "Hello World"
|
|
48
|
+
})));
|
|
47
49
|
const button = document.querySelector('button');
|
|
48
50
|
expect(button).toBeInTheDocument();
|
|
49
51
|
expect(button).toHaveTextContent('Hello World');
|
|
50
52
|
});
|
|
51
53
|
it('should not error with a null child', () => {
|
|
52
|
-
render(_BaseButton2 || (_BaseButton2 =
|
|
54
|
+
render(_BaseButton2 || (_BaseButton2 = _jsxs(BaseButton, {
|
|
55
|
+
children: ["Hello World", null]
|
|
56
|
+
})));
|
|
53
57
|
const button = document.querySelector('button');
|
|
54
58
|
expect(button).toBeInTheDocument();
|
|
55
59
|
expect(button).toHaveTextContent('Hello World');
|
|
56
60
|
});
|
|
57
61
|
it('should render a link styled as a button if href is provided', () => {
|
|
58
|
-
render(_BaseButton3 || (_BaseButton3 =
|
|
59
|
-
href: "example.html"
|
|
60
|
-
|
|
62
|
+
render(_BaseButton3 || (_BaseButton3 = _jsx(BaseButton, {
|
|
63
|
+
href: "example.html",
|
|
64
|
+
children: "Hello World"
|
|
65
|
+
})));
|
|
61
66
|
const linkButton = screen.getByRole('link', {
|
|
62
67
|
name: 'Hello World'
|
|
63
68
|
});
|
|
@@ -65,17 +70,19 @@ describe('<BaseButton/>', () => {
|
|
|
65
70
|
expect(linkButton).toHaveAttribute('href', 'example.html');
|
|
66
71
|
});
|
|
67
72
|
it('should render as a link when `to` prop is provided', () => {
|
|
68
|
-
const _render = render(_BaseButton4 || (_BaseButton4 =
|
|
69
|
-
to: "/example"
|
|
70
|
-
|
|
73
|
+
const _render = render(_BaseButton4 || (_BaseButton4 = _jsx(BaseButton, {
|
|
74
|
+
to: "/example",
|
|
75
|
+
children: "Test"
|
|
76
|
+
}))),
|
|
71
77
|
container = _render.container;
|
|
72
78
|
const linkButton = container.querySelector('a');
|
|
73
79
|
expect(linkButton.getAttribute('to')).toBe('/example');
|
|
74
80
|
});
|
|
75
81
|
it('should render designated tag if `as` prop is specified', () => {
|
|
76
|
-
const _render2 = render(_BaseButton5 || (_BaseButton5 =
|
|
77
|
-
as: "span"
|
|
78
|
-
|
|
82
|
+
const _render2 = render(_BaseButton5 || (_BaseButton5 = _jsx(BaseButton, {
|
|
83
|
+
as: "span",
|
|
84
|
+
children: "Hello World"
|
|
85
|
+
}))),
|
|
79
86
|
container = _render2.container;
|
|
80
87
|
const button = container.querySelector('[type="button"]');
|
|
81
88
|
expect(button).toBeInTheDocument();
|
|
@@ -84,10 +91,11 @@ describe('<BaseButton/>', () => {
|
|
|
84
91
|
});
|
|
85
92
|
it('should set role="button"', () => {
|
|
86
93
|
const onClick = vi.fn();
|
|
87
|
-
const _render3 = render(
|
|
94
|
+
const _render3 = render(_jsx(BaseButton, {
|
|
88
95
|
as: "span",
|
|
89
|
-
onClick: onClick
|
|
90
|
-
|
|
96
|
+
onClick: onClick,
|
|
97
|
+
children: "Hello World"
|
|
98
|
+
})),
|
|
91
99
|
container = _render3.container;
|
|
92
100
|
const button = container.querySelector('span[type="button"]');
|
|
93
101
|
expect(button).toBeInTheDocument();
|
|
@@ -95,10 +103,11 @@ describe('<BaseButton/>', () => {
|
|
|
95
103
|
});
|
|
96
104
|
it('should set tabIndex="0"', () => {
|
|
97
105
|
const onClick = vi.fn();
|
|
98
|
-
render(
|
|
106
|
+
render(_jsx(BaseButton, {
|
|
99
107
|
as: "span",
|
|
100
|
-
onClick: onClick
|
|
101
|
-
|
|
108
|
+
onClick: onClick,
|
|
109
|
+
children: "Hello World"
|
|
110
|
+
}));
|
|
102
111
|
const button = screen.getByRole('button', {
|
|
103
112
|
name: 'Hello World'
|
|
104
113
|
});
|
|
@@ -107,13 +116,17 @@ describe('<BaseButton/>', () => {
|
|
|
107
116
|
});
|
|
108
117
|
it('should not set tabIndex="0" when the element has it by default', () => {
|
|
109
118
|
const onClick = vi.fn();
|
|
110
|
-
render(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
render(_jsxs(_Fragment, {
|
|
120
|
+
children: [_jsx(BaseButton, {
|
|
121
|
+
as: "button",
|
|
122
|
+
onClick: onClick,
|
|
123
|
+
children: "Hello Button"
|
|
124
|
+
}), _jsx(BaseButton, {
|
|
125
|
+
onClick: onClick,
|
|
126
|
+
href: "example.html",
|
|
127
|
+
children: "Hello link"
|
|
128
|
+
})]
|
|
129
|
+
}));
|
|
117
130
|
const button = screen.getByRole('button', {
|
|
118
131
|
name: 'Hello Button'
|
|
119
132
|
});
|
|
@@ -127,10 +140,11 @@ describe('<BaseButton/>', () => {
|
|
|
127
140
|
});
|
|
128
141
|
it('should pass down the type prop to the button element', async () => {
|
|
129
142
|
const onClick = vi.fn();
|
|
130
|
-
render(
|
|
143
|
+
render(_jsx(BaseButton, {
|
|
131
144
|
type: "submit",
|
|
132
|
-
onClick: onClick
|
|
133
|
-
|
|
145
|
+
onClick: onClick,
|
|
146
|
+
children: "Hello World"
|
|
147
|
+
}));
|
|
134
148
|
const button = screen.getByRole('button', {
|
|
135
149
|
name: 'Hello World'
|
|
136
150
|
});
|
|
@@ -138,19 +152,24 @@ describe('<BaseButton/>', () => {
|
|
|
138
152
|
expect(button).toHaveAttribute('type', 'submit');
|
|
139
153
|
});
|
|
140
154
|
it('should pass down an icon via the icon property', () => {
|
|
141
|
-
const SomeIcon = () => _svg || (_svg =
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
155
|
+
const SomeIcon = () => _svg || (_svg = _jsx("svg", {
|
|
156
|
+
children: _jsx("circle", {
|
|
157
|
+
cx: "25",
|
|
158
|
+
cy: "75",
|
|
159
|
+
r: "20"
|
|
160
|
+
})
|
|
161
|
+
}));
|
|
162
|
+
render(_jsx(BaseButton, {
|
|
163
|
+
renderIcon: SomeIcon,
|
|
164
|
+
children: "Hello World"
|
|
165
|
+
}));
|
|
149
166
|
const icon = document.querySelector('svg');
|
|
150
167
|
expect(icon).toBeInTheDocument();
|
|
151
168
|
});
|
|
152
169
|
it('focuses with the focus helper', async () => {
|
|
153
|
-
render(_BaseButton6 || (_BaseButton6 =
|
|
170
|
+
render(_BaseButton6 || (_BaseButton6 = _jsx(BaseButton, {
|
|
171
|
+
children: "Hello World"
|
|
172
|
+
})));
|
|
154
173
|
const button = screen.getByRole('button', {
|
|
155
174
|
name: 'Hello World'
|
|
156
175
|
});
|
|
@@ -159,9 +178,10 @@ describe('<BaseButton/>', () => {
|
|
|
159
178
|
});
|
|
160
179
|
it('should provide an elementRef prop', async () => {
|
|
161
180
|
const elementRef = vi.fn();
|
|
162
|
-
render(
|
|
163
|
-
elementRef: elementRef
|
|
164
|
-
|
|
181
|
+
render(_jsx(BaseButton, {
|
|
182
|
+
elementRef: elementRef,
|
|
183
|
+
children: "Hello World"
|
|
184
|
+
}));
|
|
165
185
|
const button = screen.getByRole('button', {
|
|
166
186
|
name: 'Hello World'
|
|
167
187
|
});
|
|
@@ -170,9 +190,10 @@ describe('<BaseButton/>', () => {
|
|
|
170
190
|
describe('onClick', () => {
|
|
171
191
|
it('should call onClick when clicked', async () => {
|
|
172
192
|
const onClick = vi.fn();
|
|
173
|
-
render(
|
|
174
|
-
onClick: onClick
|
|
175
|
-
|
|
193
|
+
render(_jsx(BaseButton, {
|
|
194
|
+
onClick: onClick,
|
|
195
|
+
children: "Hello World"
|
|
196
|
+
}));
|
|
176
197
|
const button = screen.getByRole('button', {
|
|
177
198
|
name: 'Hello World'
|
|
178
199
|
});
|
|
@@ -183,10 +204,11 @@ describe('<BaseButton/>', () => {
|
|
|
183
204
|
});
|
|
184
205
|
it('should not call onClick when interaction is "disabled"', async () => {
|
|
185
206
|
const onClick = vi.fn();
|
|
186
|
-
render(
|
|
207
|
+
render(_jsx(BaseButton, {
|
|
187
208
|
interaction: "disabled",
|
|
188
|
-
onClick: onClick
|
|
189
|
-
|
|
209
|
+
onClick: onClick,
|
|
210
|
+
children: "Hello World"
|
|
211
|
+
}));
|
|
190
212
|
const button = screen.getByRole('button', {
|
|
191
213
|
name: 'Hello World'
|
|
192
214
|
});
|
|
@@ -197,10 +219,11 @@ describe('<BaseButton/>', () => {
|
|
|
197
219
|
});
|
|
198
220
|
it('should not call onClick when disabled is set"', async () => {
|
|
199
221
|
const onClick = vi.fn();
|
|
200
|
-
render(
|
|
222
|
+
render(_jsx(BaseButton, {
|
|
201
223
|
disabled: true,
|
|
202
|
-
onClick: onClick
|
|
203
|
-
|
|
224
|
+
onClick: onClick,
|
|
225
|
+
children: "Hello World"
|
|
226
|
+
}));
|
|
204
227
|
const button = screen.getByRole('button', {
|
|
205
228
|
name: 'Hello World'
|
|
206
229
|
});
|
|
@@ -211,10 +234,11 @@ describe('<BaseButton/>', () => {
|
|
|
211
234
|
});
|
|
212
235
|
it('should not call onClick when interaction is "readonly"', async () => {
|
|
213
236
|
const onClick = vi.fn();
|
|
214
|
-
render(
|
|
237
|
+
render(_jsx(BaseButton, {
|
|
215
238
|
interaction: "readonly",
|
|
216
|
-
onClick: onClick
|
|
217
|
-
|
|
239
|
+
onClick: onClick,
|
|
240
|
+
children: "Hello World"
|
|
241
|
+
}));
|
|
218
242
|
const button = screen.getByRole('button', {
|
|
219
243
|
name: 'Hello World'
|
|
220
244
|
});
|
|
@@ -225,10 +249,11 @@ describe('<BaseButton/>', () => {
|
|
|
225
249
|
});
|
|
226
250
|
it('should not call onClick when readOnly is set', async () => {
|
|
227
251
|
const onClick = vi.fn();
|
|
228
|
-
render(
|
|
252
|
+
render(_jsx(BaseButton, {
|
|
229
253
|
readOnly: true,
|
|
230
|
-
onClick: onClick
|
|
231
|
-
|
|
254
|
+
onClick: onClick,
|
|
255
|
+
children: "Hello World"
|
|
256
|
+
}));
|
|
232
257
|
const button = screen.getByRole('button', {
|
|
233
258
|
name: 'Hello World'
|
|
234
259
|
});
|
|
@@ -239,9 +264,10 @@ describe('<BaseButton/>', () => {
|
|
|
239
264
|
});
|
|
240
265
|
it('should not call onClick when button is disabled and an href prop is provided', async () => {
|
|
241
266
|
const onClick = vi.fn();
|
|
242
|
-
render(_BaseButton7 || (_BaseButton7 =
|
|
243
|
-
href: "#"
|
|
244
|
-
|
|
267
|
+
render(_BaseButton7 || (_BaseButton7 = _jsx(BaseButton, {
|
|
268
|
+
href: "#",
|
|
269
|
+
children: "Hello World"
|
|
270
|
+
})));
|
|
245
271
|
const button = screen.getByRole('link', {
|
|
246
272
|
name: 'Hello World'
|
|
247
273
|
});
|
|
@@ -252,11 +278,12 @@ describe('<BaseButton/>', () => {
|
|
|
252
278
|
});
|
|
253
279
|
it('should not call onClick when interaction is "readonly" and an href prop is provided', async () => {
|
|
254
280
|
const onClick = vi.fn();
|
|
255
|
-
render(
|
|
281
|
+
render(_jsx(BaseButton, {
|
|
256
282
|
interaction: "readonly",
|
|
257
283
|
onClick: onClick,
|
|
258
|
-
href: "#"
|
|
259
|
-
|
|
284
|
+
href: "#",
|
|
285
|
+
children: "Hello World"
|
|
286
|
+
}));
|
|
260
287
|
const button = screen.getByRole('link', {
|
|
261
288
|
name: 'Hello World'
|
|
262
289
|
});
|
|
@@ -267,10 +294,11 @@ describe('<BaseButton/>', () => {
|
|
|
267
294
|
});
|
|
268
295
|
it('should call onClick when space key is pressed if href is provided', async () => {
|
|
269
296
|
const onClick = vi.fn();
|
|
270
|
-
render(
|
|
297
|
+
render(_jsx(BaseButton, {
|
|
271
298
|
onClick: onClick,
|
|
272
|
-
href: "#"
|
|
273
|
-
|
|
299
|
+
href: "#",
|
|
300
|
+
children: "Hello World"
|
|
301
|
+
}));
|
|
274
302
|
const button = screen.getByRole('link', {
|
|
275
303
|
name: 'Hello World'
|
|
276
304
|
});
|
|
@@ -281,10 +309,11 @@ describe('<BaseButton/>', () => {
|
|
|
281
309
|
});
|
|
282
310
|
it('should call onClick when enter key is pressed when not a button or link', async () => {
|
|
283
311
|
const onClick = vi.fn();
|
|
284
|
-
render(
|
|
312
|
+
render(_jsx(BaseButton, {
|
|
285
313
|
as: "span",
|
|
286
|
-
onClick: onClick
|
|
287
|
-
|
|
314
|
+
onClick: onClick,
|
|
315
|
+
children: "Hello World"
|
|
316
|
+
}));
|
|
288
317
|
const button = screen.getByRole('button', {
|
|
289
318
|
name: 'Hello World'
|
|
290
319
|
});
|
|
@@ -295,11 +324,12 @@ describe('<BaseButton/>', () => {
|
|
|
295
324
|
});
|
|
296
325
|
it('should not call onClick when interaction is "disabled" and space key is pressed', async () => {
|
|
297
326
|
const onClick = vi.fn();
|
|
298
|
-
render(
|
|
327
|
+
render(_jsx(BaseButton, {
|
|
299
328
|
interaction: "disabled",
|
|
300
329
|
onClick: onClick,
|
|
301
|
-
href: "#"
|
|
302
|
-
|
|
330
|
+
href: "#",
|
|
331
|
+
children: "Hello World"
|
|
332
|
+
}));
|
|
303
333
|
const button = screen.getByRole('link', {
|
|
304
334
|
name: 'Hello World'
|
|
305
335
|
});
|
|
@@ -310,11 +340,12 @@ describe('<BaseButton/>', () => {
|
|
|
310
340
|
});
|
|
311
341
|
it('should not call onClick when interaction is "readonly" and space key is pressed', async () => {
|
|
312
342
|
const onClick = vi.fn();
|
|
313
|
-
render(
|
|
343
|
+
render(_jsx(BaseButton, {
|
|
314
344
|
interaction: "readonly",
|
|
315
345
|
onClick: onClick,
|
|
316
|
-
href: "#"
|
|
317
|
-
|
|
346
|
+
href: "#",
|
|
347
|
+
children: "Hello World"
|
|
348
|
+
}));
|
|
318
349
|
const button = screen.getByRole('link', {
|
|
319
350
|
name: 'Hello World'
|
|
320
351
|
});
|
|
@@ -326,7 +357,9 @@ describe('<BaseButton/>', () => {
|
|
|
326
357
|
});
|
|
327
358
|
describe('when passing down props to View', () => {
|
|
328
359
|
it("passes cursor='pointer' to View by default", async () => {
|
|
329
|
-
render(_BaseButton8 || (_BaseButton8 =
|
|
360
|
+
render(_BaseButton8 || (_BaseButton8 = _jsx(BaseButton, {
|
|
361
|
+
children: "Hello World"
|
|
362
|
+
})));
|
|
330
363
|
const button = screen.getByRole('button', {
|
|
331
364
|
name: 'Hello World'
|
|
332
365
|
});
|
|
@@ -334,9 +367,10 @@ describe('<BaseButton/>', () => {
|
|
|
334
367
|
expect(style.cursor).toBe('pointer');
|
|
335
368
|
});
|
|
336
369
|
it("passes cursor='not-allowed' to View when disabled", async () => {
|
|
337
|
-
render(_BaseButton9 || (_BaseButton9 =
|
|
338
|
-
interaction: "disabled"
|
|
339
|
-
|
|
370
|
+
render(_BaseButton9 || (_BaseButton9 = _jsx(BaseButton, {
|
|
371
|
+
interaction: "disabled",
|
|
372
|
+
children: "Hello World"
|
|
373
|
+
})));
|
|
340
374
|
const button = screen.getByRole('button', {
|
|
341
375
|
name: 'Hello World'
|
|
342
376
|
});
|
|
@@ -347,9 +381,10 @@ describe('<BaseButton/>', () => {
|
|
|
347
381
|
describe('for a11y', () => {
|
|
348
382
|
it('should meet standards when onClick is given', async () => {
|
|
349
383
|
const onClick = vi.fn();
|
|
350
|
-
render(
|
|
351
|
-
onClick: onClick
|
|
352
|
-
|
|
384
|
+
render(_jsx(BaseButton, {
|
|
385
|
+
onClick: onClick,
|
|
386
|
+
children: "Hello World"
|
|
387
|
+
}));
|
|
353
388
|
const button = screen.getByRole('button', {
|
|
354
389
|
name: 'Hello World'
|
|
355
390
|
});
|
|
@@ -361,9 +396,10 @@ describe('<BaseButton/>', () => {
|
|
|
361
396
|
});
|
|
362
397
|
describe('when disabled', () => {
|
|
363
398
|
it('sets the disabled attribute so that the button is not in tab order', () => {
|
|
364
|
-
render(_BaseButton10 || (_BaseButton10 =
|
|
365
|
-
interaction: "disabled"
|
|
366
|
-
|
|
399
|
+
render(_BaseButton10 || (_BaseButton10 = _jsx(BaseButton, {
|
|
400
|
+
interaction: "disabled",
|
|
401
|
+
children: "Hello World"
|
|
402
|
+
})));
|
|
367
403
|
const button = screen.getByRole('button', {
|
|
368
404
|
name: 'Hello World'
|
|
369
405
|
});
|
|
@@ -372,9 +408,10 @@ describe('<BaseButton/>', () => {
|
|
|
372
408
|
});
|
|
373
409
|
describe('when readonly', () => {
|
|
374
410
|
it('sets the disabled attribute so that the button is not in tab order', async () => {
|
|
375
|
-
render(_BaseButton11 || (_BaseButton11 =
|
|
376
|
-
interaction: "readonly"
|
|
377
|
-
|
|
411
|
+
render(_BaseButton11 || (_BaseButton11 = _jsx(BaseButton, {
|
|
412
|
+
interaction: "readonly",
|
|
413
|
+
children: "Hello World"
|
|
414
|
+
})));
|
|
378
415
|
const button = screen.getByRole('button', {
|
|
379
416
|
name: 'Hello World'
|
|
380
417
|
});
|
package/es/BaseButton/index.js
CHANGED
|
@@ -25,18 +25,18 @@ var _dec, _dec2, _class, _BaseButton;
|
|
|
25
25
|
* SOFTWARE.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
import React, { Component } from 'react';
|
|
28
|
+
import { Component } from 'react';
|
|
30
29
|
import keycode from 'keycode';
|
|
31
30
|
import { testable } from '@instructure/ui-testable';
|
|
32
31
|
import { getElementType, getInteraction, passthroughProps, callRenderProp } from '@instructure/ui-react-utils';
|
|
33
32
|
import { isActiveElement } from '@instructure/ui-dom-utils';
|
|
34
33
|
import { hasVisibleChildren } from '@instructure/ui-a11y-utils';
|
|
35
34
|
import { View } from '@instructure/ui-view';
|
|
36
|
-
import { withStyle
|
|
35
|
+
import { withStyle } from '@instructure/emotion';
|
|
37
36
|
import generateStyles from './styles';
|
|
38
37
|
import generateComponentTheme from './theme';
|
|
39
38
|
import { propTypes, allowedProps } from './props';
|
|
39
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
40
40
|
/**
|
|
41
41
|
---
|
|
42
42
|
category: components/utilities
|
|
@@ -159,28 +159,32 @@ let BaseButton = (_dec = withStyle(generateStyles, generateComponentTheme), _dec
|
|
|
159
159
|
renderIcon = _this$props6.renderIcon,
|
|
160
160
|
children = _this$props6.children,
|
|
161
161
|
styles = _this$props6.styles;
|
|
162
|
-
const wrappedChildren =
|
|
163
|
-
css: styles === null || styles === void 0 ? void 0 : styles.children
|
|
164
|
-
|
|
162
|
+
const wrappedChildren = _jsx("span", {
|
|
163
|
+
css: styles === null || styles === void 0 ? void 0 : styles.children,
|
|
164
|
+
children: children
|
|
165
|
+
});
|
|
165
166
|
if (!renderIcon) {
|
|
166
167
|
return wrappedChildren;
|
|
167
168
|
}
|
|
168
169
|
const hasOnlyIconVisible = this.hasOnlyIconVisible;
|
|
169
|
-
const wrappedIcon =
|
|
170
|
-
css: styles === null || styles === void 0 ? void 0 : styles.iconSVG
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
170
|
+
const wrappedIcon = _jsx("span", {
|
|
171
|
+
css: styles === null || styles === void 0 ? void 0 : styles.iconSVG,
|
|
172
|
+
children: callRenderProp(renderIcon)
|
|
173
|
+
});
|
|
174
|
+
const flexChildren = hasOnlyIconVisible ? _jsxs("span", {
|
|
175
|
+
css: styles === null || styles === void 0 ? void 0 : styles.iconOnly,
|
|
176
|
+
children: [wrappedIcon, children]
|
|
177
|
+
}) : [_jsx("span", {
|
|
178
|
+
css: styles === null || styles === void 0 ? void 0 : styles.iconWrapper,
|
|
179
|
+
children: wrappedIcon
|
|
180
|
+
}, "icon"), _jsx("span", {
|
|
181
|
+
css: styles === null || styles === void 0 ? void 0 : styles.childrenWrapper,
|
|
182
|
+
children: wrappedChildren
|
|
183
|
+
}, "children")];
|
|
184
|
+
return _jsx("span", {
|
|
185
|
+
css: styles === null || styles === void 0 ? void 0 : styles.childrenLayout,
|
|
186
|
+
children: flexChildren
|
|
187
|
+
});
|
|
184
188
|
}
|
|
185
189
|
render() {
|
|
186
190
|
var _styles$content;
|
|
@@ -225,7 +229,8 @@ let BaseButton = (_dec = withStyle(generateStyles, generateComponentTheme), _dec
|
|
|
225
229
|
if (onClick && as && needsZeroTabIndex) {
|
|
226
230
|
tabIndexValue = tabIndex || 0;
|
|
227
231
|
}
|
|
228
|
-
return
|
|
232
|
+
return _jsx(View, {
|
|
233
|
+
...passthroughProps(props),
|
|
229
234
|
as: elementType,
|
|
230
235
|
focusColor: this.focusColor,
|
|
231
236
|
position: "relative",
|
|
@@ -246,10 +251,12 @@ let BaseButton = (_dec = withStyle(generateStyles, generateComponentTheme), _dec
|
|
|
246
251
|
tabIndex: tabIndexValue,
|
|
247
252
|
disabled: isDisabled || isReadOnly,
|
|
248
253
|
css: isEnabled ? styles === null || styles === void 0 ? void 0 : styles.baseButton : null,
|
|
249
|
-
focusRingBorderRadius: String(styles === null || styles === void 0 ? void 0 : (_styles$content = styles.content) === null || _styles$content === void 0 ? void 0 : _styles$content.borderRadius)
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
254
|
+
focusRingBorderRadius: String(styles === null || styles === void 0 ? void 0 : (_styles$content = styles.content) === null || _styles$content === void 0 ? void 0 : _styles$content.borderRadius),
|
|
255
|
+
children: _jsx("span", {
|
|
256
|
+
css: styles === null || styles === void 0 ? void 0 : styles.content,
|
|
257
|
+
children: this.renderChildren()
|
|
258
|
+
})
|
|
259
|
+
});
|
|
253
260
|
}
|
|
254
261
|
}, _BaseButton.displayName = "BaseButton", _BaseButton.componentId = 'BaseButton', _BaseButton.propTypes = propTypes, _BaseButton.allowedProps = allowedProps, _BaseButton.defaultProps = {
|
|
255
262
|
type: 'button',
|