@instructure/ui-link 8.23.0 → 8.23.1-snapshot.11

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/LICENSE.md ADDED
@@ -0,0 +1,27 @@
1
+ ---
2
+ title: The MIT License (MIT)
3
+ category: Getting Started
4
+ order: 9
5
+ ---
6
+
7
+ # The MIT License (MIT)
8
+
9
+ Copyright (c) 2015 Instructure, Inc.
10
+
11
+ **Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions.**
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
@@ -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
@@ -1,7 +1,7 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
2
  const _excluded = ["children", "onClick", "color", "href", "margin", "renderIcon", "iconPlacement", "isWithinText"];
3
3
 
4
- var _dec, _dec2, _class, _class2, _temp;
4
+ var _dec, _dec2, _class, _class2;
5
5
 
6
6
  /*
7
7
  * The MIT License (MIT)
@@ -46,7 +46,7 @@ category: components
46
46
  ---
47
47
  @tsProps
48
48
  **/
49
- let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class Link extends Component {
49
+ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_class2 = class Link extends Component {
50
50
  constructor() {
51
51
  super(...arguments);
52
52
  this.state = {
@@ -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
227
- }, _temp)) || _class) || _class);
238
+ isWithinText: true,
239
+ forceButtonRole: true
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
@@ -45,7 +45,7 @@ var _props = require("./props");
45
45
 
46
46
  const _excluded = ["children", "onClick", "color", "href", "margin", "renderIcon", "iconPlacement", "isWithinText"];
47
47
 
48
- var _dec, _dec2, _class, _class2, _temp;
48
+ var _dec, _dec2, _class, _class2;
49
49
 
50
50
  /**
51
51
  ---
@@ -53,7 +53,7 @@ category: components
53
53
  ---
54
54
  @tsProps
55
55
  **/
56
- let Link = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class Link extends _react.Component {
56
+ let Link = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_class2 = class Link extends _react.Component {
57
57
  constructor() {
58
58
  super(...arguments);
59
59
  this.state = {
@@ -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,8 +243,9 @@ 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
235
- }, _temp)) || _class) || _class);
246
+ isWithinText: true,
247
+ forceButtonRole: true
248
+ }, _class2)) || _class) || _class);
236
249
  exports.Link = Link;
237
250
  var _default = Link;
238
251
  exports.default = _default;
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.0",
3
+ "version": "8.23.1-snapshot.11+5e829fae6",
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.0",
28
- "@instructure/emotion": "8.23.0",
29
- "@instructure/shared-types": "8.23.0",
30
- "@instructure/ui-a11y-utils": "8.23.0",
31
- "@instructure/ui-color-utils": "8.23.0",
32
- "@instructure/ui-dom-utils": "8.23.0",
33
- "@instructure/ui-icons": "8.23.0",
34
- "@instructure/ui-prop-types": "8.23.0",
35
- "@instructure/ui-react-utils": "8.23.0",
36
- "@instructure/ui-testable": "8.23.0",
37
- "@instructure/ui-view": "8.23.0",
27
+ "@instructure/console": "8.23.1-snapshot.11+5e829fae6",
28
+ "@instructure/emotion": "8.23.1-snapshot.11+5e829fae6",
29
+ "@instructure/shared-types": "8.23.1-snapshot.11+5e829fae6",
30
+ "@instructure/ui-a11y-utils": "8.23.1-snapshot.11+5e829fae6",
31
+ "@instructure/ui-color-utils": "8.23.1-snapshot.11+5e829fae6",
32
+ "@instructure/ui-dom-utils": "8.23.1-snapshot.11+5e829fae6",
33
+ "@instructure/ui-icons": "8.23.1-snapshot.11+5e829fae6",
34
+ "@instructure/ui-prop-types": "8.23.1-snapshot.11+5e829fae6",
35
+ "@instructure/ui-react-utils": "8.23.1-snapshot.11+5e829fae6",
36
+ "@instructure/ui-testable": "8.23.1-snapshot.11+5e829fae6",
37
+ "@instructure/ui-view": "8.23.1-snapshot.11+5e829fae6",
38
38
  "prop-types": "^15"
39
39
  },
40
40
  "devDependencies": {
41
- "@instructure/ui-babel-preset": "8.23.0",
42
- "@instructure/ui-test-locator": "8.23.0",
43
- "@instructure/ui-test-queries": "8.23.0",
44
- "@instructure/ui-test-utils": "8.23.0",
45
- "@instructure/ui-themes": "8.23.0"
41
+ "@instructure/ui-babel-preset": "8.23.1-snapshot.11+5e829fae6",
42
+ "@instructure/ui-test-locator": "8.23.1-snapshot.11+5e829fae6",
43
+ "@instructure/ui-test-queries": "8.23.1-snapshot.11+5e829fae6",
44
+ "@instructure/ui-test-utils": "8.23.1-snapshot.11+5e829fae6",
45
+ "@instructure/ui-themes": "8.23.1-snapshot.11+5e829fae6"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "react": ">=16.8 <=17"
@@ -50,5 +50,6 @@
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "sideEffects": false
53
+ "sideEffects": false,
54
+ "gitHead": "5e829fae6b005f080497818df8b3fff19365aab3"
54
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',