@instructure/ui-heading 10.24.1-snapshot-1 → 10.24.1-snapshot-2

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,9 +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
- ## [10.24.1-snapshot-1](https://github.com/instructure/instructure-ui/compare/v10.24.0...v10.24.1-snapshot-1) (2025-07-29)
6
+ ## [10.24.1-snapshot-2](https://github.com/instructure/instructure-ui/compare/v10.24.0...v10.24.1-snapshot-2) (2025-07-30)
7
7
 
8
- **Note:** Version bump only for package @instructure/ui-heading
8
+
9
+ ### Bug Fixes
10
+
11
+ * **ui-heading:** fix Heading rendering as H2 in most cases ([d6e4cd5](https://github.com/instructure/instructure-ui/commit/d6e4cd5f6369f219e70975c95f0e1e1bcb22ced4))
9
12
 
10
13
 
11
14
 
@@ -27,7 +27,7 @@ var _dec, _dec2, _class, _Heading, _IconAiColoredSolid, _IconAiColoredSolid2, _I
27
27
 
28
28
  import { Component } from 'react';
29
29
  import { View } from '@instructure/ui-view';
30
- import { getElementType, passthroughProps, callRenderProp } from '@instructure/ui-react-utils';
30
+ import { passthroughProps, callRenderProp } from '@instructure/ui-react-utils';
31
31
  import { testable } from '@instructure/ui-testable';
32
32
  import { IconAiColoredSolid } from '@instructure/ui-icons';
33
33
  import { withStyle } from '@instructure/emotion';
@@ -184,19 +184,27 @@ let Heading = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 =
184
184
  makeStyles = _this$props6.makeStyles,
185
185
  variant = _this$props6.variant,
186
186
  props = _objectWithoutProperties(_this$props6, _excluded);
187
- const propsForGetElementType = variant ? {} : this.props;
188
- const ElementType = getElementType(Heading, propsForGetElementType, () => {
189
- if (level === 'reset') {
190
- return 'span';
191
- } else if (level) {
192
- return level;
187
+ let ElementType = 'h2';
188
+ if (variant) {
189
+ // TODO deprecated, remove. `variant` should not set DOM level
190
+ if (level) {
191
+ if (level === 'reset') {
192
+ ElementType = 'span';
193
+ } else {
194
+ ElementType = level;
195
+ }
196
+ } else {
197
+ ElementType = variantLevels[variant];
193
198
  }
194
- if (variant) {
195
- return variantLevels[variant];
199
+ } else if (props.as) {
200
+ ElementType = props.as;
201
+ } else if (level) {
202
+ if (level === 'reset') {
203
+ ElementType = 'span';
196
204
  } else {
197
- return 'span';
205
+ ElementType = level;
198
206
  }
199
- });
207
+ }
200
208
  return _jsx(View, {
201
209
  "aria-label": this.getAriaLabel(),
202
210
  ...passthroughProps(props),
@@ -210,8 +218,7 @@ let Heading = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 =
210
218
  }, _Heading.displayName = "Heading", _Heading.componentId = 'Heading', _Heading.propTypes = propTypes, _Heading.allowedProps = allowedProps, _Heading.defaultProps = {
211
219
  children: null,
212
220
  border: 'none',
213
- color: 'inherit',
214
- level: 'h2'
221
+ color: 'inherit'
215
222
  }, _Heading)) || _class) || _class);
216
223
  export default Heading;
217
224
  export { Heading };
@@ -8,7 +8,6 @@ exports.default = exports.Heading = void 0;
8
8
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
9
  var _react = require("react");
10
10
  var _View = require("@instructure/ui-view/lib/View");
11
- var _getElementType = require("@instructure/ui-react-utils/lib/getElementType.js");
12
11
  var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
13
12
  var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
14
13
  var _testable = require("@instructure/ui-testable/lib/testable.js");
@@ -192,19 +191,27 @@ let Heading = exports.Heading = (_dec = (0, _emotion.withStyle)(_styles.default,
192
191
  makeStyles = _this$props6.makeStyles,
193
192
  variant = _this$props6.variant,
194
193
  props = (0, _objectWithoutProperties2.default)(_this$props6, _excluded);
195
- const propsForGetElementType = variant ? {} : this.props;
196
- const ElementType = (0, _getElementType.getElementType)(Heading, propsForGetElementType, () => {
197
- if (level === 'reset') {
198
- return 'span';
199
- } else if (level) {
200
- return level;
194
+ let ElementType = 'h2';
195
+ if (variant) {
196
+ // TODO deprecated, remove. `variant` should not set DOM level
197
+ if (level) {
198
+ if (level === 'reset') {
199
+ ElementType = 'span';
200
+ } else {
201
+ ElementType = level;
202
+ }
203
+ } else {
204
+ ElementType = variantLevels[variant];
201
205
  }
202
- if (variant) {
203
- return variantLevels[variant];
206
+ } else if (props.as) {
207
+ ElementType = props.as;
208
+ } else if (level) {
209
+ if (level === 'reset') {
210
+ ElementType = 'span';
204
211
  } else {
205
- return 'span';
212
+ ElementType = level;
206
213
  }
207
- });
214
+ }
208
215
  return (0, _jsxRuntime.jsx)(_View.View, {
209
216
  "aria-label": this.getAriaLabel(),
210
217
  ...(0, _passthroughProps.passthroughProps)(props),
@@ -218,7 +225,6 @@ let Heading = exports.Heading = (_dec = (0, _emotion.withStyle)(_styles.default,
218
225
  }, _Heading.displayName = "Heading", _Heading.componentId = 'Heading', _Heading.propTypes = _props.propTypes, _Heading.allowedProps = _props.allowedProps, _Heading.defaultProps = {
219
226
  children: null,
220
227
  border: 'none',
221
- color: 'inherit',
222
- level: 'h2'
228
+ color: 'inherit'
223
229
  }, _Heading)) || _class) || _class);
224
230
  var _default = exports.default = Heading;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-heading",
3
- "version": "10.24.1-snapshot-1",
3
+ "version": "10.24.1-snapshot-2",
4
4
  "description": "A component for creating typographic headings",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -24,20 +24,20 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.27.6",
27
- "@instructure/console": "10.24.1-snapshot-1",
28
- "@instructure/emotion": "10.24.1-snapshot-1",
29
- "@instructure/shared-types": "10.24.1-snapshot-1",
30
- "@instructure/ui-icons": "10.24.1-snapshot-1",
31
- "@instructure/ui-prop-types": "10.24.1-snapshot-1",
32
- "@instructure/ui-react-utils": "10.24.1-snapshot-1",
33
- "@instructure/ui-testable": "10.24.1-snapshot-1",
34
- "@instructure/ui-view": "10.24.1-snapshot-1",
27
+ "@instructure/console": "10.24.1-snapshot-2",
28
+ "@instructure/emotion": "10.24.1-snapshot-2",
29
+ "@instructure/shared-types": "10.24.1-snapshot-2",
30
+ "@instructure/ui-icons": "10.24.1-snapshot-2",
31
+ "@instructure/ui-prop-types": "10.24.1-snapshot-2",
32
+ "@instructure/ui-react-utils": "10.24.1-snapshot-2",
33
+ "@instructure/ui-testable": "10.24.1-snapshot-2",
34
+ "@instructure/ui-view": "10.24.1-snapshot-2",
35
35
  "prop-types": "^15.8.1"
36
36
  },
37
37
  "devDependencies": {
38
- "@instructure/ui-axe-check": "10.24.1-snapshot-1",
39
- "@instructure/ui-babel-preset": "10.24.1-snapshot-1",
40
- "@instructure/ui-themes": "10.24.1-snapshot-1",
38
+ "@instructure/ui-axe-check": "10.24.1-snapshot-2",
39
+ "@instructure/ui-babel-preset": "10.24.1-snapshot-2",
40
+ "@instructure/ui-themes": "10.24.1-snapshot-2",
41
41
  "@testing-library/jest-dom": "^6.6.3",
42
42
  "@testing-library/react": "^16.0.1",
43
43
  "vitest": "^3.2.2"
@@ -4,33 +4,39 @@ describes: Heading
4
4
 
5
5
  Heading is a component for creating typographic headings.
6
6
 
7
- ## Variant
7
+ ### Variant
8
8
 
9
9
  Variant covers almost all use cases for headings on pages. Their name reflects the places they meant to be used. It takes care of the style of the heading
10
10
 
11
- NOTE 1: for legacy reasons, each `variant` has a default `level` set. This is not the recommended way and will be removed in a later major release. Please specify the `level` directly!
12
-
13
- NOTE 2: when `variant` is set the `as` prop is ignored
14
-
15
- IMPORTANT A11Y NOTE 1: there can be only one `h1` tag in a page
16
-
17
- IMPORTANT A11Y NOTE 2: `h` tags can not skip a level, so for example an `h1` followed by an `h3` not allowed
11
+ ```js
12
+ ---
13
+ type: embed
14
+ ---
15
+ <Alert variant="info">
16
+ <List margin="0 0 medium">
17
+ <List.Item>For legacy reasons, each <code>variant</code> has a default <code>level</code> set. This is not the recommended way and will be removed in a later major release. Please always specify the <code>level</code>!</List.Item>
18
+ <List.Item>When <code>variant</code> is set the <code>as</code> prop is ignored</List.Item>
19
+ <List.Item>A11Y GUIDELINE: There can be only one <code>h1</code> tag in a page</List.Item>
20
+ <List.Item>A11Y GUIDELINE: <code>h</code> tags can not skip a level, so for example an <code>h1</code> followed by an <code>h3</code> not allowed</List.Item>
21
+ </List>
22
+ </Alert>
23
+ ```
18
24
 
19
25
  ```js
20
26
  ---
21
27
  type: example
22
28
  ---
23
29
  <div>
24
- <Heading variant="titlePageDesktop"> titlePageDesktop </Heading><br/>
25
- <Heading variant="titlePageMobile"> titlePageMobile </Heading><br/>
26
- <Heading variant="titleSection"> titleSection </Heading><br/>
27
- <Heading variant="titleCardSection"> titleCardSection </Heading><br/>
28
- <Heading variant="titleModule"> titleModule </Heading><br/>
29
- <Heading variant="titleCardLarge"> titleCardLarge </Heading><br/>
30
- <Heading variant="titleCardRegular"> titleCardRegular </Heading><br/>
31
- <Heading variant="titleCardMini"> titleCardMini </Heading><br/>
32
- <Heading variant="label"> label </Heading><br/>
33
- <Heading variant="labelInline"> labelInline </Heading><br/>
30
+ <Heading variant="titlePageDesktop" level="h1"> titlePageDesktop </Heading><br/>
31
+ <Heading variant="titlePageMobile" level="h1"> titlePageMobile </Heading><br/>
32
+ <Heading variant="titleSection" level="h2"> titleSection </Heading><br/>
33
+ <Heading variant="titleCardSection" level="h2"> titleCardSection </Heading><br/>
34
+ <Heading variant="titleModule" level="h2"> titleModule </Heading><br/>
35
+ <Heading variant="titleCardLarge" level="h3"> titleCardLarge </Heading><br/>
36
+ <Heading variant="titleCardRegular" level="h3"> titleCardRegular </Heading><br/>
37
+ <Heading variant="titleCardMini" level="h4"> titleCardMini </Heading><br/>
38
+ <Heading variant="label" level="h5"> label </Heading><br/>
39
+ <Heading variant="labelInline" level="h6"> labelInline </Heading><br/>
34
40
  </div>
35
41
  ```
36
42
 
@@ -51,18 +57,21 @@ type: example
51
57
 
52
58
  ### Heading level
53
59
 
54
- Generate content headings, from h1 to h5. Use the `margin` prop to add margin.
60
+ What DOM element is output is determined in the following order:
55
61
 
56
- - The `as` prop controls what html element is output. _(if not defined it will default to level)._
57
- - The `level` prop sets its appearance.
62
+ 1. (deprecated) If the variant prop is set, then the value of level prop. If variant is set but level is not, <h1>-<h6> based on the variant prop's value.
63
+ 2. The value of the `as` prop
64
+ 3. The value of the `level` prop
65
+ 4. `<h2>`
66
+
67
+ The `variant` and `level` props sets its appearance in this order.
58
68
 
59
69
  ```js
60
70
  ---
61
71
  type: example
62
72
  ---
63
73
  <div>
64
- <Heading level="h1" as="h2" margin="0 0 x-small">Heading level One</Heading>
65
-
74
+ <Heading level="h1" as="h3" margin="0 0 x-small">This renders as <code>&lt;h3&gt;</code></Heading>
66
75
  </div>
67
76
  ```
68
77
 
@@ -25,11 +25,7 @@
25
25
  import { Component } from 'react'
26
26
 
27
27
  import { View } from '@instructure/ui-view'
28
- import {
29
- getElementType,
30
- passthroughProps,
31
- callRenderProp
32
- } from '@instructure/ui-react-utils'
28
+ import { passthroughProps, callRenderProp } from '@instructure/ui-react-utils'
33
29
  import { testable } from '@instructure/ui-testable'
34
30
  import { IconAiColoredSolid } from '@instructure/ui-icons'
35
31
 
@@ -40,6 +36,7 @@ import generateComponentTheme from './theme'
40
36
 
41
37
  import { propTypes, allowedProps } from './props'
42
38
  import type { HeadingProps } from './props'
39
+ import { AsElementType } from '@instructure/shared-types'
43
40
 
44
41
  const variantLevels: Record<
45
42
  NonNullable<HeadingProps['variant']>,
@@ -72,8 +69,7 @@ class Heading extends Component<HeadingProps> {
72
69
  static defaultProps = {
73
70
  children: null,
74
71
  border: 'none',
75
- color: 'inherit',
76
- level: 'h2'
72
+ color: 'inherit'
77
73
  } as const
78
74
 
79
75
  ref: Element | null = null
@@ -201,22 +197,27 @@ class Heading extends Component<HeadingProps> {
201
197
  ...props
202
198
  } = this.props
203
199
 
204
- const propsForGetElementType = variant ? {} : this.props
205
-
206
- const ElementType = getElementType(Heading, propsForGetElementType, () => {
207
- if (level === 'reset') {
208
- return 'span'
209
- } else if (level) {
210
- return level
200
+ let ElementType: AsElementType = 'h2'
201
+ if (variant) {
202
+ // TODO deprecated, remove. `variant` should not set DOM level
203
+ if (level) {
204
+ if (level === 'reset') {
205
+ ElementType = 'span'
206
+ } else {
207
+ ElementType = level
208
+ }
209
+ } else {
210
+ ElementType = variantLevels[variant]
211
211
  }
212
-
213
- if (variant) {
214
- return variantLevels[variant]
212
+ } else if (props.as) {
213
+ ElementType = props.as
214
+ } else if (level) {
215
+ if (level === 'reset') {
216
+ ElementType = 'span'
215
217
  } else {
216
- return 'span'
218
+ ElementType = level
217
219
  }
218
- })
219
-
220
+ }
220
221
  return (
221
222
  <View
222
223
  aria-label={this.getAriaLabel()}
@@ -43,7 +43,7 @@ type HeadingLevel<U extends keyof JSX.IntrinsicElements> = U
43
43
 
44
44
  type HeadingOwnProps = {
45
45
  /**
46
- * transforms heading into an ai variant
46
+ * transforms heading into an `ai` variant
47
47
  */
48
48
  aiVariant?: 'stacked' | 'horizontal' | 'iconOnly'
49
49
  /**
@@ -58,19 +58,23 @@ type HeadingOwnProps = {
58
58
  * The font color to render, NOTE: `ai` color is deprecated. Use the `aiVariant` prop instead
59
59
  */
60
60
  color?:
61
- | 'primary'
62
- | 'secondary'
63
- | 'primary-inverse'
64
- | 'secondary-inverse'
65
- | 'inherit'
66
- | 'ai'
61
+ | 'primary'
62
+ | 'secondary'
63
+ | 'primary-inverse'
64
+ | 'secondary-inverse'
65
+ | 'inherit'
66
+ | 'ai'
67
67
  /**
68
- * The *visual* appearance of the Heading: h1 is largest; h5 is smallest.
68
+ * The level of the heading in the DOM: h1 is largest; h5 is smallest.
69
69
  */
70
70
  level?: HeadingLevel<'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'> | 'reset'
71
71
  /**
72
- * Choose the element Heading should render as. Will default to the `level` prop
73
- * if not specified.
72
+ * What DOM element is output is determined in the following order:
73
+ * 1. (deprecated) If `variant` is set, then use the `level` prop, if that's
74
+ * not set use `<h1>`-`<h6>` based on the `variant` prop's value
75
+ * 2. The value of the `as` prop
76
+ * 3. The value of the `level` prop
77
+ * 4. `<h2>`
74
78
  */
75
79
  as?: AsElementType
76
80
  /**
@@ -88,19 +92,20 @@ type HeadingOwnProps = {
88
92
  */
89
93
  renderIcon?: Renderable
90
94
  /**
91
- * Sets appearance of the heading.
95
+ * Sets appearance of the heading. Will also set its heading level, if not
96
+ * specified by the `level` prop (deprecated, not recommended!)
92
97
  */
93
98
  variant?:
94
- | 'titlePageDesktop'
95
- | 'titlePageMobile'
96
- | 'titleSection'
97
- | 'titleCardSection'
98
- | 'titleModule'
99
- | 'titleCardLarge'
100
- | 'titleCardRegular'
101
- | 'titleCardMini'
102
- | 'label'
103
- | 'labelInline'
99
+ | 'titlePageDesktop'
100
+ | 'titlePageMobile'
101
+ | 'titleSection'
102
+ | 'titleCardSection'
103
+ | 'titleModule'
104
+ | 'titleCardLarge'
105
+ | 'titleCardRegular'
106
+ | 'titleCardMini'
107
+ | 'label'
108
+ | 'labelInline'
104
109
  }
105
110
 
106
111
  type PropKeys = keyof HeadingOwnProps