Link

With links, users can navigate seamlessly throughout a website. This component has a hyperlinked appearance for a user-friendly experience.
Installation
API Reference
Spec Doc
This is an illustration of Link component.
<Link href="https://gluestack.io/">
<LinkText>gluestack</LinkText>
</Link>

Installation

Step 1: Install the following dependencies:

npm i @gluestack-ui/link

Step 2: Copy and paste the following code into your project.

import { createLink } from "@gluestack-ui/link"
import { Pressable, Text, Platform } from "react-native"
import {
tva,
withStyleContextAndStates,
withStyleContext,
} from "@gluestack-ui/nativewind-utils"
import React from "react"
import { cssInterop } from "nativewind"
export const UILink = createLink({
// @ts-ignore
Root:
Platform.OS === "web"
? withStyleContext(Pressable)
: withStyleContextAndStates(Pressable),
Text: Text,
})
cssInterop(UILink, { className: "style" })
cssInterop(UILink.Text, { className: "style" })
const linkStyle = tva({
base: "web:outline-0 web:disabled:cursor-not-allowed web:focus-visible:outline-2 web:focus-visible:outline-primary-700 web:focus-visible:outline",
})
const linkTextStyle = tva({
base: "underline text-info-700 hover:text-info-600 hover:no-underline active:text-info-700 disabled:opacity-40",
})
export const Link = React.forwardRef(({ className, ...props }: any, ref) => {
return (
<UILink
ref={ref}
className={linkStyle({ class: className })}
context={{}}
/>
)
})
export const LinkText = React.forwardRef(
({ className, ...props }: any, ref) => {
return (
<UILink.Text
ref={ref}
{...props}
className={linkTextStyle({
class: className,
})}
/>
)
}
)

Step 3: Update the import paths to match your project setup.

API Reference

To use this component in your project, include the following import statement in your file.
import { Link } from "@/components/ui/Link"
export default () => (
<Link>
<LinkText />
</Link>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.
Contains all link related layout style props and actions. It inherits all the properties of React Native's Pressable component.
Prop
Type
Default
Description
href
string
-
URL that should be opened on Link press.
onPress
(event?: GestureResponderEvent) => any
-
Callback that will be invoked on Link press.
isExternal
boolean
false
If true, link will be opened in new tab on web. It uses _target property to achieve this.
isHovered
boolean
false
When true, the link displays a hover state.
isFocusVisible
boolean
false
To manually set focus visible state to the link.

LinkText

Contains all text related layout style props and actions. It inherits all the properties of React Native's Text component.

Accessibility

We have outlined the various features that ensure the Link component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards. Adheres to the WAI-ARIA design pattern.

Keyboard

  • Tab: Moves focus to the next focusable element.
  • Enter: Users should be able to open a link.

Screen Reader

  • VoiceOver: When a link receives focus, screen readers should announce a descriptive link name.

Props

Link component is created using Pressable component from react-native. It extends all the props supported by React Native Pressable.
Edit this page on GitHub