Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions docs/content/Heading.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
title: Heading
---

The Heading component will render an html `h1-6` tag without any default styling. Please reference the [w3 recommendations for headings](https://www.w3.org/WAI/tutorials/page-structure/headings/) to ensure your headings provide an accessible experience for screen reader users.
The Heading component will render an html `h2` tag without any default styling. Other heading level elements `h1-h6` are available through use of the `as` prop (see [System Props](/system-props) for additional explanation). Please reference the [w3 recommendations for headings](https://www.w3.org/WAI/tutorials/page-structure/headings/) to ensure your headings provide an accessible experience for screen reader users.

**Attention:** Make sure to include a valid heading element to render a Heading component other than `h2` (`<Heading as="h1">H1 Element</Heading>`).

## Default example
```jsx live
<Heading fontSize={1} mb={2}>With fontSize={1}</Heading>
<Heading fontSize={1} mb={2}>H2 heading with fontSize={1}</Heading>
```

## System props
Expand All @@ -15,4 +17,6 @@ Heading components get `TYPOGRAPHY` and `COMMON` system props. Read our [System

## Component props

Heading does not get any additional props other than the system props mentioned above.
| Prop name | Type | Description |
| :-------- | :------ | :----------------------------------------------- |
| as | String | sets the HTML tag for the component |
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ declare module '@primer/components' {
extends BaseProps,
CommonProps,
TypographyProps,
Omit<React.HTMLAttributes<HTMLHeadingElement>, 'color'> {}
Omit<React.HTMLAttributes<HTMLHeadingElement>, 'color'> {
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
}

export const Heading: React.FunctionComponent<HeadingProps>

Expand Down
5 changes: 3 additions & 2 deletions src/Heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import {TYPOGRAPHY, COMMON, get} from './constants'
import theme from './theme'

const Heading = styled.h1`
const Heading = styled.h2`
font-weight: ${get('fontWeights.bold')};
font-size: ${get('fontSizes.5')};
margin: 0;
Expand All @@ -17,7 +17,8 @@ Heading.defaultProps = {
Heading.propTypes = {
...COMMON.propTypes,
...TYPOGRAPHY.propTypes,
theme: PropTypes.object
theme: PropTypes.object,
as: PropTypes.oneOf(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']),
}

export default Heading
5 changes: 2 additions & 3 deletions src/__tests__/Heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const theme = {
}

describe('Heading', () => {
it('renders <h1> by default', () => {
expect(render(<Heading />).type).toEqual('h1')
it('renders <h2> by default', () => {
expect(render(<Heading />).type).toEqual('h2')
})

it('should have no axe violations', async () => {
Expand Down Expand Up @@ -94,7 +94,6 @@ describe('Heading', () => {

it('respects the "fontStyle" prop', () => {
expect(render(<Heading fontStyle="italic" />)).toHaveStyleRule('font-style', 'italic')
expect(render(<Heading as="i" fontStyle="normal" />)).toHaveStyleRule('font-style', 'normal')
})

it.skip('renders fontSize with f* classes using inverse scale', () => {
Expand Down