Skip to content

Commit 2f291a4

Browse files
authored
[LinkV1] Remove text from Link a11y tree and add a11yLabel (#3856)
* Remove text from Link a11y tree and add a11yLabel * add LinkV1 to macOS test pages * Change files * undo yarn.lock changes * restore yarn.lock * update link snapshots
1 parent 6a01667 commit 2f291a4

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

apps/fluent-tester/src/testPages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export const tests: TestDescription[] = [
185185
name: 'Link V1',
186186
component: LinkV1Test,
187187
testPageButton: Constants.HOMEPAGE_LINKV1_BUTTON,
188-
platforms: ['win32', 'android', 'windows'],
188+
platforms: ['macos', 'win32', 'android', 'windows'],
189189
},
190190
{
191191
name: 'Menu',
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Remove text from Link a11y tree and add a11yLabel",
4+
"packageName": "@fluentui-react-native/link",
5+
"email": "[email protected]",
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": "add LinkV1 to macOS test pages",
4+
"packageName": "@fluentui-react-native/tester",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/components/Link/src/Link.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @jsxRuntime classic */
22
/** @jsx withSlots */
3+
import React from 'react';
34
import { Platform, View } from 'react-native';
45

56
import type { UseSlots } from '@fluentui-react-native/framework';
@@ -48,11 +49,20 @@ export const Link = compose<LinkType>({
4849
// Views in Text, we use that to handle interactions instead.
4950
const supportsInteractionOnText = Platform.OS !== 'macos';
5051

52+
// Find the first child that's a string and save it to set as the link's
53+
// accessibilityLabel if one isn't defined.
54+
let linkA11yLabel = '';
55+
linkA11yLabel = React.Children.toArray(children)
56+
.find((child) => typeof child === 'string')
57+
.toString();
58+
5159
return supportsA11yTextInText && supportsInteractionOnText && (inline || mergedProps.selectable) ? (
5260
<Slots.content {...mergedProps}>{children}</Slots.content>
5361
) : (
54-
<Slots.root {...mergedProps}>
55-
<Slots.content focusable={false}>{children}</Slots.content>
62+
<Slots.root {...mergedProps} accessibilityLabel={mergedProps.accessibilityLabel ?? linkA11yLabel}>
63+
<Slots.content focusable={false} accessible={false}>
64+
{children}
65+
</Slots.content>
5666
</Slots.root>
5767
);
5868
};

packages/components/Link/src/__tests__/__snapshots__/Link.test.tsx.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`Link component tests Default Link 1`] = `
44
<View
5+
accessibilityLabel="Link to Bing"
56
accessibilityRole="link"
67
accessibilityState={
78
{
@@ -31,6 +32,7 @@ exports[`Link component tests Default Link 1`] = `
3132
tooltip="https://www.bing.com"
3233
>
3334
<Text
35+
accessible={false}
3436
ellipsizeMode="tail"
3537
focusable={false}
3638
numberOfLines={0}
@@ -52,6 +54,7 @@ exports[`Link component tests Default Link 1`] = `
5254

5355
exports[`Link component tests Default Link as a pressable 1`] = `
5456
<View
57+
accessibilityLabel="Link to Bing"
5558
accessibilityRole="link"
5659
accessibilityState={
5760
{
@@ -80,6 +83,7 @@ exports[`Link component tests Default Link as a pressable 1`] = `
8083
}
8184
>
8285
<Text
86+
accessible={false}
8387
ellipsizeMode="tail"
8488
focusable={false}
8589
numberOfLines={0}
@@ -101,6 +105,7 @@ exports[`Link component tests Default Link as a pressable 1`] = `
101105

102106
exports[`Link component tests Inline Link 1`] = `
103107
<View
108+
accessibilityLabel="Link to Bing"
104109
accessibilityRole="link"
105110
accessibilityState={
106111
{
@@ -130,6 +135,7 @@ exports[`Link component tests Inline Link 1`] = `
130135
tooltip="https://www.bing.com"
131136
>
132137
<Text
138+
accessible={false}
133139
ellipsizeMode="tail"
134140
focusable={false}
135141
numberOfLines={0}
@@ -152,6 +158,7 @@ exports[`Link component tests Inline Link 1`] = `
152158

153159
exports[`Link component tests Subtle Link 1`] = `
154160
<View
161+
accessibilityLabel="Link to Bing"
155162
accessibilityRole="link"
156163
accessibilityState={
157164
{
@@ -182,6 +189,7 @@ exports[`Link component tests Subtle Link 1`] = `
182189
tooltip="https://www.bing.com"
183190
>
184191
<Text
192+
accessible={false}
185193
ellipsizeMode="tail"
186194
focusable={false}
187195
numberOfLines={0}

0 commit comments

Comments
 (0)