Skip to content

Commit

Permalink
fix: User-provided props win over defined defaults in Link component (m…
Browse files Browse the repository at this point in the history
…icrosoft#30062)

* fix: User-provided props win over defined defaults in Link component.

* Adding change file.

---------

Co-authored-by: Humberto Makoto Morimoto Burgos <[email protected]>
  • Loading branch information
khmakoto and Humberto Makoto Morimoto Burgos authored Dec 13, 2023
1 parent b6766ba commit 6fbf7dc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: User-provided props win over defined defaults in Link component.",
"packageName": "@fluentui/react-link",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ describe('Link', () => {

expect(link.getAttribute('tabIndex')).toBe('-1');
});

it('allows overriding "role"', () => {
const result = render(
<Link href="https://www.bing.com" role="button">
This is a link
</Link>,
);
expect(result.queryAllByRole('link')).toHaveLength(0);
expect(result.queryAllByRole('button')).toHaveLength(1);
});
});

describe('when rendered as a button', () => {
Expand Down Expand Up @@ -120,5 +130,15 @@ describe('Link', () => {

expect(button.getAttribute('tabIndex')).toBe('-1');
});

it('allows overriding "role"', () => {
const result = render(
<Link href="https://www.bing.com" role="presentation">
This is a link
</Link>,
);
expect(result.queryAllByRole('link')).toHaveLength(0);
expect(result.queryAllByRole('presentation')).toHaveLength(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export const useLink_unstable = (

// Casting is required here as `as` prop would break the union between `a`, `button` and `span` types
const propsWithAssignedAs = {
...props,
as: elementType,
role: elementType === 'span' ? 'button' : undefined,
type: elementType === 'button' ? 'button' : undefined,
...props,
as: elementType,
} as LinkProps;

const state: LinkState = {
Expand Down

0 comments on commit 6fbf7dc

Please sign in to comment.