# React Native Link

> An accessible React Native Link for iOS, Android and the web: a real anchor on the web, opens the browser on native, external links in a new tab with ↗, underlined as each platform does it.

# Link

A text link, inline in a sentence or on its own. With `href` it's a real `<a>` on the web, so people can open it in a new tab or copy its address, and it opens the browser on iOS and Android. For an action that isn't navigation, use a [Button](./button).

```tsx
import { Link } from 'patine-ui';
```

```tsx live
import { Box, Link, Text } from 'patine-ui';

export default function Example() {
  return (
    <Box padding="lg" border radius="lg" gap="sm" style={{ maxWidth: 420 }}>
      <Text weight="semibold">Almost there</Text>
      <Text color="textSecondary">
        By creating an account you agree to our <Link href="https://patine.dev/terms">Terms of Service</Link> and{' '}
        <Link href="https://patine.dev/privacy">Privacy Policy</Link>.
      </Text>
      <Link href="https://status.patine.dev" external size="sm">
        System status
      </Link>
    </Box>
  );
}
```

## Example: a sign-in form's links

A sign-in card has three kinds of link: one that acts inside the app (Forgot password), one that goes to another page (Create an account), and one that leaves for another site, marked external.

```tsx live
import { useState } from 'react';
import { Box, Button, HStack, Link, Text, TextField } from 'patine-ui';

export default function Example() {
  const [reset, setReset] = useState(false);
  return (
    <Box border radius="lg" padding="lg" gap="md" style={{ width: '100%', maxWidth: 380 }}>
      <Text size="lg" weight="semibold">Sign in to Ledger</Text>
      <TextField label="Email" defaultValue="maya@example.com" autoCapitalize="none" />
      <TextField label="Password" secureTextEntry />
      <Link onPress={() => setReset(true)} size="sm">
        Forgot password?
      </Link>
      {reset ? <Text size="sm" color="success">We sent a reset link to maya@example.com.</Text> : null}
      <Button>Sign in</Button>
      <HStack gap="xs" wrap justify="center">
        <Text size="sm" color="textSecondary">New here?</Text>
        <Link href="/docs/components/link" size="sm">
          Create an account
        </Link>
      </HStack>
      <Link href="https://status.example.com" external size="sm" style={{ alignSelf: 'center' }}>
        Service status
      </Link>
    </Box>
  );
}
```

## Routing it yourself

Give `onPress` to navigate inside the app. To keep `href` from opening (for example, to use your router but keep the address on the web), call `event.preventDefault()` in `onPress`.

## Designs

iOS tints links without a line. Material underlines them. brand and the web underline on hover, as shadcn does. `underline` overrides it: `'always'`, `'hover'` or `'none'`.

## Accessibility

- A `link` role, named by its text. On the web it's an anchor, reached with Tab and opened with Enter.
- `external` adds ↗ and opens a new tab with `rel="noopener noreferrer"`.
- Color isn't the only cue where it matters: use `underline="always"` for links inside body text if your primary color is close to the text color.

## Props

Also takes [Text](./text) props: `size`, `weight`, `numberOfLines`…

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | — | The link text. |
| `href` | `string` | — | A URL to open. |
| `onPress` | `(event) => void` | — | Called on press; `preventDefault()` keeps `href` from opening. |
| `external` | `boolean` | `false` | New tab on the web, and a ↗. |
| `underline` | `'always' \| 'hover' \| 'none'` | the design's | When to underline. |
| `disabled` | `boolean` | `false` | Grays it and ignores presses. |
| `theme`, `design` | | | As every component. |
