Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions change/@fluentui-react-link-no-native-props-filter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: pass root props through without the native props allow-list to reduce bundle size",
"packageName": "@fluentui/react-link",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,38 @@ describe('Link', () => {
});
});
});

describe('Link DOM attributes', () => {
it('does not render component props as DOM attributes', () => {
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => undefined);
const { container } = render(
<Link appearance="subtle" disabledFocusable href="https://www.bing.com" inline>
Link
</Link>,
);

expect(consoleError).not.toHaveBeenCalled();
consoleError.mockRestore();
expect((container.firstElementChild as HTMLElement).getAttributeNames().sort()).toEqual([
'aria-disabled',
'class',
'href',
'role',
'tabindex',
]);
});

it('does not render disabled on an anchor', () => {
const { container } = render(
<Link disabled href="https://www.bing.com">
Link
</Link>,
);

expect((container.firstElementChild as HTMLElement).getAttributeNames().sort()).toEqual([
'aria-disabled',
'class',
'role',
]);
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import type * as React from 'react';
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
import { slot } from '@fluentui/react-utilities';
import { useBackgroundAppearance } from '@fluentui/react-shared-contexts';
import { useLinkState_unstable } from './useLinkState';
import type { LinkBaseProps, LinkBaseState, LinkProps, LinkState } from './Link.types';
Expand Down Expand Up @@ -41,15 +41,15 @@ export const useLinkBase_unstable = (
props: LinkBaseProps,
ref: React.Ref<HTMLAnchorElement | HTMLButtonElement | HTMLSpanElement>,
): LinkBaseState => {
const { disabled = false, disabledFocusable = false } = props;
const { disabled = false, disabledFocusable = false, ...rest } = props;

const elementType = props.as || (props.href ? 'a' : 'button');

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

Expand All @@ -64,10 +64,10 @@ export const useLinkBase_unstable = (
},

root: slot.always(
getIntrinsicElementProps<LinkBaseProps>(elementType, {
{
ref,
...propsWithAssignedAs,
} as const),
} as LinkBaseState['root'],
{ elementType },
),
};
Expand Down
Loading