Skip to content

Commit

Permalink
feat(PageItem): add linkStyle and linkClassName props (#6636)
Browse files Browse the repository at this point in the history
* Fix(Unable to add custom styles to PageItem Component)

* Fix(Unable to add custom styles to PageItem Component)

* Change innerStyle, innerClassName to linkStyle, linkClassName & adding tests
  • Loading branch information
devmuhnnad committed Jun 23, 2023
1 parent aeecea8 commit cc8efc3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/PageItem.tsx
Expand Up @@ -13,6 +13,8 @@ export interface PageItemProps
active?: boolean;
activeLabel?: string;
href?: string;
linkStyle?: React.CSSProperties;
linkClassName?: string;
}

const propTypes = {
Expand All @@ -30,6 +32,12 @@ const propTypes = {

/** A callback function for when this component is clicked. */
onClick: PropTypes.func,

/** custom style for the inner component of the PageItem */
linkStyle: PropTypes.object,

/** custom className for the inner component of the PageItem */
linkClassName: PropTypes.string,
};

const PageItem: BsPrefixRefForwardingComponent<'li', PageItemProps> =
Expand All @@ -42,6 +50,8 @@ const PageItem: BsPrefixRefForwardingComponent<'li', PageItemProps> =
style,
activeLabel = '(current)',
children,
linkStyle,
linkClassName,
...props
}: PageItemProps,
ref,
Expand All @@ -53,7 +63,11 @@ const PageItem: BsPrefixRefForwardingComponent<'li', PageItemProps> =
style={style}
className={classNames(className, 'page-item', { active, disabled })}
>
<Component className="page-link" {...props}>
<Component
className={classNames('page-link', linkClassName)}
style={linkStyle}
{...props}
>
{children}
{active && activeLabel && (
<span className="visually-hidden">{activeLabel}</span>
Expand Down
18 changes: 18 additions & 0 deletions test/PageItemSpec.tsx
Expand Up @@ -49,5 +49,23 @@ describe('<PageItem>', () => {

pageItemInnerElem.classList.contains('page-link').should.be.true;
});

it('should apply className to the inner component if linkClassName is set', () => {
const { container } = render(
<PageItem linkClassName="custom-class-name" />,
);
const pageItemElem = container.firstElementChild!;
const pageItemInnerElem = pageItemElem.firstElementChild!;

pageItemInnerElem.classList.contains('custom-class-name').should.be.true;
});

it('should apply style to the inner component if linkStyle is set', () => {
const { container } = render(<PageItem linkStyle={{ color: 'red' }} />);
const pageItemElem = container.firstElementChild!;
const pageItemInnerElem = pageItemElem.firstElementChild!;

pageItemInnerElem.getAttribute('style')!.should.equal('color: red;');
});
});
});

0 comments on commit cc8efc3

Please sign in to comment.