Skip to content

Commit

Permalink
[LinkV1] Simplify code to find child string of LinkV1 when setting a1…
Browse files Browse the repository at this point in the history
…1yLabel (#3859)

* Check if we find a string as a child before calling .toString()

* Change files

* Simplify code to find child string of LinkV1
  • Loading branch information
ksiler authored Feb 20, 2025
1 parent 0d66c8a commit 91d4ef1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Simplify code to find child string of LinkV1",
"packageName": "@fluentui-react-native/link",
"email": "krsiler@microsoft.com",
"dependentChangeType": "patch"
}
7 changes: 2 additions & 5 deletions packages/components/Link/src/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ export const Link = compose<LinkType>({
// Views in Text, we use that to handle interactions instead.
const supportsInteractionOnText = Platform.OS !== 'macos';

// Find the first child that's a string and save it to set as the link's
// Find the first child that's a string (if it exists) and save it to set as the link's
// accessibilityLabel if one isn't defined.
let linkA11yLabel = '';
linkA11yLabel = React.Children.toArray(children)
.find((child) => typeof child === 'string')
.toString();
const linkA11yLabel = React.Children.toArray(children).find((child) => typeof child === 'string');

return supportsA11yTextInText && supportsInteractionOnText && (inline || mergedProps.selectable) ? (
<Slots.content {...mergedProps}>{children}</Slots.content>
Expand Down

0 comments on commit 91d4ef1

Please sign in to comment.