Skip to content

Commit

Permalink
Allow href and onClick in ListGroupItem
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed May 8, 2019
1 parent ebc3c01 commit d53abb4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ exports[`EuiListGroupItem props isDisabled is rendered 1`] = `
</li>
`;

exports[`EuiListGroupItem props onClick and href is rendered 1`] = `
<li
class="euiListGroupItem euiListGroupItem--medium euiListGroupItem-isClickable"
>
<a
class="euiListGroupItem__button"
href="#"
>
<span
class="euiListGroupItem__label"
title="Label"
>
Label
</span>
</a>
</li>
`;

exports[`EuiListGroupItem props onClick is rendered 1`] = `
<li
class="euiListGroupItem euiListGroupItem--medium euiListGroupItem-isClickable"
Expand Down Expand Up @@ -308,19 +326,3 @@ exports[`EuiListGroupItem throws an warning if both iconType and icon are provid
</span>
</li>
`;

exports[`EuiListGroupItem throws an warning if both onClick and href are provided but still renders 1`] = `
<li
class="euiListGroupItem euiListGroupItem--medium euiListGroupItem-isClickable"
>
<a
class="euiListGroupItem__button"
href="#"
>
<span
class="euiListGroupItem__label"
title=""
/>
</a>
</li>
`;
6 changes: 1 addition & 5 deletions src/components/list_group/list_group_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,11 @@ export const EuiListGroupItem = ({

if (href && !isDisabled) {
itemContent = (
<a href={href} className="euiListGroupItem__button" {...rest}>
<a href={href} onClick={onClick} className="euiListGroupItem__button" {...rest}>
{iconNode}
{labelContent}
</a>
);

if (onClick) {
console.warn('Both `href` and `onClick` were passed to EuiListGroupItem but only one can exist. The `href` was used.');
}
} else if ((href && isDisabled) || onClick) {
itemContent = (
<button
Expand Down
21 changes: 9 additions & 12 deletions src/components/list_group/list_group_item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ describe('EuiListGroupItem', () => {
});
});

describe('onClick and href', () => {
test('is rendered', () => {
const component = render(
<EuiListGroupItem label="Label" onClick={() => {}} href="#" />
);

expect(component).toMatchSnapshot();
});
});
});

test('renders a disabled button even if provided an href', () => {
Expand Down Expand Up @@ -156,18 +165,6 @@ describe('EuiListGroupItem', () => {
console.warn = oldConsoleError;
});

test('if both onClick and href are provided but still renders', () => {
const component = render(
<EuiListGroupItem label="" onClick={() => {}} href="#" />
);

expect(consoleStub).toBeCalled();
expect(consoleStub.mock.calls[0][0]).toMatch(
'`href` and `onClick` were passed'
);
expect(component).toMatchSnapshot();
});

test('if both iconType and icon are provided but still renders', () => {
const component = render(
<EuiListGroupItem label="" iconType="empty" icon={<span/>} />
Expand Down

0 comments on commit d53abb4

Please sign in to comment.