Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow heading truncation #2371

Merged
merged 2 commits into from
Jul 29, 2022
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
6 changes: 6 additions & 0 deletions .changeset/wise-terms-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@aws-amplify/ui-react': patch
'@aws-amplify/ui': patch
cshfang marked this conversation as resolved.
Show resolved Hide resolved
---

fix(ui-react): Fixes an issue where the isTruncated prop of the Heading component was not properly applying a truncation.
9 changes: 7 additions & 2 deletions packages/react/src/primitives/Heading/Heading.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import classNames from 'classnames';

import { classNameModifier } from '../shared/utils';
import { classNameModifier, classNameModifierByFlag } from '../shared/utils';
import { ComponentClassNames } from '../shared/constants';
import { HeadingProps, Primitive } from '../types';
import { View } from '../View';
Expand All @@ -22,14 +22,19 @@ const headingLevels: HeadingLevels = {
};

const HeadingPrimitive: Primitive<HeadingProps, HeadingTag> = (
{ className, children, level = 6, ...rest },
{ className, children, isTruncated, level = 6, ...rest },
ref
) => (
<View
as={headingLevels[level]}
className={classNames(
ComponentClassNames.Heading,
classNameModifier(ComponentClassNames.Heading, level),
classNameModifierByFlag(
ComponentClassNames.Heading,
'truncated',
isTruncated
),
className
)}
ref={ref}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,20 @@ describe('Heading: ', () => {
const heading = await screen.findByTestId('dataTest');
expect(heading.dataset['demo']).toBe('true');
});

it('should render the truncated class on Heading', async () => {
render(
<div>
<Heading testId="truncated" isTruncated={true}>
truncated
</Heading>
</div>
);

const truncated = await screen.findByTestId('truncated');

expect(truncated.classList).toContain(
`${ComponentClassNames['Heading']}--truncated`
);
});
});
6 changes: 6 additions & 0 deletions packages/ui/src/theme/css/component/heading.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
color: var(--amplify-components-heading-color);
line-height: var(--amplify-components-heading-line-height);
display: block;

&--truncated {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}

.amplify-heading--1 {
Expand Down