Skip to content

Commit 0ecaf6f

Browse files
Copilotmattcosta7francineluccaprimer[bot]
authored
fix(Link): destructure muted prop to prevent unintentional DOM attribute leakage (#7631)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mattcosta7 <8616962+mattcosta7@users.noreply.github.com> Co-authored-by: Marie Lucca <40550942+francinelucca@users.noreply.github.com> Co-authored-by: primer[bot] <119360173+primer[bot]@users.noreply.github.com> Co-authored-by: Matthew Costabile <mattcosta7@github.com>
1 parent 91bf343 commit 0ecaf6f

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

.changeset/tame-lions-blend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
Add test to validate that the `muted` prop is not leaked as a bare DOM attribute on `Link`

packages/react/src/Link/Link.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const UnwrappedLink = <As extends React.ElementType = 'a'>(
1818
props: PolymorphicProps<As, 'a', StyledLinkProps>,
1919
ref: ForwardedRef<unknown>,
2020
) => {
21-
const {as: Component = 'a', className, inline, hoverColor, ...restProps} = props
21+
const {as: Component = 'a', className, inline, muted, hoverColor, ...restProps} = props
2222
const innerRef = React.useRef<ElementRef<As>>(null)
2323
useRefObjectAsForwardedRef(ref, innerRef)
2424

@@ -49,7 +49,7 @@ export const UnwrappedLink = <As extends React.ElementType = 'a'>(
4949
return (
5050
<Component
5151
className={clsx(className, classes.Link)}
52-
data-muted={restProps.muted}
52+
data-muted={muted}
5353
data-inline={inline}
5454
data-hover-color={hoverColor}
5555
{...restProps}

packages/react/src/Link/__tests__/Link.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('Link', () => {
2525
it('respects the "muted" prop', () => {
2626
const {container} = render(<Link muted />)
2727
expect(container.firstChild).toHaveAttribute('data-muted', 'true')
28+
expect(container.firstChild).not.toHaveAttribute('muted')
2829
})
2930

3031
it('logs a warning when trying to render invalid "as" prop', () => {

0 commit comments

Comments
 (0)