Skip to content

Commit 4fb4983

Browse files
mainframevviktorgenaevlayershifter
authored
fix(react-message-bar): force links to be underlined (#32850)
Co-authored-by: viktorgenaev <viktorgenaev@microsoft.com> Co-authored-by: Oleksandr Fediashov <alexander.mcgarret@gmail.com>
1 parent 536af62 commit 4fb4983

File tree

14 files changed

+86
-6
lines changed

14 files changed

+86
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "feat: add LinkContextProvider",
4+
"packageName": "@fluentui/react-link",
5+
"email": "vgenaev@gmail.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix: use LinkContextProvider to force all links inside MessageBody to be underlined",
4+
"packageName": "@fluentui/react-message-bar",
5+
"email": "vgenaev@gmail.com",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-link/library/etc/react-link.api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ export const Link: ForwardRefComponent<LinkProps>;
1818
// @public (undocumented)
1919
export const linkClassNames: SlotClassNames<LinkSlots>;
2020

21+
// @public (undocumented)
22+
export const linkContextDefaultValue: LinkContextValue;
23+
24+
// @public (undocumented)
25+
export const LinkContextProvider: React_2.Provider<LinkContextValue | undefined>;
26+
27+
// @public (undocumented)
28+
export type LinkContextValue = {
29+
inline?: boolean;
30+
};
31+
2132
// @public (undocumented)
2233
export type LinkProps = ComponentProps<LinkSlots> & {
2334
appearance?: 'default' | 'subtle';
@@ -42,6 +53,9 @@ export const renderLink_unstable: (state: LinkState) => JSX.Element;
4253
// @public
4354
export const useLink_unstable: (props: LinkProps, ref: React_2.Ref<HTMLAnchorElement | HTMLButtonElement | HTMLSpanElement>) => LinkState;
4455

56+
// @public (undocumented)
57+
export const useLinkContext: () => LinkContextValue;
58+
4559
// @public
4660
export const useLinkState_unstable: (state: LinkState) => LinkState;
4761

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './components/Link/index';
2+
export * from './contexts';

packages/react-components/react-link/library/src/components/Link/useLink.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
33
import { useBackgroundAppearance } from '@fluentui/react-shared-contexts';
44
import { useLinkState_unstable } from './useLinkState';
55
import type { LinkProps, LinkState } from './Link.types';
6+
import { useLinkContext } from '../../contexts/linkContext';
67

78
/**
89
* Given user props, defines default props for the Link, calls useLinkState_unstable, and returns processed state.
@@ -14,6 +15,7 @@ export const useLink_unstable = (
1415
ref: React.Ref<HTMLAnchorElement | HTMLButtonElement | HTMLSpanElement>,
1516
): LinkState => {
1617
const backgroundAppearance = useBackgroundAppearance();
18+
const { inline: inlineContext } = useLinkContext();
1719
const { appearance = 'default', disabled = false, disabledFocusable = false, inline = false } = props;
1820

1921
const elementType = props.as || (props.href ? 'a' : 'button');
@@ -31,7 +33,7 @@ export const useLink_unstable = (
3133
appearance,
3234
disabled,
3335
disabledFocusable,
34-
inline,
36+
inline: inline ?? !!inlineContext,
3537

3638
// Slots definition
3739
components: {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './linkContext';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as React from 'react';
2+
3+
export type LinkContextValue = {
4+
inline?: boolean;
5+
};
6+
7+
const LinkContext = React.createContext<LinkContextValue | undefined>(undefined);
8+
9+
export const linkContextDefaultValue: LinkContextValue = {
10+
inline: false,
11+
};
12+
13+
export const LinkContextProvider = LinkContext.Provider;
14+
export const useLinkContext = () => React.useContext(LinkContext) ?? linkContextDefaultValue;

packages/react-components/react-link/library/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ export {
77
useLink_unstable,
88
} from './Link';
99
export type { LinkProps, LinkSlots, LinkState } from './Link';
10+
export { linkContextDefaultValue, LinkContextProvider, useLinkContext } from './contexts';
11+
export type { LinkContextValue } from './contexts';

packages/react-components/react-message-bar/library/etc/react-message-bar.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export const renderMessageBar_unstable: (state: MessageBarState, contexts: Messa
163163
export const renderMessageBarActions_unstable: (state: MessageBarActionsState, contexts: MessageBarActionsContextValues) => JSX.Element;
164164

165165
// @public
166-
export const renderMessageBarBody_unstable: (state: MessageBarBodyState) => JSX.Element;
166+
export const renderMessageBarBody_unstable: (state: MessageBarBodyState, contextValues: MessageBarBodyContextValues) => JSX.Element;
167167

168168
// @public
169169
export const renderMessageBarGroup_unstable: (state: MessageBarGroupState) => JSX.Element;

packages/react-components/react-message-bar/library/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@fluentui/react-icons": "^2.0.245",
3535
"@fluentui/react-jsx-runtime": "^9.0.44",
3636
"@fluentui/react-shared-contexts": "^9.20.1",
37+
"@fluentui/react-link": "^9.2.32",
3738
"@fluentui/react-theme": "^9.1.20",
3839
"@fluentui/react-utilities": "^9.18.15",
3940
"@griffel/react": "^1.5.22",

0 commit comments

Comments
 (0)