@instructure/ui-link 7.16.0 → 7.19.0

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 CHANGED
@@ -3,6 +3,20 @@
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
+ # [7.19.0](https://github.com/instructure/instructure-ui/compare/v7.18.0...v7.19.0) (2022-06-03)
7
+
8
+ ### Features
9
+
10
+ - **ui-link:** add `role`and `forceButtonRole` prop to Link component ([cd9ce8c](https://github.com/instructure/instructure-ui/commit/cd9ce8c))
11
+
12
+ # [7.18.0](https://github.com/instructure/instructure-ui/compare/v7.17.0...v7.18.0) (2022-03-30)
13
+
14
+ **Note:** Version bump only for package @instructure/ui-link
15
+
16
+ # [7.17.0](https://github.com/instructure/instructure-ui/compare/v7.16.0...v7.17.0) (2022-03-22)
17
+
18
+ **Note:** Version bump only for package @instructure/ui-link
19
+
6
20
  # [7.16.0](https://github.com/instructure/instructure-ui/compare/v7.15.0...v7.16.0) (2022-02-08)
7
21
 
8
22
  **Note:** Version bump only for package @instructure/ui-link
@@ -34,7 +34,9 @@ export default {
34
34
  },
35
35
  getComponentProps: function getComponentProps(props) {
36
36
  return {
37
- href: 'http://instructure.design'
37
+ href: 'http://instructure.design',
38
+ forceButtonRole: false,
39
+ role: void 0
38
40
  };
39
41
  },
40
42
  getExampleProps: function getExampleProps(props) {
package/es/Link/index.js CHANGED
@@ -168,9 +168,8 @@ var Link = (_dec = deprecated('8.0.0', {
168
168
  var classes = (_classes = {}, _defineProperty(_classes, styles.root, true), _defineProperty(_classes, styles['color--link-inverse'], variant === 'inverse' || color === 'link-inverse'), _defineProperty(_classes, styles["iconPlacement--".concat(iconPlacement)], renderIcon && this.hasVisibleChildren), _defineProperty(_classes, styles.truncates, this.containsTruncateText), _defineProperty(_classes, styles["is".concat(isWithinText ? 'Within' : 'Outside', "Text")], true), _classes);
169
169
  var interaction = this.interaction;
170
170
  var isDisabled = interaction === 'disabled';
171
- var role = onClick && this.element !== 'button' ? 'button' : null;
172
171
  var type = this.element === 'button' || this.element === 'input' ? 'button' : null;
173
- var tabIndex = role === 'button' && !isDisabled ? '0' : null;
172
+ var tabIndex = this.role === 'button' && !isDisabled ? '0' : null;
174
173
  return /*#__PURE__*/React.createElement(View, Object.assign({}, passthroughProps(props), {
175
174
  elementRef: this.handleElementRef,
176
175
  as: this.element,
@@ -181,7 +180,7 @@ var Link = (_dec = deprecated('8.0.0', {
181
180
  onFocus: this.handleFocus,
182
181
  onBlur: this.handleBlur,
183
182
  "aria-disabled": isDisabled ? 'true' : null,
184
- role: role,
183
+ role: this.role,
185
184
  type: type,
186
185
  tabIndex: tabIndex,
187
186
  className: classnames(classes)
@@ -248,6 +247,20 @@ var Link = (_dec = deprecated('8.0.0', {
248
247
  get: function get() {
249
248
  return hasVisibleChildren(this.props.children);
250
249
  }
250
+ }, {
251
+ key: "role",
252
+ get: function get() {
253
+ var _this$props3 = this.props,
254
+ role = _this$props3.role,
255
+ forceButtonRole = _this$props3.forceButtonRole,
256
+ onClick = _this$props3.onClick;
257
+
258
+ if (forceButtonRole) {
259
+ return onClick && this.element !== 'button' ? 'button' : role;
260
+ }
261
+
262
+ return role;
263
+ }
251
264
  }]);
252
265
 
253
266
  Link.displayName = "Link";
@@ -278,6 +291,17 @@ var Link = (_dec = deprecated('8.0.0', {
278
291
  */
279
292
  as: PropTypes.elementType,
280
293
 
294
+ /**
295
+ * The ARIA role of the element.
296
+ */
297
+ role: PropTypes.string,
298
+
299
+ /**
300
+ * If the Link has an onClick handler but is not a button element,
301
+ * force ARIA role to be "button".
302
+ */
303
+ forceButtonRole: PropTypes.bool,
304
+
281
305
  /**
282
306
  * Determines if the link is enabled or disabled
283
307
  */
@@ -347,6 +371,8 @@ var Link = (_dec = deprecated('8.0.0', {
347
371
  display: void 0,
348
372
  color: 'link',
349
373
  as: void 0,
374
+ role: void 0,
375
+ forceButtonRole: true,
350
376
  iconPlacement: 'start',
351
377
  isWithinText: true,
352
378
  onClick: void 0,
@@ -42,7 +42,9 @@ var _default = {
42
42
  },
43
43
  getComponentProps: function getComponentProps(props) {
44
44
  return {
45
- href: 'http://instructure.design'
45
+ href: 'http://instructure.design',
46
+ forceButtonRole: false,
47
+ role: void 0
46
48
  };
47
49
  },
48
50
  getExampleProps: function getExampleProps(props) {
package/lib/Link/index.js CHANGED
@@ -183,9 +183,8 @@ var Link = (_dec = (0, _deprecated.deprecated)('8.0.0', {
183
183
  var classes = (_classes = {}, (0, _defineProperty2.default)(_classes, styles.root, true), (0, _defineProperty2.default)(_classes, styles['color--link-inverse'], variant === 'inverse' || color === 'link-inverse'), (0, _defineProperty2.default)(_classes, styles["iconPlacement--".concat(iconPlacement)], renderIcon && this.hasVisibleChildren), (0, _defineProperty2.default)(_classes, styles.truncates, this.containsTruncateText), (0, _defineProperty2.default)(_classes, styles["is".concat(isWithinText ? 'Within' : 'Outside', "Text")], true), _classes);
184
184
  var interaction = this.interaction;
185
185
  var isDisabled = interaction === 'disabled';
186
- var role = onClick && this.element !== 'button' ? 'button' : null;
187
186
  var type = this.element === 'button' || this.element === 'input' ? 'button' : null;
188
- var tabIndex = role === 'button' && !isDisabled ? '0' : null;
187
+ var tabIndex = this.role === 'button' && !isDisabled ? '0' : null;
189
188
  return /*#__PURE__*/_react.default.createElement(_View.View, Object.assign({}, (0, _passthroughProps.passthroughProps)(props), {
190
189
  elementRef: this.handleElementRef,
191
190
  as: this.element,
@@ -196,7 +195,7 @@ var Link = (_dec = (0, _deprecated.deprecated)('8.0.0', {
196
195
  onFocus: this.handleFocus,
197
196
  onBlur: this.handleBlur,
198
197
  "aria-disabled": isDisabled ? 'true' : null,
199
- role: role,
198
+ role: this.role,
200
199
  type: type,
201
200
  tabIndex: tabIndex,
202
201
  className: (0, _classnames.default)(classes)
@@ -261,6 +260,20 @@ var Link = (_dec = (0, _deprecated.deprecated)('8.0.0', {
261
260
  get: function get() {
262
261
  return (0, _hasVisibleChildren.hasVisibleChildren)(this.props.children);
263
262
  }
263
+ }, {
264
+ key: "role",
265
+ get: function get() {
266
+ var _this$props3 = this.props,
267
+ role = _this$props3.role,
268
+ forceButtonRole = _this$props3.forceButtonRole,
269
+ onClick = _this$props3.onClick;
270
+
271
+ if (forceButtonRole) {
272
+ return onClick && this.element !== 'button' ? 'button' : role;
273
+ }
274
+
275
+ return role;
276
+ }
264
277
  }]);
265
278
  Link.displayName = "Link";
266
279
  return Link;
@@ -290,6 +303,17 @@ var Link = (_dec = (0, _deprecated.deprecated)('8.0.0', {
290
303
  */
291
304
  as: _propTypes.default.elementType,
292
305
 
306
+ /**
307
+ * The ARIA role of the element.
308
+ */
309
+ role: _propTypes.default.string,
310
+
311
+ /**
312
+ * If the Link has an onClick handler but is not a button element,
313
+ * force ARIA role to be "button".
314
+ */
315
+ forceButtonRole: _propTypes.default.bool,
316
+
293
317
  /**
294
318
  * Determines if the link is enabled or disabled
295
319
  */
@@ -359,6 +383,8 @@ var Link = (_dec = (0, _deprecated.deprecated)('8.0.0', {
359
383
  display: void 0,
360
384
  color: 'link',
361
385
  as: void 0,
386
+ role: void 0,
387
+ forceButtonRole: true,
362
388
  iconPlacement: 'start',
363
389
  isWithinText: true,
364
390
  onClick: void 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-link",
3
- "version": "7.16.0",
3
+ "version": "7.19.0",
4
4
  "description": "A component for creating links",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "type": "commonjs",
@@ -24,24 +24,24 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.9.2",
27
- "@instructure/console": "^7.16.0",
28
- "@instructure/ui-a11y-utils": "^7.16.0",
29
- "@instructure/ui-color-utils": "^7.16.0",
30
- "@instructure/ui-dom-utils": "^7.16.0",
31
- "@instructure/ui-icons": "^7.16.0",
32
- "@instructure/ui-prop-types": "^7.16.0",
33
- "@instructure/ui-react-utils": "^7.16.0",
34
- "@instructure/ui-testable": "^7.16.0",
35
- "@instructure/ui-themeable": "^7.16.0",
36
- "@instructure/ui-view": "^7.16.0",
27
+ "@instructure/console": "^7.19.0",
28
+ "@instructure/ui-a11y-utils": "^7.19.0",
29
+ "@instructure/ui-color-utils": "^7.19.0",
30
+ "@instructure/ui-dom-utils": "^7.19.0",
31
+ "@instructure/ui-icons": "^7.19.0",
32
+ "@instructure/ui-prop-types": "^7.19.0",
33
+ "@instructure/ui-react-utils": "^7.19.0",
34
+ "@instructure/ui-testable": "^7.19.0",
35
+ "@instructure/ui-themeable": "^7.19.0",
36
+ "@instructure/ui-view": "^7.19.0",
37
37
  "classnames": "^2",
38
38
  "prop-types": "^15"
39
39
  },
40
40
  "devDependencies": {
41
- "@instructure/ui-babel-preset": "^7.16.0",
42
- "@instructure/ui-test-locator": "^7.16.0",
43
- "@instructure/ui-test-queries": "^7.16.0",
44
- "@instructure/ui-test-utils": "^7.16.0"
41
+ "@instructure/ui-babel-preset": "^7.19.0",
42
+ "@instructure/ui-test-locator": "^7.19.0",
43
+ "@instructure/ui-test-queries": "^7.19.0",
44
+ "@instructure/ui-test-utils": "^7.19.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "^16.8"
@@ -37,7 +37,9 @@ export default {
37
37
  },
38
38
  getComponentProps: (props) => {
39
39
  return {
40
- href: 'http://instructure.design'
40
+ href: 'http://instructure.design',
41
+ forceButtonRole: false,
42
+ role: undefined
41
43
  }
42
44
  },
43
45
  getExampleProps: (props) => {
package/src/Link/index.js CHANGED
@@ -77,6 +77,15 @@ class Link extends Component {
77
77
  * The element type to render as (will default to `<a>` if href is provided)
78
78
  */
79
79
  as: PropTypes.elementType,
80
+ /**
81
+ * The ARIA role of the element.
82
+ */
83
+ role: PropTypes.string,
84
+ /**
85
+ * If the Link has an onClick handler but is not a button element,
86
+ * force ARIA role to be "button".
87
+ */
88
+ forceButtonRole: PropTypes.bool,
80
89
  /**
81
90
  * Determines if the link is enabled or disabled
82
91
  */
@@ -144,6 +153,8 @@ class Link extends Component {
144
153
  display: undefined,
145
154
  color: 'link',
146
155
  as: undefined,
156
+ role: undefined,
157
+ forceButtonRole: true,
147
158
  iconPlacement: 'start',
148
159
  isWithinText: true,
149
160
  onClick: undefined,
@@ -239,6 +250,16 @@ class Link extends Component {
239
250
  return hasVisibleChildren(this.props.children)
240
251
  }
241
252
 
253
+ get role() {
254
+ const { role, forceButtonRole, onClick } = this.props
255
+
256
+ if (forceButtonRole) {
257
+ return onClick && this.element !== 'button' ? 'button' : role
258
+ }
259
+
260
+ return role
261
+ }
262
+
242
263
  focus() {
243
264
  this._link && this._link.focus()
244
265
  }
@@ -284,10 +305,11 @@ class Link extends Component {
284
305
  const { interaction } = this
285
306
 
286
307
  const isDisabled = interaction === 'disabled'
287
- const role = onClick && this.element !== 'button' ? 'button' : null
308
+
288
309
  const type =
289
310
  this.element === 'button' || this.element === 'input' ? 'button' : null
290
- const tabIndex = role === 'button' && !isDisabled ? '0' : null
311
+
312
+ const tabIndex = this.role === 'button' && !isDisabled ? '0' : null
291
313
 
292
314
  return (
293
315
  <View
@@ -301,7 +323,7 @@ class Link extends Component {
301
323
  onFocus={this.handleFocus}
302
324
  onBlur={this.handleBlur}
303
325
  aria-disabled={isDisabled ? 'true' : null}
304
- role={role}
326
+ role={this.role}
305
327
  type={type}
306
328
  tabIndex={tabIndex}
307
329
  className={classnames(classes)}
package/types/index.d.ts CHANGED
@@ -33,6 +33,15 @@ export interface LinkProps {
33
33
  * The element type to render as (will default to `<a>` if href is provided)
34
34
  */
35
35
  as?: any;
36
+ /**
37
+ * The ARIA role of the element.
38
+ */
39
+ role?: string;
40
+ /**
41
+ * If the Link has an onClick handler but is not a button element,
42
+ * force ARIA role to be "button".
43
+ */
44
+ forceButtonRole?: boolean;
36
45
  /**
37
46
  * Determines if the link is enabled or disabled
38
47
  */