Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
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-avatar-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-avatar",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@fluentui-react-breadcrumb-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-breadcrumb",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@fluentui-react-card-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-card",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
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-headless-components-preview",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@fluentui-react-infolabel-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-infolabel",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
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"
}
7 changes: 7 additions & 0 deletions change/@fluentui-react-progress-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-progress",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@fluentui-react-provider-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-provider",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@fluentui-react-rating-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-rating",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@fluentui-react-spinner-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-spinner",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@fluentui-react-text-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-text",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@fluentui-react-toolbar-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-toolbar",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { AvatarGroup } from './AvatarGroup';
import { AvatarGroupItem } from '../AvatarGroupItem';
import { isConformant } from '../../testing/isConformant';
import { AvatarGroupPopover } from '../AvatarGroupPopover/AvatarGroupPopover';
import { render, screen } from '@testing-library/react';
import { render, screen, renderHook } from '@testing-library/react';
import { useAvatarGroupBase_unstable } from './useAvatarGroup';

describe('AvatarGroup', () => {
isConformant({
Expand Down Expand Up @@ -48,3 +49,22 @@ describe('AvatarGroup', () => {
expect(screen.getByRole('button').textContent).toBe('');
});
});

describe('AvatarGroup DOM attributes', () => {
it('does not render component props as DOM attributes', () => {
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => undefined);
const { container } = render(<AvatarGroup layout="stack" size={40} />);

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

describe('useAvatarGroupBase_unstable base hook', () => {
it('does not forward component props to the root slot', () => {
const { result } = renderHook(() => useAvatarGroupBase_unstable({ layout: 'pie' }, React.createRef()));

expect(result.current.root).not.toHaveProperty('layout');
});
});
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 type {
AvatarGroupBaseProps,
AvatarGroupBaseState,
Expand Down Expand Up @@ -38,14 +38,14 @@ export const useAvatarGroupBase_unstable = (
props: AvatarGroupBaseProps,
ref: React.Ref<HTMLDivElement>,
): AvatarGroupBaseState => {
const { layout = 'spread' } = props;
const { layout = 'spread', ...rest } = props;

const root = slot.always(
getIntrinsicElementProps('div', {
{
role: 'group',
...props,
...rest,
ref,
}),
},
{ elementType: 'div' },
);
return { layout, components: { root: 'div' }, root };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,18 @@ describe('Breadcrumb', () => {
`);
});
});

describe('Breadcrumb DOM attributes', () => {
it('does not render component props as DOM attributes', () => {
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => undefined);
const { container } = render(<Breadcrumb focusMode="arrow" size="large" />);

expect(consoleError).not.toHaveBeenCalled();
consoleError.mockRestore();
expect((container.firstElementChild as HTMLElement).getAttributeNames().sort()).toEqual([
'aria-label',
'class',
'data-tabster',
]);
});
});
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 type { BreadcrumbBaseProps, BreadcrumbBaseState, BreadcrumbProps, BreadcrumbState } from './Breadcrumb.types';
import type { TabsterDOMAttribute } from '@fluentui/react-tabster';
import { useArrowNavigationGroup } from '@fluentui/react-tabster';
Expand Down Expand Up @@ -50,11 +50,11 @@ export const useBreadcrumbBase_unstable = (
list: 'ol',
},
root: slot.always(
getIntrinsicElementProps('nav', {
{
ref,
'aria-label': props['aria-label'] ?? 'breadcrumb',
...rest,
}),
},
{ elementType: 'nav' },
),
list: slot.optional(list, { renderByDefault: true, defaultProps: { role: 'list' }, elementType: 'ol' }),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import * as React from 'react';
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
import { slot } from '@fluentui/react-utilities';
import type {
BreadcrumbDividerBaseProps,
BreadcrumbDividerBaseState,
Expand Down Expand Up @@ -55,11 +55,11 @@ export const useBreadcrumbDividerBase_unstable = (
root: 'li',
},
root: slot.always(
getIntrinsicElementProps('li', {
{
ref,
'aria-hidden': true,
...props,
}),
},
{ elementType: 'li' },
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,14 @@ describe('BreadcrumbItem', () => {
`);
});
});

describe('BreadcrumbItem DOM attributes', () => {
it('does not render component props as DOM attributes', () => {
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => undefined);
const { container } = render(<BreadcrumbItem size="large" />);

expect(consoleError).not.toHaveBeenCalled();
consoleError.mockRestore();
expect((container.firstElementChild as HTMLElement).getAttributeNames().sort()).toEqual(['class']);
});
});
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 type {
BreadcrumbItemBaseProps,
BreadcrumbItemBaseState,
Expand All @@ -24,7 +24,9 @@ export const useBreadcrumbItem_unstable = (
ref: React.Ref<HTMLLIElement>,
): BreadcrumbItemState => {
const { size } = useBreadcrumbContext_unstable();
const state = useBreadcrumbItemBase_unstable(props, ref);
// `size` comes from the Breadcrumb context, the prop is not a DOM attribute.
const { size: _size, ...baseProps } = props;
const state = useBreadcrumbItemBase_unstable(baseProps, ref);

return {
...state,
Expand All @@ -46,10 +48,10 @@ export const useBreadcrumbItemBase_unstable = (
return {
components: { root: 'li' },
root: slot.always(
getIntrinsicElementProps('li', {
{
ref,
...props,
}),
},
{ elementType: 'li' },
),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as React from 'react';
import '@testing-library/jest-dom';
import { render, fireEvent } from '@testing-library/react';
import { render, fireEvent, renderHook } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { isConformant } from '../../testing/isConformant';

import { Card } from './Card';
import type { CardProps } from './Card.types';
import { cardClassNames } from './useCardStyles.styles';
import { useCardBase_unstable } from './useCard';

describe('Card', () => {
isConformant<CardProps>({
Expand Down Expand Up @@ -149,3 +150,51 @@ describe('Card', () => {
expect(getByTestId('card').getAttribute('tabindex')).toBeNull();
});
});

describe('Card DOM attributes', () => {
it('does not render component props as DOM attributes', () => {
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => undefined);
const { container } = render(
<Card
appearance="outline"
defaultSelected
focusMode="off"
onSelectionChange={jest.fn()}
orientation="horizontal"
size="large"
/>,
);

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

describe('useCardBase_unstable base hook', () => {
it('does not forward component props to the root slot', () => {
const { result } = renderHook(() =>
useCardBase_unstable(
{
checkbox: {},
defaultSelected: true,
disabled: false,
floatingAction: {},
focusMode: 'off',
onSelectionChange: jest.fn(),
shouldRestrictTriggerAction: () => false,
},
React.createRef(),
),
);

expect(result.current.root).not.toHaveProperty('checkbox');
expect(result.current.root).not.toHaveProperty('defaultSelected');
expect(result.current.root).not.toHaveProperty('disabled');
expect(result.current.root).not.toHaveProperty('floatingAction');
expect(result.current.root).not.toHaveProperty('focusMode');
expect(result.current.root).not.toHaveProperty('onSelectionChange');
expect(result.current.root).not.toHaveProperty('selected');
expect(result.current.root).not.toHaveProperty('shouldRestrictTriggerAction');
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import * as React from 'react';
import { getIntrinsicElementProps, useMergedRefs, slot } from '@fluentui/react-utilities';
import { useMergedRefs, slot } from '@fluentui/react-utilities';
import { useFocusableGroup, useFocusFinders, useFocusWithin } from '@fluentui/react-tabster';

import type { CardBaseProps, CardBaseState, CardOnSelectionChangeEvent, CardProps, CardState } from './Card.types';
Expand Down Expand Up @@ -119,7 +119,17 @@ export const useCard_unstable = (props: CardProps, ref: React.Ref<HTMLDivElement
* @param options - optional behavior overrides such as a focus-aware restriction predicate
*/
export const useCardBase_unstable = (props: CardBaseProps, ref: React.Ref<HTMLDivElement>): CardBaseState => {
const { disabled = false, ...restProps } = props;
const {
disabled = false,
focusMode,
selected: selectedProp,
defaultSelected,
onSelectionChange,
shouldRestrictTriggerAction,
floatingAction,
checkbox,
...restProps
} = props;

const [referenceId, setReferenceId] = React.useState(cardContextDefaultValue.selectableA11yProps.referenceId);
const [referenceLabel, setReferenceLabel] = React.useState(cardContextDefaultValue.selectableA11yProps.referenceId);
Expand Down Expand Up @@ -162,11 +172,11 @@ export const useCardBase_unstable = (props: CardBaseProps, ref: React.Ref<HTMLDi
},

root: slot.always(
getIntrinsicElementProps('div', {
{
ref,
role: 'group',
...cardRootProps,
}),
},
{ elementType: 'div' },
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ describe('CardFooter', () => {
expect(result.container).toMatchSnapshot();
});
});

describe('CardFooter DOM attributes', () => {
it('does not render component props as DOM attributes', () => {
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => undefined);
const { container } = render(<CardFooter action={<button />} />);

expect(consoleError).not.toHaveBeenCalled();
consoleError.mockRestore();
expect((container.firstElementChild as HTMLElement).getAttributeNames().sort()).toEqual(['class']);
});
});
Loading
Loading