Skip to main content

Link

The link component makes text interactive, allowing users to trigger actions through tappable text. Use it for lightweight interactions, navigation triggers, or actions embedded within text content.

Links support the command system for controlling other components declaratively. Use command and commandFor to show, hide, or toggle modals and other targetable elements. For primary actions like submitting forms or triggering operations, use button instead.


Configure the following properties on the link component.

string

A label that describes the purpose or contents of the link. It will be read to users using assistive technologies such as screen readers.

Use this when using only an icon or the content of the link is not enough context for users using assistive technologies.

'--auto' | '--show' | '--hide' | '--toggle' | '--copy'
Default: '--auto'

Sets the action the commandFor should take when this clickable is activated.

See the documentation of particular components for the actions they support.

  • --auto: a default action for the target component.
  • --show: shows the target component.
  • --hide: hides the target component.
  • --toggle: toggles the target component.
  • --copy: copies the target ClipboardItem.
string

ID of a component that should respond to activations (e.g. clicks) on this component.

See command for how to control the behavior of the target.

string

A unique identifier for the element.

The link component provides event callbacks for handling user interactions. Learn more about handling events.

Anchor to click
click
(event: <"s-link">) => void

Called when the link is activated.


Create interactive links using the link component. This example demonstrates basic link usage with onClick handlers for custom actions.

Create an interactive link

Create interactive links using the link component. This example demonstrates basic link usage with onClick handlers for custom actions.

Create an interactive link

<s-link onclick="handleLinkTap">Tappable link</s-link>

  • Write clear, descriptive text: link text should clearly indicate the action or destination, helping users understand what will happen when they tap.
  • Keep text concise: Use brief, actionable language that doesn't clutter the interface. Links work well embedded within text content.
  • Provide accessibility labels when needed: Use accessibilityLabel when the visible text doesn't fully describe the action, especially for short labels like "Edit" or "View".
  • Use the command system for component control: Use command (--show, --hide, --toggle, --copy) with commandFor to control modals and other components declaratively.
  • Handle onClick for custom logic: Implement onClick handlers for actions like showing toasts, updating state, or triggering side effects.
  • Reserve buttons for primary actions: Use button for prominent actions like "Save" or "Submit". Use link for secondary, embedded, or text-based interactions.

Was this page helpful?