Skip to content

Commit

Permalink
fix(ffe-lists-react): retter html hierarki feil med at button og link…
Browse files Browse the repository at this point in the history
… ikke kan være under dl
  • Loading branch information
HeleneKassandra committed Mar 13, 2024
1 parent a4c7e9e commit 79b0cb9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
4 changes: 0 additions & 4 deletions packages/ffe-lists-react/src/DetailListCard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ describe('<DetailListCard />', () => {
expect(wrapper.hasClass('test-class')).toBe(true);
});

it('render correct element based on element prop', () => {
const wrapper = getDetailListCardItemWrapper({ element: 'a' });
expect(wrapper.is('a')).toBe(true);
});
it('adds additional props correctly', () => {
const wrapper = getDetailListCardItemWrapper({ href: '#' });
expect(wrapper.prop('href')).toBe('#');
Expand Down
17 changes: 7 additions & 10 deletions packages/ffe-lists-react/src/DetailListCardItem.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import React from 'react';
import classNames from 'classnames';
import { string, oneOfType, node, func, elementType } from 'prop-types';
import { string, oneOfType, node, oneOf } from 'prop-types';

const DetailListCardItem = props => {
const { className, label, value, element: Element, ...rest } = props;
const { className, label, value, role, ...rest } = props;

const isClickable = rest.onClick || rest.href;

return (
<Element
<div
className={classNames(
'ffe-detail-list-card__item',
{
'ffe-detail-list-card__item--clickable': isClickable,
},
className,
)}
role={role}
{...rest}
>
<dt className="ffe-detail-list-card__item-label">
Expand All @@ -28,19 +29,15 @@ const DetailListCardItem = props => {
? value
: React.cloneElement(value, { ...value.props })}
</dd>
</Element>
</div>
);
};

DetailListCardItem.defaultProps = {
element: 'div',
};

DetailListCardItem.propTypes = {
/** Additional classnames */
className: string,
/** The element to render the item as */
element: oneOfType([func, string, elementType]),
/** The role the row should have. use Link if it has a href, and button if it only got an onClick */
role: oneOf(['link', 'button']),
/** Content of the label / left column */
label: oneOfType([node, string]).isRequired,
/** Content of the value / right column */
Expand Down
2 changes: 1 addition & 1 deletion packages/ffe-lists-react/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface DescriptionListProps extends BaseListProps {

export interface DetailListCardItemProps {
className?: string;
element?: HTMLElement | string | React.ElementType;
role?: 'link' | 'button';
label: React.ReactNode;
value: React.ReactNode;
}
Expand Down

0 comments on commit 79b0cb9

Please sign in to comment.