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

[Banner] Propagate attributes #114

Merged
merged 2 commits into from
Aug 9, 2023
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
12 changes: 12 additions & 0 deletions src/components/Banner/Banner.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ import { Banner } from './Banner';
import { LanguageLink } from './BannerLanguageLink';

describe('<Banner />', () => {
it('Propagates additional HTML properties to main component element', () => {
const testClass = 'this-is-a-test-classname';
const testTitle = 'test-title';

const testId = 'eyebrow';

render(<Banner className={testClass} title={testTitle} />);
expect(screen.getByTestId(testId)).toBeInTheDocument();
expect(screen.getByTestId(testId)).toHaveClass(testClass);
expect(screen.getByTestId(testId)).toHaveAttribute('title', testTitle);
});

it('renders tagline correctly', () => {
render(
<Banner tagline='An official website of the United States government' />
Expand Down
14 changes: 11 additions & 3 deletions src/components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { JSXElement } from '../../types/jsxElement';
import { Tagline } from '../Tagline/Tagline';
import './Banner.less';

interface BannerProperties {
interface BannerProperties extends React.HTMLProps<HTMLDivElement> {
isHorizontal?: boolean;
links?: JSX.Element[];
phoneNumber?: string;
Expand Down Expand Up @@ -37,7 +37,9 @@ export const Banner = ({
isHorizontal = true,
tagline = 'This is a tagline',
phoneNumber,
links = []
links = [],
className,
...properties
}: BannerProperties): JSX.Element => {
const eyebrowClasses = ['m-global-eyebrow'];
const wrapperClasses = ['wrapper'];
Expand All @@ -53,8 +55,14 @@ export const Banner = ({
eyebrowClasses.push('m-global-eyebrow__list');
}

if (className) eyebrowClasses.push(className);

return (
<div className={classnames(eyebrowClasses)} data-testid='eyebrow'>
<div
className={classnames(eyebrowClasses)}
data-testid='eyebrow'
{...properties}
>
<div className={classnames(wrapperClasses)}>
{taglineContent}

Expand Down