A
A link to somewhere else, inline in a sentence or on its own. Use `asChild` to pass it a router link.
compliant
- Overview
- Props
- Figma
Basic usage​
Inline usage​
You can use links inline.
Usage with router libraries​
Web: react-router​
It can easily be used with react-router by relying on the asChild prop:
import { A } from "murray";
import { Link } from "react-router-dom";
const Component = () => {
return (
<A asChild>
<Link to="/somepage?id=foo">Go somewhere</Link>
</A>
);
};
Mobile: @react-navigation/native​
It can easily be used with @react-navigation/native by relying on onPress:
import { A } from "murray";
const Component = () => {
const { navigate } = useNavigation();
return <A onPress={() => navigate("SomeScreen", { id: "foo" })}>Go somewhere</A>;
};
Accessibility​
Adheres to the WAI-ARIA Link Pattern
The href, onPress, and asChild props are mutually exclusive by design to ensure proper accessibility semantics. You must provide exactly one of these props.
Edge case: Using href and onPress together
In rare cases where you need both href and onPress (typically for tracking purposes), you can use them together by explicitly disabling TypeScript's type checking with @ts-expect-error:
import { A } from "murray";
import type { GestureResponderEvent } from "react-native";
const Component = () => {
const handleTracking = (e: GestureResponderEvent | KeyboardEvent) => {
// In a web context, Prevent default navigation to ensure onPress completes before page change
// This is critical: without preventDefault, the browser will navigate immediately,
// potentially interrupting your tracking or async operations
if (e && "preventDefault" in e) {
e.preventDefault();
}
// Track link click (this may be async)
analytics.track("link_clicked");
// Optionally navigate programmatically after tracking completes
// window.location.href = "/some-page";
};
return (
<A
href="/some-page"
// @ts-expect-error - href and onPress are mutually exclusive
onPress={handleTracking}
>
Tracked link
</A>
);
};
Important: When using both href and onPress, the onPress handler must intercept the event and call preventDefault() to avoid the page navigation happening before onPress finishes executing. Without this, the browser will navigate immediately, potentially interrupting your tracking or other async operations.
Event types on web:
- For mouse clicks:
GestureResponderEvent(Tamagui wraps the underlying DOMMouseEventfor cross-platform consistency) - For keyboard events (Enter key):
KeyboardEvent
The GestureResponderEvent type definition doesn't include preventDefault() in its signature, but on web the actual event object does have this method. Always check for preventDefault availability before calling it (as shown in the example above).
Note: This is an edge case typically required only for tracking purposes. In most scenarios, prefer using either href for navigation or onPress for custom actions, but not both.
More details in the dedicated section Anchors.
Playground​
murray and murray/mobile.A props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| aria-label | stringundefined | |||
| asChild | 5 possibilitiesboolean"web""except-style""except-style-web"undefined | |||
| color | 4 possibilitiesundefined`$${string}`Variable<any>OpaqueColorValue | |||
| disabled | booleanundefined | false | ||
| download | stringbooleanundefined | false | ||
| focusedColor | ColorTokensundefined | |||
| href | stringundefined | |||
| id | stringundefined | |||
| onFocus | undefinedFocusEventHandler<HTMLDivElement> | |||
| onPress | 2 possibilities((e: GestureResponderEvent | KeyboardEvent) => void)undefined | |||
| pressedColor | ColorTokensundefined | |||
| rel | stringundefined | |||
| size | 8 possibilitiesundefinednumberVariable<any>"$text100""$text200""$text300""$text400""$text500" | |||
| sx | 2 possibilitiesundefinedOmit<Omit<TextProps, "fontStyle" | "fontFamily" | "fontWeight">, "hoverStyle" | "pressStyle" | "focusStyle"> | |||
| target | stringundefined | |||
| testID | stringundefined | Test identifier forwarded to the underlying element (e2e selection) | ||
| title | stringundefined | |||
| unstyled | booleanundefined | false | ||
| weight | TextWeightundefined |
Undocumented props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| aria-current | any | |||
| aria-disabled | any | |||
| className | any | |||
| css | any | |||
| data-testid | any | |||
| ref | any | |||
| to | any |
Style API​
Use sx for one-off adjustments. It accepts these style keys:
Each can be overridden per breakpoint with: