Skip to content
Open
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
16 changes: 16 additions & 0 deletions src/components/Headings/heading.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ describe('<Heading />', () => {
}
});

it('Renders React elements with text', () => {
render(
<Heading type='2' data-testid='heading-with-element'>
<span data-testid='heading-icon' aria-hidden='true' />
Information
</Heading>,
);

const current = screen.getByTestId('heading-with-element');

expect(current).toBeInTheDocument();
expect(current.tagName.toLowerCase()).toBe('h2');
expect(screen.getByTestId('heading-icon')).toBeInTheDocument();
expect(current).toHaveTextContent('Information');
});

it('Renders Display heading', () => {
const headingType = `display`;
const testid = `h${headingType}`;
Expand Down
8 changes: 6 additions & 2 deletions src/components/Headings/heading.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import classnames from 'classnames';
import { JSX } from 'react';
import type { HTMLProps } from 'react';
import type { HTMLProps, ReactNode } from 'react';

export type HeadingType =
| '1'
Expand All @@ -12,9 +12,13 @@ export type HeadingType =
| 'eyebrow'
| 'slug';

interface HeadingProperties extends HTMLProps<HTMLHeadingElement> {
interface HeadingProperties extends Omit<
HTMLProps<HTMLHeadingElement>,
'children'
> {
/** Heading type (1-5, display, eyebrow, slug) */
type?: HeadingType;
children?: ReactNode;
}

export const Heading = ({
Expand Down
13 changes: 12 additions & 1 deletion src/components/Headings/headings.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { Heading } from '~/src/index';
import { expect, within } from 'storybook/test';
import { Heading, Icon } from '~/src/index';
/**
* A successful type hierarchy establishes the order of importance of elements on a page. Consistent scaling, weights, and capitalization are used to create distinction between headings and provide users with familiar focus points when scanning text.
*
Expand Down Expand Up @@ -98,3 +98,14 @@ export const Slug: Story = {
children: 'Slug',
},
};

export const WithIcon: Story = {
args: {
type: '2',
},
render: (arguments_) => (
<Heading {...arguments_}>
<Icon name='taxes' /> Information
</Heading>
),
};
Loading