Skip to content

Commit d000a4e

Browse files
committed
fix(paragraph): allow global HTML attributes to be passed to p element
1 parent b91194a commit d000a4e

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

.changeset/warm-hats-serve.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@twilio-paste/paragraph': patch
3+
'@twilio-paste/core': patch
4+
---
5+
6+
[Paragraph] allow for global HTML attriutes to be passed to the paragraph element

packages/paste-core/components/paragraph/__tests__/paragraph.test.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
import * as React from 'react';
2-
import {render as testRender} from '@testing-library/react';
2+
import {render, screen} from '@testing-library/react';
33
// @ts-ignore typescript doesn't like js imports
44
import axe from '../../../../../.jest/axe-helper';
55
import {Paragraph} from '../src';
66

77
describe('General', () => {
88
it('should render', (): void => {
99
const textContent = `This is a paragraph`;
10-
const {getByText} = testRender(<Paragraph>{textContent}</Paragraph>);
10+
const {getByText} = render(<Paragraph>{textContent}</Paragraph>);
1111
expect(getByText(textContent)).toBeDefined();
12+
expect(getByText(textContent).tagName).toEqual('P');
13+
});
14+
it('should allow for global html Attributes', (): void => {
15+
const textContent = `This is a paragraph`;
16+
render(
17+
<Paragraph aria-label="foo" data-testid="bar">
18+
{textContent}
19+
</Paragraph>
20+
);
21+
expect(screen.getByTestId('bar')).toBeDefined();
22+
expect(screen.getByLabelText('foo')).toBeDefined();
1223
});
1324
});
1425

1526
describe('Accessibility', () => {
1627
it('Should have no accessibility violations', async () => {
17-
const {container} = testRender(<Paragraph>Hello world!</Paragraph>);
28+
const {container} = render(<Paragraph>Hello world!</Paragraph>);
1829
const results = await axe(container);
1930
expect(results).toHaveNoViolations();
2031
});

packages/paste-core/components/paragraph/src/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import * as React from 'react';
2-
import {Text} from '@twilio-paste/text';
2+
import {Text, safelySpreadTextProps} from '@twilio-paste/text';
33

44
export interface ParagraphProps extends React.HTMLAttributes<HTMLParagraphElement> {
55
id?: never;
66
className?: never;
77
marginBottom?: 'space0';
88
}
99

10-
const Paragraph = React.forwardRef<HTMLParagraphElement, ParagraphProps>(({children, marginBottom}, ref) => {
10+
const Paragraph = React.forwardRef<HTMLParagraphElement, ParagraphProps>(({children, marginBottom, ...props}, ref) => {
1111
return (
1212
<Text
13+
{...safelySpreadTextProps(props)}
1314
as="p"
1415
marginBottom={marginBottom || 'space70'}
1516
fontSize="fontSize30"

0 commit comments

Comments
 (0)