🚧 Glyx is pre-release software. APIs may change before v1.0. Get started →
Documentation
Components
SelectableText

SelectableText

User-selectable text with pointer-driven selection and Ctrl+C / Cmd+C copy. Default Text nodes are intentionally non-selectable (no overhead for labels and buttons).

import { SelectableText, SelectionArea } from '@glyx-dev/react'

Basic usage

<SelectableText fontSize={16} color="#E5E7EB">
  Copy me with Ctrl+C
</SelectableText>

Click to place a cursor. Click and drag to select a range. Press Ctrl+C (or Cmd+C on macOS) to copy the selected text to the clipboard.

Props

PropTypeDefaultDescription
childrenstringText content
fontSizenumber16Font size in px
colorstringinheritedText color
textAlign'left' | 'center' | 'right''left'Horizontal alignment
numberOfLinesnumberClamp to N lines
selectablebooleantrue (or from context)Override the SelectionArea context for this element
styleobjectStyle for the outer container

Disabling selection

Per element

<SelectableText selectable={false}>
  This text cannot be selected
</SelectableText>

For a subtree (SelectionArea)

Wrap any subtree with <SelectionArea enabled={false}> to disable selection for all SelectableText nodes inside it. A per-element selectable={true} prop overrides the context and re-enables selection for that element.

import { SelectionArea, SelectableText } from '@glyx-dev/react'
 
// Kiosk / presentation mode — disable for the entire window
function App() {
  return (
    <SelectionArea enabled={false}>
      <MyScreen />
    </SelectionArea>
  )
}
 
// Disable a panel but keep another selectable
function TwoPanel() {
  return (
    <View style={{ flexDirection: 'row' }}>
      <SelectionArea enabled={false}>
        <ReadOnlyPane />
      </SelectionArea>
 
      {/* SelectableText outside SelectionArea is enabled by default */}
      <SelectableText>Copy this</SelectableText>
    </View>
  )
}
 
// Re-enable one element inside a disabled area
function Mixed() {
  return (
    <SelectionArea enabled={false}>
      <SelectableText>not selectable</SelectableText>
      <SelectableText selectable={true}>still selectable</SelectableText>
    </SelectionArea>
  )
}

In a document viewer

function ArticleView({ article }) {
  return (
    <ScrollView style={{ flex: 1, padding: 24 }}>
      <SelectableText fontSize={28} color="#111" style={{ marginBottom: 12 }}>
        {article.title}
      </SelectableText>
      <SelectableText fontSize={14} color="#555" style={{ marginBottom: 20 }}>
        {article.author} · {article.date}
      </SelectableText>
      <SelectableText fontSize={16} color="#222" style={{ lineHeight: 26 }}>
        {article.body}
      </SelectableText>
    </ScrollView>
  )
}

Compared to Text

FeatureTextSelectableText
Renderingnative text nodeView wrapper + Text
Pointer eventsnoneclick + drag selection
ClipboardnoCtrl/Cmd+C
Overheadzeronegligible (1 extra node)
Use caselabels, buttons, headingsarticles, code, log output, chat messages

Notes

  • Selection highlight color is rgba(100, 120, 255, 0.47) — the same blue used by TextInput.
  • Multi-line selection is not yet supported; selection spans a single visual line.
  • textAlign: 'center' or 'right' affects rendering but hit-testing always measures from the left edge (V1 limitation).
  • For a full rich-text editor (cursor + keyboard navigation + editable), use TextInput instead.