Skip to content

Commit

Permalink
fix: Breadcrumb uses button when no href is present, tooltip labels b…
Browse files Browse the repository at this point in the history
…utton (#29803)
  • Loading branch information
smhigley authored Nov 9, 2023
1 parent f500d2b commit 506c225
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: use button when no href is defined",
"packageName": "@fluentui/react-breadcrumb-preview",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@fluentui/scripts-tasks": "*"
},
"dependencies": {
"@fluentui/react-aria": "^9.3.44",
"@fluentui/react-button": "^9.3.54",
"@fluentui/react-icons": "^2.0.217",
"@fluentui/react-link": "^9.1.33",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ describe('Breadcrumb', () => {
<li
class="fui-BreadcrumbItem"
>
<a
<button
class="fui-Button fui-BreadcrumbButton"
tabindex="0"
>
Item 1
</a>
</button>
</li>
</ol>
</nav>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ describe('BreadcrumbButton', () => {
const result = render(<BreadcrumbButton>Default BreadcrumbButton</BreadcrumbButton>);
expect(result.container).toMatchInlineSnapshot(`
<div>
<a
<button
class="fui-Button fui-BreadcrumbButton"
tabindex="0"
>
Default BreadcrumbButton
</a>
</button>
</div>
`);
});
Expand All @@ -42,9 +41,8 @@ describe('BreadcrumbButton', () => {
);
expect(result.container).toMatchInlineSnapshot(`
<div>
<a
<button
class="fui-Button fui-BreadcrumbButton"
tabindex="0"
>
<span
class="fui-Button__icon"
Expand All @@ -65,7 +63,7 @@ describe('BreadcrumbButton', () => {
</svg>
</span>
BreadcrumbButton with icon
</a>
</button>
</div>
`);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import type { ARIAButtonProps } from '@fluentui/react-aria';
import { useButton_unstable } from '@fluentui/react-button';
import type { ButtonProps } from '@fluentui/react-button';
import { useBreadcrumbContext_unstable } from '../Breadcrumb/BreadcrumbContext';
Expand All @@ -18,15 +19,17 @@ export const useBreadcrumbButton_unstable = (
ref: React.Ref<HTMLButtonElement | HTMLAnchorElement>,
): BreadcrumbButtonState => {
const { size } = useBreadcrumbContext_unstable();
const { current = false, ...rest } = props;
const { current = false, as, ...rest } = props;

const controlType = as ?? (props as ARIAButtonProps<'a'>).href ? 'a' : 'button';

return {
...useButton_unstable(
{
appearance: 'subtle',
role: undefined,
type: undefined,
as: 'a' as const,
as: controlType,
iconPosition: 'before',
'aria-current': current ? props['aria-current'] ?? 'page' : undefined,
'aria-disabled': current ? props['aria-disabled'] ?? true : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ function renderItem(entry: Item, isLastItem: boolean) {
return (
<React.Fragment key={`item-${entry.key}`}>
{isTruncatableBreadcrumbContent(entry.item, 30) ? (
<Tooltip withArrow content={truncateBreadcrumLongTooltip(entry.item)} relationship="label">
<BreadcrumbItem>
<BreadcrumbItem>
<Tooltip withArrow content={truncateBreadcrumLongTooltip(entry.item)} relationship="label">
<BreadcrumbButton current={isLastItem}>{truncateBreadcrumbLongName(entry.item)}</BreadcrumbButton>
</BreadcrumbItem>
</Tooltip>
</Tooltip>
</BreadcrumbItem>
) : (
<BreadcrumbItem>
<BreadcrumbButton current={isLastItem}>{entry.item}</BreadcrumbButton>
Expand Down

0 comments on commit 506c225

Please sign in to comment.