Skip to content

Commit

Permalink
feat(ui-breadcrumb,ui-link): add onMouseEnter prop
Browse files Browse the repository at this point in the history
Closes: INSTUI-3930
  • Loading branch information
HerrTopi committed Nov 8, 2023
1 parent da016c8 commit 67b3b87
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ describe('<BreadcrumbLink />', () => {
expect(onClick).toHaveBeenCalledTimes(1)
})

it('should respond to mouseEnter event when provided with onMouseEnter prop', () => {
const onMouseEnter = jest.fn()

render(
<BreadcrumbLink onMouseEnter={onMouseEnter} href={TEST_LINK}>
{TEST_TEXT_01}
</BreadcrumbLink>
)
const link = screen.getByRole('link')
fireEvent.mouseEnter(link)

expect(onMouseEnter).toHaveBeenCalledTimes(1)
})

it('should allow to prop to pass through', () => {
const { container } = render(
<BreadcrumbLink to={TEST_TO}>{TEST_TEXT_01}</BreadcrumbLink>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class BreadcrumbLink extends Component<BreadcrumbLinkProps> {
}

render() {
const { children, href, renderIcon, iconPlacement, onClick } = this.props
const { children, href, renderIcon, iconPlacement, onClick, onMouseEnter } =
this.props

const props = omitProps(this.props, BreadcrumbLink.allowedProps)

Expand All @@ -65,6 +66,7 @@ class BreadcrumbLink extends Component<BreadcrumbLinkProps> {
renderIcon={renderIcon}
iconPlacement={iconPlacement}
onClick={onClick}
onMouseEnter={onMouseEnter}
isWithinText={false}
elementRef={this.handleRef}
>
Expand Down
6 changes: 6 additions & 0 deletions packages/ui-breadcrumb/src/Breadcrumb/BreadcrumbLink/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type BreadcrumbLinkOwnProps = {
* If the Breadcrumb.Link has an onClick prop (and no href), it will render as a button
*/
onClick?: (event: React.MouseEvent<ViewOwnProps, MouseEvent>) => void
/**
* Fires when the Link is hovered
*/
onMouseEnter?: (event: React.MouseEvent<ViewOwnProps, MouseEvent>) => void
/**
* Sets the font-size of the breadcrumb text
*/
Expand Down Expand Up @@ -82,6 +86,7 @@ const propTypes: PropValidators<PropKeys> = {
children: PropTypes.node.isRequired,
href: PropTypes.string,
onClick: PropTypes.func,
onMouseEnter: PropTypes.func,
size: PropTypes.oneOf(['small', 'medium', 'large']),
renderIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
iconPlacement: PropTypes.oneOf(['start', 'end'])
Expand All @@ -92,6 +97,7 @@ const allowedProps: AllowedPropKeys = [
'href',
'iconPlacement',
'onClick',
'onMouseEnter',
'renderIcon',
'size'
]
Expand Down
13 changes: 13 additions & 0 deletions packages/ui-link/src/Link/__tests__/Link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ describe('<Link />', async () => {
})
})

it('should call the onMouseEnter prop when mouseEntered', async () => {
const onMouseEnter = stub()
await mount(<Link onMouseEnter={onMouseEnter}>Hello World</Link>)

const link = await LinkLocator.find()

await link.mouseEnter()

await wait(() => {
expect(onMouseEnter).to.have.been.called()
})
})

it('should pass down an icon via the icon property', async () => {
const customIcon = (
<svg height="100" width="100">
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-link/src/Link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class Link extends Component<LinkProps, LinkState> {
const {
children,
onClick,
onMouseEnter,
color,
href,
margin,
Expand Down Expand Up @@ -241,6 +242,7 @@ class Link extends Component<LinkProps, LinkState> {
display={this.display}
margin={margin}
href={href}
onMouseEnter={onMouseEnter}
onClick={this.handleClick}
onFocus={this.handleFocus}
onBlur={this.handleBlur}
Expand Down
15 changes: 11 additions & 4 deletions packages/ui-link/src/Link/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ type LinkOwnProps = {
*/
isWithinText?: boolean

/**
* Fires when the Link loses focus
*/
onBlur?: (event: React.FocusEvent<ViewOwnProps>) => void

/**
* Fires when the Link is clicked
*/
Expand All @@ -123,9 +128,9 @@ type LinkOwnProps = {
onFocus?: (event: React.FocusEvent<ViewOwnProps>) => void

/**
* Fires when the Link loses focus
* Fires when the Link is hovered
*/
onBlur?: (event: React.FocusEvent<ViewOwnProps>) => void
onMouseEnter?: (event: React.MouseEvent<ViewOwnProps>) => void
}

export type LinkStyleProps = {
Expand Down Expand Up @@ -168,9 +173,10 @@ const propTypes: PropValidators<PropKeys> = {
'inline-flex'
]),
isWithinText: PropTypes.bool,
onBlur: PropTypes.func,
onClick: PropTypes.func,
onFocus: PropTypes.func,
onBlur: PropTypes.func
onMouseEnter: PropTypes.func
}

const allowedProps: AllowedPropKeys = [
Expand All @@ -187,9 +193,10 @@ const allowedProps: AllowedPropKeys = [
'iconPlacement',
'display',
'isWithinText',
'onBlur',
'onClick',
'onFocus',
'onBlur'
'onMouseEnter'
]

export type { LinkProps, LinkState, LinkStyle }
Expand Down

0 comments on commit 67b3b87

Please sign in to comment.