Skip to content

Commit

Permalink
[Banner] Propagate attributes (#114)
Browse files Browse the repository at this point in the history
* feat: [Banner] Allow additional classnames; propagate other attributes to wrapper element

* chore: [Banner] Update test code
  • Loading branch information
meissadia committed Aug 9, 2023
1 parent 92e644c commit d42a349
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
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

0 comments on commit d42a349

Please sign in to comment.