Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
Comment thread
dmytrokirpa marked this conversation as resolved.
"type": "patch",
"comment": "fix: make BreadcrumbButtonBaseProps distribute over the ARIA button union so the anchor arm's href stays assignable",
"packageName": "@fluentui/react-breadcrumb",
"email": "array.knight@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { ButtonSlots } from '@fluentui/react-button';
import type { ButtonState } from '@fluentui/react-button';
import type { ComponentProps } from '@fluentui/react-utilities';
import type { ComponentState } from '@fluentui/react-utilities';
import type { DistributiveOmit } from '@fluentui/react-utilities';
import type { ForwardRefComponent } from '@fluentui/react-utilities';
import type { JSXElement } from '@fluentui/react-utilities';
import * as React_2 from 'react';
Expand All @@ -29,7 +30,7 @@ export type BreadcrumbBaseState = Omit<BreadcrumbState, 'size'>;
export const BreadcrumbButton: ForwardRefComponent<BreadcrumbButtonProps>;

// @public (undocumented)
export type BreadcrumbButtonBaseProps = Omit<BreadcrumbButtonProps, 'size'>;
export type BreadcrumbButtonBaseProps = DistributiveOmit<BreadcrumbButtonProps, 'size'>;

// @public (undocumented)
export type BreadcrumbButtonBaseState = Omit<BreadcrumbButtonState, 'appearance' | 'size' | 'shape'>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { render } from '@testing-library/react';
import { BreadcrumbButton } from './BreadcrumbButton';
import type { BreadcrumbButtonProps } from './BreadcrumbButton.types';
import type { BreadcrumbButtonBaseProps, BreadcrumbButtonProps } from './BreadcrumbButton.types';
import { isConformant } from '../../testing/isConformant';
import { breadcrumbButtonClassNames } from './useBreadcrumbButtonStyles.styles';
import { ArrowRight16Filled } from '@fluentui/react-icons';
Expand Down Expand Up @@ -67,4 +67,20 @@ describe('BreadcrumbButton', () => {
</div>
`);
});

// Type-level regression test for https://github.com/microsoft/fluentui/issues/36645.
// `BreadcrumbButtonBaseProps` used a plain `Omit`, which collapsed the distributive ARIA button
// union and dropped the anchor arm's `href`. These assignments are validated by the package's
// type-check target.
it('keeps both arms of the ARIA button union assignable to BreadcrumbButtonBaseProps', () => {
const anchorProps: BreadcrumbButtonBaseProps = { as: 'a', href: '/somewhere' };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apologies for the confusion, but could we test the base hook with needed args, something like:

const { result } = renderHook(() => useBreadcrumbButtonBase({ as: 'a', href: '/somewhere' })

expect(result.current).toMatchObject({
  components: { root: 'a' },
  root: { href: '/somewhere' }
})

it will cover both base hook and types, as we run typecheck against tests as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6c355b2 — reworked to the renderHook shape. One adjustment from your sketch: components.root stays 'button' (the slot's declared default element type in useButtonBase); the anchor arm resolves through the slot props, where useARIAButtonProps carries as: 'a' to the render layer. So the assertion pins root: { as: 'a', href: '/somewhere' }, which is the field that actually witnesses the anchor path. 108/108 green.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets clean up the unnecessary comments in tests and should be good to go.

thank you!

const buttonProps: BreadcrumbButtonBaseProps = { as: 'button' };

// @ts-expect-error - `size` is omitted from BreadcrumbButtonBaseProps
const sizeProps: BreadcrumbButtonBaseProps = { as: 'button', size: 'small' };

expect(anchorProps).toBeDefined();
expect(buttonProps).toBeDefined();
expect(sizeProps).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ComponentProps, ComponentState } from '@fluentui/react-utilities';
import type { ComponentProps, ComponentState, DistributiveOmit } from '@fluentui/react-utilities';
import type { ButtonProps, ButtonSlots, ButtonState } from '@fluentui/react-button';
import type { BreadcrumbProps } from '../Breadcrumb/Breadcrumb.types';

Expand All @@ -25,6 +25,6 @@ export type BreadcrumbButtonState = ComponentState<BreadcrumbButtonSlots> &
Omit<ButtonState, keyof ButtonSlots | 'components'> &
Required<Pick<BreadcrumbButtonProps, 'current' | 'size'>>;

export type BreadcrumbButtonBaseProps = Omit<BreadcrumbButtonProps, 'size'>;
export type BreadcrumbButtonBaseProps = DistributiveOmit<BreadcrumbButtonProps, 'size'>;
Comment thread
dmytrokirpa marked this conversation as resolved.

export type BreadcrumbButtonBaseState = Omit<BreadcrumbButtonState, 'appearance' | 'size' | 'shape'>;
Loading