Skip to content

Commit 512c0df

Browse files
committed
feat(ui-heading): enable setting level for headings with variant
INSTUI-4612
1 parent 48b5a4a commit 512c0df

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

packages/ui-heading/src/Heading/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ Heading is a component for creating typographic headings.
66

77
## Variant
88

9-
Variant covers almost all use cases for headings on pages. Their name reflects the places they meant to be used. It sets the `level` prop and takes care of the style of the heading
10-
We recommend using `variants` instead of the `level` (and `as`) props.
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
1110

12-
NOTE: when `variant` is set, `level` and `as` props are ignored
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
1318

1419
```js
1520
---

packages/ui-heading/src/Heading/index.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ class Heading extends Component<HeadingProps> {
8888
}
8989

9090
checkProps() {
91-
const { variant, level, as } = this.props
91+
const { variant, as } = this.props
9292
if (variant) {
93-
if (level) {
94-
console.warn("[Heading]: Don't use 'level' with 'variant' ")
95-
}
9693
if (as) {
9794
console.warn("[Heading]: Don't use 'as' with 'variant' ")
9895
}
@@ -138,13 +135,16 @@ class Heading extends Component<HeadingProps> {
138135
const propsForGetElementType = variant ? {} : this.props
139136

140137
const ElementType = getElementType(Heading, propsForGetElementType, () => {
141-
if (variant) {
142-
return variantLevels[variant]
143-
}
144138
if (level === 'reset') {
145139
return 'span'
140+
} else if (level) {
141+
return level
142+
}
143+
144+
if (variant) {
145+
return variantLevels[variant]
146146
} else {
147-
return level!
147+
return 'span'
148148
}
149149
})
150150

packages/ui-heading/src/Heading/props.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ type HeadingOwnProps = {
8484
*/
8585
renderIcon?: Renderable
8686
/**
87-
* Sets style and level at once. The as property will be the same as the level.
88-
* NOTE: this is the recommended way of setting the appearance, instead of level
87+
* Sets appearance of the heading.
8988
*/
9089
variant?:
9190
| 'titlePageDesktop'

0 commit comments

Comments
 (0)