@instructure/ui-link 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/Link/__new-tests__/Link.test.js +165 -120
- package/es/Link/index.js +13 -10
- package/lib/Link/__new-tests__/Link.test.js +198 -153
- package/lib/Link/index.js +12 -10
- package/package.json +16 -16
- package/src/Link/__new-tests__/Link.test.tsx +5 -5
- package/src/Link/index.tsx +3 -4
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Link/__new-tests__/Link.test.d.ts.map +1 -1
- package/types/Link/index.d.ts +4 -6
- package/types/Link/index.d.ts.map +1 -1
- package/tsconfig.json +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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
|
|
6
|
+
## [10.16.1](https://github.com/instructure/instructure-ui/compare/v10.16.0...v10.16.1) (2025-04-22)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-link
|
|
9
9
|
|
|
@@ -23,18 +23,20 @@ var _Link, _Link2, _Link3, _svg, _TruncateText2, _svg2, _Link4, _Link5, _Link6,
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
/** jsxImportSource @emotion/react */
|
|
27
|
+
import { Component } from 'react';
|
|
27
28
|
import { userEvent } from '@testing-library/user-event';
|
|
28
29
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
29
30
|
import '@testing-library/jest-dom';
|
|
30
|
-
import { vi } from 'vitest';
|
|
31
|
+
import { expect, vi } from 'vitest';
|
|
31
32
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
32
33
|
import { Link } from '../index';
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class TruncateText extends React.Component {
|
|
34
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
35
|
+
class TruncateText extends Component {
|
|
36
36
|
render() {
|
|
37
|
-
return
|
|
37
|
+
return _jsx("span", {
|
|
38
|
+
children: this.props.children
|
|
39
|
+
});
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
TruncateText.displayName = "TruncateText";
|
|
@@ -48,68 +50,82 @@ describe('<Link />', () => {
|
|
|
48
50
|
consoleErrorMock.mockRestore();
|
|
49
51
|
});
|
|
50
52
|
it('should render the children as text content', async () => {
|
|
51
|
-
render(_Link || (_Link =
|
|
52
|
-
href: "https://instructure.design"
|
|
53
|
-
|
|
53
|
+
render(_Link || (_Link = _jsx(Link, {
|
|
54
|
+
href: "https://instructure.design",
|
|
55
|
+
children: "Hello World"
|
|
56
|
+
})));
|
|
54
57
|
const link = screen.getByRole('link');
|
|
55
58
|
expect(link).toHaveTextContent('Hello World');
|
|
56
59
|
});
|
|
57
60
|
it('should render a button', async () => {
|
|
58
61
|
const onClick = vi.fn();
|
|
59
|
-
render(
|
|
60
|
-
onClick: onClick
|
|
61
|
-
|
|
62
|
+
render(_jsx(Link, {
|
|
63
|
+
onClick: onClick,
|
|
64
|
+
children: "Hello World"
|
|
65
|
+
}));
|
|
62
66
|
const button = screen.getByRole('button');
|
|
63
67
|
expect(button).toHaveAttribute('type', 'button');
|
|
64
68
|
});
|
|
65
69
|
it('should meet a11y standards', async () => {
|
|
66
|
-
const _render = render(_Link2 || (_Link2 =
|
|
67
|
-
href: "https://instructure.design"
|
|
68
|
-
|
|
70
|
+
const _render = render(_Link2 || (_Link2 = _jsx(Link, {
|
|
71
|
+
href: "https://instructure.design",
|
|
72
|
+
children: "Hello World"
|
|
73
|
+
}))),
|
|
69
74
|
container = _render.container;
|
|
70
75
|
const axeCheck = await runAxeCheck(container);
|
|
71
76
|
expect(axeCheck).toBe(true);
|
|
72
77
|
});
|
|
73
78
|
it('should focus with the focus helper', async () => {
|
|
74
79
|
let linkRef;
|
|
75
|
-
render(
|
|
80
|
+
render(_jsx(Link, {
|
|
76
81
|
href: "https://instructure.design",
|
|
77
82
|
elementRef: el => {
|
|
78
83
|
linkRef = el;
|
|
79
|
-
}
|
|
80
|
-
|
|
84
|
+
},
|
|
85
|
+
children: "Hello World"
|
|
86
|
+
}));
|
|
81
87
|
const linkElement = screen.getByRole('link');
|
|
82
88
|
linkRef.focus();
|
|
83
89
|
expect(linkElement).toHaveFocus();
|
|
84
90
|
});
|
|
85
91
|
it('should display block when TruncateText is a child', async () => {
|
|
86
|
-
render(_Link3 || (_Link3 =
|
|
87
|
-
href: "example.html"
|
|
88
|
-
|
|
92
|
+
render(_Link3 || (_Link3 = _jsx(Link, {
|
|
93
|
+
href: "example.html",
|
|
94
|
+
children: _jsx(TruncateText, {
|
|
95
|
+
children: "Hello World"
|
|
96
|
+
})
|
|
97
|
+
})));
|
|
89
98
|
const link = screen.getByRole('link');
|
|
90
99
|
expect(link).toHaveStyle('display: block');
|
|
91
100
|
});
|
|
92
101
|
it('should display inline-flex when TruncateText is a child and there is an icon', async () => {
|
|
93
|
-
const customIcon = _svg || (_svg =
|
|
102
|
+
const customIcon = _svg || (_svg = _jsxs("svg", {
|
|
94
103
|
height: "24",
|
|
95
|
-
width: "24"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
width: "24",
|
|
105
|
+
children: [_jsx("title", {
|
|
106
|
+
children: "Custom icon"
|
|
107
|
+
}), _jsx("circle", {
|
|
108
|
+
cx: "50",
|
|
109
|
+
cy: "50",
|
|
110
|
+
r: "40"
|
|
111
|
+
})]
|
|
112
|
+
}));
|
|
113
|
+
render(_jsx(Link, {
|
|
102
114
|
href: "example.html",
|
|
103
|
-
renderIcon: customIcon
|
|
104
|
-
|
|
115
|
+
renderIcon: customIcon,
|
|
116
|
+
children: _TruncateText2 || (_TruncateText2 = _jsx(TruncateText, {
|
|
117
|
+
children: "Hello World"
|
|
118
|
+
}))
|
|
119
|
+
}));
|
|
105
120
|
const link = screen.getByRole('link');
|
|
106
121
|
expect(link).toHaveStyle('display: inline-flex');
|
|
107
122
|
});
|
|
108
123
|
it('should call the onClick prop when clicked', async () => {
|
|
109
124
|
const onClick = vi.fn();
|
|
110
|
-
render(
|
|
111
|
-
onClick: onClick
|
|
112
|
-
|
|
125
|
+
render(_jsx(Link, {
|
|
126
|
+
onClick: onClick,
|
|
127
|
+
children: "Hello World"
|
|
128
|
+
}));
|
|
113
129
|
const link = screen.getByRole('button');
|
|
114
130
|
userEvent.click(link);
|
|
115
131
|
await waitFor(() => {
|
|
@@ -118,30 +134,35 @@ describe('<Link />', () => {
|
|
|
118
134
|
});
|
|
119
135
|
it('should call the onMouseEnter prop when mouseEntered', async () => {
|
|
120
136
|
const onMouseEnter = vi.fn();
|
|
121
|
-
const _render2 = render(
|
|
122
|
-
onMouseEnter: onMouseEnter
|
|
123
|
-
|
|
137
|
+
const _render2 = render(_jsx(Link, {
|
|
138
|
+
onMouseEnter: onMouseEnter,
|
|
139
|
+
children: "Hello World"
|
|
140
|
+
})),
|
|
124
141
|
container = _render2.container;
|
|
125
|
-
const link = container.querySelector('span[class
|
|
142
|
+
const link = container.querySelector('span[class*="-link"]');
|
|
126
143
|
userEvent.hover(link);
|
|
127
144
|
await waitFor(() => {
|
|
128
145
|
expect(onMouseEnter).toHaveBeenCalledTimes(1);
|
|
129
146
|
});
|
|
130
147
|
});
|
|
131
148
|
it('should pass down an icon via the icon property', async () => {
|
|
132
|
-
const customIcon = _svg2 || (_svg2 =
|
|
149
|
+
const customIcon = _svg2 || (_svg2 = _jsxs("svg", {
|
|
133
150
|
"data-testid": "svg",
|
|
134
151
|
height: "100",
|
|
135
|
-
width: "100"
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
152
|
+
width: "100",
|
|
153
|
+
children: [_jsx("title", {
|
|
154
|
+
children: "Custom icon"
|
|
155
|
+
}), _jsx("circle", {
|
|
156
|
+
cx: "50",
|
|
157
|
+
cy: "50",
|
|
158
|
+
r: "40"
|
|
159
|
+
})]
|
|
160
|
+
}));
|
|
161
|
+
render(_jsx(Link, {
|
|
142
162
|
href: "https://instructure.design",
|
|
143
|
-
renderIcon: customIcon
|
|
144
|
-
|
|
163
|
+
renderIcon: customIcon,
|
|
164
|
+
children: "Hello World"
|
|
165
|
+
}));
|
|
145
166
|
const title = screen.getByText('Custom icon');
|
|
146
167
|
const icon = screen.getByTestId('svg');
|
|
147
168
|
expect(title).toBeInTheDocument();
|
|
@@ -149,37 +170,41 @@ describe('<Link />', () => {
|
|
|
149
170
|
});
|
|
150
171
|
describe('when interaction is disabled', () => {
|
|
151
172
|
it('should apply aria-disabled when interaction is disabled', async () => {
|
|
152
|
-
render(_Link4 || (_Link4 =
|
|
173
|
+
render(_Link4 || (_Link4 = _jsx(Link, {
|
|
153
174
|
href: "example.html",
|
|
154
|
-
interaction: "disabled"
|
|
155
|
-
|
|
175
|
+
interaction: "disabled",
|
|
176
|
+
children: "Hello World"
|
|
177
|
+
})));
|
|
156
178
|
const link = screen.getByRole('link');
|
|
157
179
|
expect(link).toHaveAttribute('aria-disabled');
|
|
158
180
|
});
|
|
159
181
|
});
|
|
160
182
|
it('should apply aria-disabled when `disabled` is set', async () => {
|
|
161
|
-
render(_Link5 || (_Link5 =
|
|
183
|
+
render(_Link5 || (_Link5 = _jsx(Link, {
|
|
162
184
|
href: "example.html",
|
|
163
|
-
disabled: true
|
|
164
|
-
|
|
185
|
+
disabled: true,
|
|
186
|
+
children: "Hello World"
|
|
187
|
+
})));
|
|
165
188
|
const link = screen.getByRole('link');
|
|
166
189
|
expect(link).toHaveAttribute('aria-disabled');
|
|
167
190
|
});
|
|
168
191
|
it('should not be clickable when interaction is disabled', async () => {
|
|
169
192
|
const onClick = vi.fn();
|
|
170
|
-
render(
|
|
193
|
+
render(_jsx(Link, {
|
|
171
194
|
onClick: onClick,
|
|
172
|
-
interaction: "disabled"
|
|
173
|
-
|
|
195
|
+
interaction: "disabled",
|
|
196
|
+
children: "Hello World"
|
|
197
|
+
}));
|
|
174
198
|
const button = screen.getByRole('button');
|
|
175
199
|
expect(button).toHaveAttribute('aria-disabled', 'true');
|
|
176
200
|
});
|
|
177
201
|
it('should not be clickable when `disabled` is set', async () => {
|
|
178
202
|
const onClick = vi.fn();
|
|
179
|
-
render(
|
|
203
|
+
render(_jsx(Link, {
|
|
180
204
|
onClick: onClick,
|
|
181
|
-
disabled: true
|
|
182
|
-
|
|
205
|
+
disabled: true,
|
|
206
|
+
children: "Hello World"
|
|
207
|
+
}));
|
|
183
208
|
const button = screen.getByRole('button');
|
|
184
209
|
expect(button).toHaveAttribute('aria-disabled', 'true');
|
|
185
210
|
});
|
|
@@ -188,19 +213,21 @@ describe('with `as` prop', () => {
|
|
|
188
213
|
describe('with `onClick`', () => {
|
|
189
214
|
it('should render designated tag', async () => {
|
|
190
215
|
const onClick = vi.fn();
|
|
191
|
-
render(
|
|
216
|
+
render(_jsx(Link, {
|
|
192
217
|
as: "a",
|
|
193
|
-
onClick: onClick
|
|
194
|
-
|
|
218
|
+
onClick: onClick,
|
|
219
|
+
children: "Hello World"
|
|
220
|
+
}));
|
|
195
221
|
const link = screen.getByText('Hello World');
|
|
196
222
|
expect(link.tagName).toBe('A');
|
|
197
223
|
});
|
|
198
224
|
it('should set role="button"', async () => {
|
|
199
225
|
const onClick = vi.fn();
|
|
200
|
-
render(
|
|
226
|
+
render(_jsx(Link, {
|
|
201
227
|
as: "span",
|
|
202
|
-
onClick: onClick
|
|
203
|
-
|
|
228
|
+
onClick: onClick,
|
|
229
|
+
children: "Hello World"
|
|
230
|
+
}));
|
|
204
231
|
const spanLink = screen.getByRole('button');
|
|
205
232
|
expect(spanLink).toHaveAttribute('role', 'button');
|
|
206
233
|
});
|
|
@@ -208,108 +235,121 @@ describe('with `as` prop', () => {
|
|
|
208
235
|
describe('should not set type="button", unless it is actually a button', () => {
|
|
209
236
|
it('should not set type="button" on other things like <span>s', async () => {
|
|
210
237
|
const onClick = vi.fn();
|
|
211
|
-
render(
|
|
238
|
+
render(_jsx(Link, {
|
|
212
239
|
as: "span",
|
|
213
|
-
onClick: onClick
|
|
214
|
-
|
|
240
|
+
onClick: onClick,
|
|
241
|
+
children: "Hello World"
|
|
242
|
+
}));
|
|
215
243
|
const link = screen.getByText('Hello World');
|
|
216
244
|
expect(link).not.toHaveAttribute('type', 'button');
|
|
217
245
|
});
|
|
218
246
|
it('should set type="button" on <button>s', async () => {
|
|
219
247
|
const onClick = vi.fn();
|
|
220
|
-
render(
|
|
248
|
+
render(_jsx(Link, {
|
|
221
249
|
as: "button",
|
|
222
|
-
onClick: onClick
|
|
223
|
-
|
|
250
|
+
onClick: onClick,
|
|
251
|
+
children: "Hello World"
|
|
252
|
+
}));
|
|
224
253
|
const button = screen.getByText('Hello World');
|
|
225
254
|
expect(button).toHaveAttribute('type', 'button');
|
|
226
255
|
});
|
|
227
256
|
it('should set tabIndex="0"', async () => {
|
|
228
257
|
const onClick = vi.fn();
|
|
229
|
-
render(
|
|
258
|
+
render(_jsx(Link, {
|
|
230
259
|
as: "span",
|
|
231
|
-
onClick: onClick
|
|
232
|
-
|
|
260
|
+
onClick: onClick,
|
|
261
|
+
children: "Hello World"
|
|
262
|
+
}));
|
|
233
263
|
const spanLink = screen.getByText('Hello World');
|
|
234
264
|
expect(spanLink).toHaveAttribute('tabIndex', '0');
|
|
235
265
|
});
|
|
236
266
|
});
|
|
237
267
|
describe('without `onClick`', () => {
|
|
238
268
|
it('should render designated tag', async () => {
|
|
239
|
-
render(_Link6 || (_Link6 =
|
|
240
|
-
as: "a"
|
|
241
|
-
|
|
269
|
+
render(_Link6 || (_Link6 = _jsx(Link, {
|
|
270
|
+
as: "a",
|
|
271
|
+
children: "Hello World"
|
|
272
|
+
})));
|
|
242
273
|
const link = screen.getByText('Hello World');
|
|
243
274
|
expect(link.tagName).toBe('A');
|
|
244
275
|
});
|
|
245
276
|
it('should not set role="button"', async () => {
|
|
246
|
-
render(_Link7 || (_Link7 =
|
|
247
|
-
as: "span"
|
|
248
|
-
|
|
277
|
+
render(_Link7 || (_Link7 = _jsx(Link, {
|
|
278
|
+
as: "span",
|
|
279
|
+
children: "Hello World"
|
|
280
|
+
})));
|
|
249
281
|
const link = screen.getByText('Hello World');
|
|
250
282
|
expect(link).not.toHaveAttribute('role', 'button');
|
|
251
283
|
});
|
|
252
284
|
it('should not set type="button"', async () => {
|
|
253
|
-
render(_Link8 || (_Link8 =
|
|
254
|
-
as: "span"
|
|
255
|
-
|
|
285
|
+
render(_Link8 || (_Link8 = _jsx(Link, {
|
|
286
|
+
as: "span",
|
|
287
|
+
children: "Hello World"
|
|
288
|
+
})));
|
|
256
289
|
const link = screen.getByText('Hello World');
|
|
257
290
|
expect(link).not.toHaveAttribute('type', 'button');
|
|
258
291
|
});
|
|
259
292
|
it('should not set tabIndex="0"', async () => {
|
|
260
|
-
render(_Link9 || (_Link9 =
|
|
261
|
-
as: "span"
|
|
262
|
-
|
|
293
|
+
render(_Link9 || (_Link9 = _jsx(Link, {
|
|
294
|
+
as: "span",
|
|
295
|
+
children: "Hello World"
|
|
296
|
+
})));
|
|
263
297
|
const link = screen.getByText('Hello World');
|
|
264
298
|
expect(link).not.toHaveAttribute('tabIndex', '0');
|
|
265
299
|
});
|
|
266
300
|
});
|
|
267
301
|
describe('when an href is provided', () => {
|
|
268
302
|
it('should render an anchor element', async () => {
|
|
269
|
-
render(_Link10 || (_Link10 =
|
|
270
|
-
href: "example.html"
|
|
271
|
-
|
|
303
|
+
render(_Link10 || (_Link10 = _jsx(Link, {
|
|
304
|
+
href: "example.html",
|
|
305
|
+
children: "Hello World"
|
|
306
|
+
})));
|
|
272
307
|
const link = screen.getByRole('link');
|
|
273
308
|
expect(link.tagName).toBe('A');
|
|
274
309
|
});
|
|
275
310
|
it('should set the href attribute', async () => {
|
|
276
|
-
render(_Link11 || (_Link11 =
|
|
277
|
-
href: "example.html"
|
|
278
|
-
|
|
311
|
+
render(_Link11 || (_Link11 = _jsx(Link, {
|
|
312
|
+
href: "example.html",
|
|
313
|
+
children: "Hello World"
|
|
314
|
+
})));
|
|
279
315
|
const link = screen.getByRole('link');
|
|
280
316
|
expect(link).toHaveAttribute('href', 'example.html');
|
|
281
317
|
});
|
|
282
318
|
it('should not set role="button"', async () => {
|
|
283
|
-
render(_Link12 || (_Link12 =
|
|
284
|
-
href: "example.html"
|
|
285
|
-
|
|
319
|
+
render(_Link12 || (_Link12 = _jsx(Link, {
|
|
320
|
+
href: "example.html",
|
|
321
|
+
children: "Hello World"
|
|
322
|
+
})));
|
|
286
323
|
const link = screen.getByRole('link');
|
|
287
324
|
expect(link).not.toHaveAttribute('role', 'button');
|
|
288
325
|
});
|
|
289
326
|
it('should not set type="button"', async () => {
|
|
290
|
-
render(_Link13 || (_Link13 =
|
|
291
|
-
href: "example.html"
|
|
292
|
-
|
|
327
|
+
render(_Link13 || (_Link13 = _jsx(Link, {
|
|
328
|
+
href: "example.html",
|
|
329
|
+
children: "Hello World"
|
|
330
|
+
})));
|
|
293
331
|
const link = screen.getByRole('link');
|
|
294
332
|
expect(link).not.toHaveAttribute('type', 'button');
|
|
295
333
|
});
|
|
296
334
|
});
|
|
297
335
|
describe('when a `role` is provided', () => {
|
|
298
336
|
it('should set role', async () => {
|
|
299
|
-
render(_Link14 || (_Link14 =
|
|
337
|
+
render(_Link14 || (_Link14 = _jsx(Link, {
|
|
300
338
|
href: "example.html",
|
|
301
|
-
role: "button"
|
|
302
|
-
|
|
339
|
+
role: "button",
|
|
340
|
+
children: "Hello World"
|
|
341
|
+
})));
|
|
303
342
|
const link = screen.getByText('Hello World');
|
|
304
343
|
expect(link).toHaveAttribute('role', 'button');
|
|
305
344
|
});
|
|
306
345
|
it('should not override button role when it is forced by default', async () => {
|
|
307
346
|
const onClick = vi.fn();
|
|
308
|
-
render(
|
|
347
|
+
render(_jsx(Link, {
|
|
309
348
|
role: "link",
|
|
310
349
|
onClick: onClick,
|
|
311
|
-
as: "a"
|
|
312
|
-
|
|
350
|
+
as: "a",
|
|
351
|
+
children: "Hello World"
|
|
352
|
+
}));
|
|
313
353
|
const link = screen.getByText('Hello World');
|
|
314
354
|
expect(link).toHaveAttribute('role', 'button');
|
|
315
355
|
});
|
|
@@ -317,45 +357,50 @@ describe('with `as` prop', () => {
|
|
|
317
357
|
describe('when a `forceButtonRole` is set to false', () => {
|
|
318
358
|
it('should not force button role', async () => {
|
|
319
359
|
const onClick = vi.fn();
|
|
320
|
-
render(
|
|
360
|
+
render(_jsx(Link, {
|
|
321
361
|
onClick: onClick,
|
|
322
362
|
as: "a",
|
|
323
|
-
forceButtonRole: false
|
|
324
|
-
|
|
363
|
+
forceButtonRole: false,
|
|
364
|
+
children: "Hello World"
|
|
365
|
+
}));
|
|
325
366
|
const link = screen.getByText('Hello World');
|
|
326
367
|
expect(link).not.toHaveAttribute('role');
|
|
327
368
|
});
|
|
328
369
|
it('should override button role with `role` prop', async () => {
|
|
329
370
|
const onClick = vi.fn();
|
|
330
|
-
render(
|
|
371
|
+
render(_jsx(Link, {
|
|
331
372
|
role: "link",
|
|
332
373
|
onClick: onClick,
|
|
333
374
|
as: "a",
|
|
334
|
-
forceButtonRole: false
|
|
335
|
-
|
|
375
|
+
forceButtonRole: false,
|
|
376
|
+
children: "Hello World"
|
|
377
|
+
}));
|
|
336
378
|
const link = screen.getByText('Hello World');
|
|
337
379
|
expect(link).toHaveAttribute('role', 'link');
|
|
338
380
|
});
|
|
339
381
|
});
|
|
340
382
|
describe('when a `to` is provided', () => {
|
|
341
383
|
it('should render an anchor element', async () => {
|
|
342
|
-
render(_Link15 || (_Link15 =
|
|
343
|
-
to: "/example"
|
|
344
|
-
|
|
384
|
+
render(_Link15 || (_Link15 = _jsx(Link, {
|
|
385
|
+
to: "/example",
|
|
386
|
+
children: "Hello World"
|
|
387
|
+
})));
|
|
345
388
|
const link = screen.getByText('Hello World');
|
|
346
389
|
expect(link.tagName).toBe('A');
|
|
347
390
|
});
|
|
348
391
|
it('should set the to attribute', async () => {
|
|
349
|
-
render(_Link16 || (_Link16 =
|
|
350
|
-
to: "/example"
|
|
351
|
-
|
|
392
|
+
render(_Link16 || (_Link16 = _jsx(Link, {
|
|
393
|
+
to: "/example",
|
|
394
|
+
children: "Hello World"
|
|
395
|
+
})));
|
|
352
396
|
const link = screen.getByText('Hello World');
|
|
353
397
|
expect(link).toHaveAttribute('to', '/example');
|
|
354
398
|
});
|
|
355
399
|
it('should not set role="button"', async () => {
|
|
356
|
-
render(_Link17 || (_Link17 =
|
|
357
|
-
to: "/example"
|
|
358
|
-
|
|
400
|
+
render(_Link17 || (_Link17 = _jsx(Link, {
|
|
401
|
+
to: "/example",
|
|
402
|
+
children: "Hello World"
|
|
403
|
+
})));
|
|
359
404
|
const link = screen.getByText('Hello World');
|
|
360
405
|
expect(link).not.toHaveAttribute('role', 'button');
|
|
361
406
|
});
|
package/es/Link/index.js
CHANGED
|
@@ -25,18 +25,18 @@ var _dec, _dec2, _class, _Link;
|
|
|
25
25
|
* SOFTWARE.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
import React, { Component } from 'react';
|
|
28
|
+
import { Children, Component } from 'react';
|
|
30
29
|
import { View } from '@instructure/ui-view';
|
|
31
30
|
import { hasVisibleChildren } from '@instructure/ui-a11y-utils';
|
|
32
31
|
import { isActiveElement, findFocusable } from '@instructure/ui-dom-utils';
|
|
33
32
|
import { getElementType, getInteraction, matchComponentTypes, passthroughProps, callRenderProp } from '@instructure/ui-react-utils';
|
|
34
33
|
import { logWarn as warn } from '@instructure/console';
|
|
35
34
|
import { testable } from '@instructure/ui-testable';
|
|
36
|
-
import { withStyle
|
|
35
|
+
import { withStyle } from '@instructure/emotion';
|
|
37
36
|
import generateStyle 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
|
|
@@ -102,7 +102,7 @@ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = tes
|
|
|
102
102
|
}
|
|
103
103
|
get containsTruncateText() {
|
|
104
104
|
let truncateText = false;
|
|
105
|
-
|
|
105
|
+
Children.forEach(this.props.children, child => {
|
|
106
106
|
if (child && matchComponentTypes(child, ['TruncateText'])) {
|
|
107
107
|
truncateText = true;
|
|
108
108
|
}
|
|
@@ -159,9 +159,10 @@ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = tes
|
|
|
159
159
|
warn(
|
|
160
160
|
// if display prop is used, warn about icon or TruncateText
|
|
161
161
|
this.props.display === void 0, '[Link] Using the display property with an icon may cause layout issues.');
|
|
162
|
-
return
|
|
163
|
-
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.icon
|
|
164
|
-
|
|
162
|
+
return _jsx("span", {
|
|
163
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.icon,
|
|
164
|
+
children: callRenderProp(this.props.renderIcon)
|
|
165
|
+
});
|
|
165
166
|
}
|
|
166
167
|
render() {
|
|
167
168
|
var _this$props$styles2;
|
|
@@ -180,7 +181,8 @@ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = tes
|
|
|
180
181
|
const isDisabled = interaction === 'disabled';
|
|
181
182
|
const type = this.element === 'button' || this.element === 'input' ? 'button' : void 0;
|
|
182
183
|
const tabIndex = this.role === 'button' && !isDisabled ? 0 : void 0;
|
|
183
|
-
return
|
|
184
|
+
return _jsxs(View, {
|
|
185
|
+
...passthroughProps(props),
|
|
184
186
|
elementRef: this.handleElementRef,
|
|
185
187
|
as: this.element,
|
|
186
188
|
display: this.display,
|
|
@@ -194,8 +196,9 @@ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = tes
|
|
|
194
196
|
role: this.role,
|
|
195
197
|
type: type,
|
|
196
198
|
tabIndex: tabIndex,
|
|
197
|
-
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.link
|
|
198
|
-
|
|
199
|
+
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.link,
|
|
200
|
+
children: [renderIcon && iconPlacement === 'start' ? this.renderIcon() : null, children, renderIcon && iconPlacement === 'end' ? this.renderIcon() : null]
|
|
201
|
+
});
|
|
199
202
|
}
|
|
200
203
|
}, _Link.displayName = "Link", _Link.componentId = 'Link', _Link.propTypes = propTypes, _Link.allowedProps = allowedProps, _Link.defaultProps = {
|
|
201
204
|
// Leave interaction default undefined so that `disabled` can also be supplied
|