@instructure/ui-link 8.23.1-snapshot.8 → 8.24.1-snapshot.16

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,12 @@
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
+ # [8.24.0](https://github.com/instructure/instructure-ui/compare/v8.23.0...v8.24.0) (2022-04-26)
7
+
8
+ ### Features
9
+
10
+ - **ui-link:** add `role` and `forceButtonRole` prop to Link component ([11828d0](https://github.com/instructure/instructure-ui/commit/11828d0b32844a522d267e189c8bc52aa928843a))
11
+
6
12
  # [8.23.0](https://github.com/instructure/instructure-ui/compare/v8.22.0...v8.23.0) (2022-04-07)
7
13
 
8
14
  **Note:** Version bump only for package @instructure/ui-link
@@ -33,7 +33,9 @@ export default {
33
33
  },
34
34
  getComponentProps: () => {
35
35
  return {
36
- href: 'http://instructure.design'
36
+ href: 'http://instructure.design',
37
+ forceButtonRole: false,
38
+ role: void 0
37
39
  };
38
40
  },
39
41
  getExampleProps: props => {
package/es/Link/index.js CHANGED
@@ -168,6 +168,19 @@ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = tes
168
168
  return hasVisibleChildren(this.props.children);
169
169
  }
170
170
 
171
+ get role() {
172
+ const _this$props3 = this.props,
173
+ role = _this$props3.role,
174
+ forceButtonRole = _this$props3.forceButtonRole,
175
+ onClick = _this$props3.onClick;
176
+
177
+ if (forceButtonRole) {
178
+ return onClick && this.element !== 'button' ? 'button' : role;
179
+ }
180
+
181
+ return role;
182
+ }
183
+
171
184
  focus() {
172
185
  this.ref && this.ref.focus();
173
186
  }
@@ -185,22 +198,21 @@ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = tes
185
198
  render() {
186
199
  var _this$props$styles2;
187
200
 
188
- const _this$props3 = this.props,
189
- children = _this$props3.children,
190
- onClick = _this$props3.onClick,
191
- color = _this$props3.color,
192
- href = _this$props3.href,
193
- margin = _this$props3.margin,
194
- renderIcon = _this$props3.renderIcon,
195
- iconPlacement = _this$props3.iconPlacement,
196
- isWithinText = _this$props3.isWithinText,
197
- props = _objectWithoutProperties(_this$props3, _excluded);
201
+ const _this$props4 = this.props,
202
+ children = _this$props4.children,
203
+ onClick = _this$props4.onClick,
204
+ color = _this$props4.color,
205
+ href = _this$props4.href,
206
+ margin = _this$props4.margin,
207
+ renderIcon = _this$props4.renderIcon,
208
+ iconPlacement = _this$props4.iconPlacement,
209
+ isWithinText = _this$props4.isWithinText,
210
+ props = _objectWithoutProperties(_this$props4, _excluded);
198
211
 
199
212
  const interaction = this.interaction;
200
213
  const isDisabled = interaction === 'disabled';
201
- const role = onClick && this.element !== 'button' ? 'button' : void 0;
202
214
  const type = this.element === 'button' || this.element === 'input' ? 'button' : void 0;
203
- const tabIndex = role === 'button' && !isDisabled ? 0 : void 0;
215
+ const tabIndex = this.role === 'button' && !isDisabled ? 0 : void 0;
204
216
  return jsx(View, Object.assign({}, passthroughProps(props), {
205
217
  elementRef: this.handleElementRef,
206
218
  as: this.element,
@@ -211,7 +223,7 @@ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = tes
211
223
  onFocus: this.handleFocus,
212
224
  onBlur: this.handleBlur,
213
225
  "aria-disabled": isDisabled ? 'true' : void 0,
214
- role: role,
226
+ role: this.role,
215
227
  type: type,
216
228
  tabIndex: tabIndex,
217
229
  css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.link
@@ -223,7 +235,8 @@ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = tes
223
235
  interaction: void 0,
224
236
  color: 'link',
225
237
  iconPlacement: 'start',
226
- isWithinText: true
238
+ isWithinText: true,
239
+ forceButtonRole: true
227
240
  }, _class2)) || _class) || _class);
228
241
  export default Link;
229
242
  export { Link };
package/es/Link/props.js CHANGED
@@ -29,6 +29,8 @@ const propTypes = {
29
29
  color: PropTypes.oneOf(['link', 'link-inverse']),
30
30
  elementRef: PropTypes.func,
31
31
  as: PropTypes.elementType,
32
+ role: PropTypes.string,
33
+ forceButtonRole: PropTypes.bool,
32
34
  interaction: PropTypes.oneOf(['enabled', 'disabled']),
33
35
  margin: ThemeablePropTypes.spacing,
34
36
  renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
@@ -39,5 +41,5 @@ const propTypes = {
39
41
  onFocus: PropTypes.func,
40
42
  onBlur: PropTypes.func
41
43
  };
42
- const allowedProps = ['children', 'href', 'color', 'elementRef', 'as', 'interaction', 'margin', 'renderIcon', 'iconPlacement', 'display', 'isWithinText', 'onClick', 'onFocus', 'onBlur'];
44
+ const allowedProps = ['children', 'href', 'color', 'elementRef', 'as', 'role', 'forceButtonRole', 'interaction', 'margin', 'renderIcon', 'iconPlacement', 'display', 'isWithinText', 'onClick', 'onFocus', 'onBlur'];
43
45
  export { propTypes, allowedProps };
@@ -41,7 +41,9 @@ var _default = {
41
41
  },
42
42
  getComponentProps: () => {
43
43
  return {
44
- href: 'http://instructure.design'
44
+ href: 'http://instructure.design',
45
+ forceButtonRole: false,
46
+ role: void 0
45
47
  };
46
48
  },
47
49
  getExampleProps: props => {
package/lib/Link/index.js CHANGED
@@ -177,6 +177,19 @@ let Link = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _de
177
177
  return (0, _hasVisibleChildren.hasVisibleChildren)(this.props.children);
178
178
  }
179
179
 
180
+ get role() {
181
+ const _this$props3 = this.props,
182
+ role = _this$props3.role,
183
+ forceButtonRole = _this$props3.forceButtonRole,
184
+ onClick = _this$props3.onClick;
185
+
186
+ if (forceButtonRole) {
187
+ return onClick && this.element !== 'button' ? 'button' : role;
188
+ }
189
+
190
+ return role;
191
+ }
192
+
180
193
  focus() {
181
194
  this.ref && this.ref.focus();
182
195
  }
@@ -194,21 +207,20 @@ let Link = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _de
194
207
  render() {
195
208
  var _this$props$styles2;
196
209
 
197
- const _this$props3 = this.props,
198
- children = _this$props3.children,
199
- onClick = _this$props3.onClick,
200
- color = _this$props3.color,
201
- href = _this$props3.href,
202
- margin = _this$props3.margin,
203
- renderIcon = _this$props3.renderIcon,
204
- iconPlacement = _this$props3.iconPlacement,
205
- isWithinText = _this$props3.isWithinText,
206
- props = (0, _objectWithoutProperties2.default)(_this$props3, _excluded);
210
+ const _this$props4 = this.props,
211
+ children = _this$props4.children,
212
+ onClick = _this$props4.onClick,
213
+ color = _this$props4.color,
214
+ href = _this$props4.href,
215
+ margin = _this$props4.margin,
216
+ renderIcon = _this$props4.renderIcon,
217
+ iconPlacement = _this$props4.iconPlacement,
218
+ isWithinText = _this$props4.isWithinText,
219
+ props = (0, _objectWithoutProperties2.default)(_this$props4, _excluded);
207
220
  const interaction = this.interaction;
208
221
  const isDisabled = interaction === 'disabled';
209
- const role = onClick && this.element !== 'button' ? 'button' : void 0;
210
222
  const type = this.element === 'button' || this.element === 'input' ? 'button' : void 0;
211
- const tabIndex = role === 'button' && !isDisabled ? 0 : void 0;
223
+ const tabIndex = this.role === 'button' && !isDisabled ? 0 : void 0;
212
224
  return (0, _emotion.jsx)(_View.View, Object.assign({}, (0, _passthroughProps.passthroughProps)(props), {
213
225
  elementRef: this.handleElementRef,
214
226
  as: this.element,
@@ -219,7 +231,7 @@ let Link = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _de
219
231
  onFocus: this.handleFocus,
220
232
  onBlur: this.handleBlur,
221
233
  "aria-disabled": isDisabled ? 'true' : void 0,
222
- role: role,
234
+ role: this.role,
223
235
  type: type,
224
236
  tabIndex: tabIndex,
225
237
  css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.link
@@ -231,7 +243,8 @@ let Link = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _de
231
243
  interaction: void 0,
232
244
  color: 'link',
233
245
  iconPlacement: 'start',
234
- isWithinText: true
246
+ isWithinText: true,
247
+ forceButtonRole: true
235
248
  }, _class2)) || _class) || _class);
236
249
  exports.Link = Link;
237
250
  var _default = Link;
package/lib/Link/props.js CHANGED
@@ -40,6 +40,8 @@ const propTypes = {
40
40
  color: _propTypes.default.oneOf(['link', 'link-inverse']),
41
41
  elementRef: _propTypes.default.func,
42
42
  as: _propTypes.default.elementType,
43
+ role: _propTypes.default.string,
44
+ forceButtonRole: _propTypes.default.bool,
43
45
  interaction: _propTypes.default.oneOf(['enabled', 'disabled']),
44
46
  margin: _emotion.ThemeablePropTypes.spacing,
45
47
  renderIcon: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node]),
@@ -51,5 +53,5 @@ const propTypes = {
51
53
  onBlur: _propTypes.default.func
52
54
  };
53
55
  exports.propTypes = propTypes;
54
- const allowedProps = ['children', 'href', 'color', 'elementRef', 'as', 'interaction', 'margin', 'renderIcon', 'iconPlacement', 'display', 'isWithinText', 'onClick', 'onFocus', 'onBlur'];
56
+ const allowedProps = ['children', 'href', 'color', 'elementRef', 'as', 'role', 'forceButtonRole', 'interaction', 'margin', 'renderIcon', 'iconPlacement', 'display', 'isWithinText', 'onClick', 'onFocus', 'onBlur'];
55
57
  exports.allowedProps = allowedProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-link",
3
- "version": "8.23.1-snapshot.8+e6ddacd12",
3
+ "version": "8.24.1-snapshot.16+363893b5f",
4
4
  "description": "A component for creating links",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -24,25 +24,25 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.13.10",
27
- "@instructure/console": "8.23.1-snapshot.8+e6ddacd12",
28
- "@instructure/emotion": "8.23.1-snapshot.8+e6ddacd12",
29
- "@instructure/shared-types": "8.23.1-snapshot.8+e6ddacd12",
30
- "@instructure/ui-a11y-utils": "8.23.1-snapshot.8+e6ddacd12",
31
- "@instructure/ui-color-utils": "8.23.1-snapshot.8+e6ddacd12",
32
- "@instructure/ui-dom-utils": "8.23.1-snapshot.8+e6ddacd12",
33
- "@instructure/ui-icons": "8.23.1-snapshot.8+e6ddacd12",
34
- "@instructure/ui-prop-types": "8.23.1-snapshot.8+e6ddacd12",
35
- "@instructure/ui-react-utils": "8.23.1-snapshot.8+e6ddacd12",
36
- "@instructure/ui-testable": "8.23.1-snapshot.8+e6ddacd12",
37
- "@instructure/ui-view": "8.23.1-snapshot.8+e6ddacd12",
27
+ "@instructure/console": "8.24.1-snapshot.16+363893b5f",
28
+ "@instructure/emotion": "8.24.1-snapshot.16+363893b5f",
29
+ "@instructure/shared-types": "8.24.1-snapshot.16+363893b5f",
30
+ "@instructure/ui-a11y-utils": "8.24.1-snapshot.16+363893b5f",
31
+ "@instructure/ui-color-utils": "8.24.1-snapshot.16+363893b5f",
32
+ "@instructure/ui-dom-utils": "8.24.1-snapshot.16+363893b5f",
33
+ "@instructure/ui-icons": "8.24.1-snapshot.16+363893b5f",
34
+ "@instructure/ui-prop-types": "8.24.1-snapshot.16+363893b5f",
35
+ "@instructure/ui-react-utils": "8.24.1-snapshot.16+363893b5f",
36
+ "@instructure/ui-testable": "8.24.1-snapshot.16+363893b5f",
37
+ "@instructure/ui-view": "8.24.1-snapshot.16+363893b5f",
38
38
  "prop-types": "^15"
39
39
  },
40
40
  "devDependencies": {
41
- "@instructure/ui-babel-preset": "8.23.1-snapshot.8+e6ddacd12",
42
- "@instructure/ui-test-locator": "8.23.1-snapshot.8+e6ddacd12",
43
- "@instructure/ui-test-queries": "8.23.1-snapshot.8+e6ddacd12",
44
- "@instructure/ui-test-utils": "8.23.1-snapshot.8+e6ddacd12",
45
- "@instructure/ui-themes": "8.23.1-snapshot.8+e6ddacd12"
41
+ "@instructure/ui-babel-preset": "8.24.1-snapshot.16+363893b5f",
42
+ "@instructure/ui-test-locator": "8.24.1-snapshot.16+363893b5f",
43
+ "@instructure/ui-test-queries": "8.24.1-snapshot.16+363893b5f",
44
+ "@instructure/ui-test-utils": "8.24.1-snapshot.16+363893b5f",
45
+ "@instructure/ui-themes": "8.24.1-snapshot.16+363893b5f"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "react": ">=16.8 <=17"
@@ -51,5 +51,5 @@
51
51
  "access": "public"
52
52
  },
53
53
  "sideEffects": false,
54
- "gitHead": "e6ddacd12e51b7dbfa1dfcb4a569f6e30f12b51d"
54
+ "gitHead": "363893b5f0575cc9743cdaa7fae4c404f3fb9cca"
55
55
  }
@@ -40,7 +40,9 @@ export default {
40
40
  },
41
41
  getComponentProps: () => {
42
42
  return {
43
- href: 'http://instructure.design'
43
+ href: 'http://instructure.design',
44
+ forceButtonRole: false,
45
+ role: undefined
44
46
  }
45
47
  },
46
48
  getExampleProps: (props) => {
@@ -65,7 +65,8 @@ class Link extends Component<LinkProps, LinkState> {
65
65
  interaction: undefined,
66
66
  color: 'link',
67
67
  iconPlacement: 'start',
68
- isWithinText: true
68
+ isWithinText: true,
69
+ forceButtonRole: true
69
70
  } as const
70
71
 
71
72
  state = { hasFocus: false }
@@ -182,6 +183,16 @@ class Link extends Component<LinkProps, LinkState> {
182
183
  return hasVisibleChildren(this.props.children)
183
184
  }
184
185
 
186
+ get role() {
187
+ const { role, forceButtonRole, onClick } = this.props
188
+
189
+ if (forceButtonRole) {
190
+ return onClick && this.element !== 'button' ? 'button' : role
191
+ }
192
+
193
+ return role
194
+ }
195
+
185
196
  focus() {
186
197
  this.ref && (this.ref as HTMLElement).focus()
187
198
  }
@@ -211,15 +222,17 @@ class Link extends Component<LinkProps, LinkState> {
211
222
  isWithinText,
212
223
  ...props
213
224
  } = this.props
225
+
214
226
  const { interaction } = this
215
227
 
216
228
  const isDisabled = interaction === 'disabled'
217
- const role = onClick && this.element !== 'button' ? 'button' : undefined
229
+
218
230
  const type =
219
231
  this.element === 'button' || this.element === 'input'
220
232
  ? 'button'
221
233
  : undefined
222
- const tabIndex = role === 'button' && !isDisabled ? 0 : undefined
234
+
235
+ const tabIndex = this.role === 'button' && !isDisabled ? 0 : undefined
223
236
 
224
237
  return (
225
238
  <View
@@ -233,7 +246,7 @@ class Link extends Component<LinkProps, LinkState> {
233
246
  onFocus={this.handleFocus}
234
247
  onBlur={this.handleBlur}
235
248
  aria-disabled={isDisabled ? 'true' : undefined}
236
- role={role}
249
+ role={this.role}
237
250
  type={type}
238
251
  tabIndex={tabIndex}
239
252
  css={this.props.styles?.link}
package/src/Link/props.ts CHANGED
@@ -67,6 +67,17 @@ type LinkOwnProps = {
67
67
  */
68
68
  as?: AsElementType
69
69
 
70
+ /**
71
+ * The ARIA role of the element.
72
+ */
73
+ role?: string
74
+
75
+ /**
76
+ * If the Link has an onClick handler but is not a button element,
77
+ * force ARIA role to be "button".
78
+ */
79
+ forceButtonRole?: boolean
80
+
70
81
  /**
71
82
  * Determines if the link is enabled or disabled
72
83
  */
@@ -142,6 +153,8 @@ const propTypes: PropValidators<PropKeys> = {
142
153
  color: PropTypes.oneOf(['link', 'link-inverse']),
143
154
  elementRef: PropTypes.func,
144
155
  as: PropTypes.elementType,
156
+ role: PropTypes.string,
157
+ forceButtonRole: PropTypes.bool,
145
158
  interaction: PropTypes.oneOf(['enabled', 'disabled']),
146
159
  margin: ThemeablePropTypes.spacing,
147
160
  renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
@@ -165,6 +178,8 @@ const allowedProps: AllowedPropKeys = [
165
178
  'color',
166
179
  'elementRef',
167
180
  'as',
181
+ 'role',
182
+ 'forceButtonRole',
168
183
  'interaction',
169
184
  'margin',
170
185
  'renderIcon',