Skip to content

Commit

Permalink
fix(link): ensure button has a type when used
Browse files Browse the repository at this point in the history
Link component was used as a button currenly does not supply the button with a type. This has caused
a bug when `Pager` is used in a `Form`. The bug was causing the `onPrevious` callback function in
`Pager` to be called in an onClick event when the enter key pressed.

fixes #5676
  • Loading branch information
DipperTheDan committed Apr 17, 2023
1 parent 71b2d0c commit 065c206
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/components/link/link.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export const Link = React.forwardRef<
...ariaProps,
};

const buttonProps = {
type: "button",
};

const createLinkBasedOnType = () => {
let type = "a";

Expand All @@ -149,12 +153,18 @@ export const Link = React.forwardRef<

return React.createElement(
type,
{
...componentProps,
...(placeholderTabIndex &&
href === undefined &&
!onClick && { tabIndex: -1 }),
},
type === "button"
? {
...componentProps,
...buttonProps,
placeholderTabIndex,
}
: {
...componentProps,
...(placeholderTabIndex &&
href === undefined &&
!onClick && { tabIndex: -1 }),
},
<>
{renderLinkIcon()}

Expand Down

0 comments on commit 065c206

Please sign in to comment.