# Values as text

> What a value looks like as text and how text is read back, so cells copy and paste between applications.

Values move between applications as text: copied from one grid, pasted into
another, typed into a cell. What a value looks like as text, and how text is read
back as a value, decide whether that movement simply works.

## Best practices

**Copy what is shown.** Put cells on the clipboard as people see them — a date as
it is written, a choice by its label — in the tab-separated form every
spreadsheet reads and writes.

**Read what is pasted as the cell's kind.** A pasted number is read as a number,
with whatever separators, digits and currency sign it came with; a pasted date
in any of the forms dates are written; a choice by its label or its value; a
yes-or-no from the words spreadsheets and people use for it.

**Leave alone what cannot be read.** Text that is not a value of a cell's kind
does not overwrite the cell, and does not become an error in it.

**Treat empty as empty.** A cell with no value copies as empty text, and empty
text pasted into a cell clears it.

**Read pasted text as written.** What is pasted is data: it is read as the
value it writes and no further. Arithmetic is worked out when a person types it,
not when a column of dates or telephone numbers lands in a number's cell —
those are not numbers, and are left out.

**Refuse a pasted value beyond the cell's limits.** A number typed beyond its
range is held within it, where the person typing can see it change. A pasted
one is refused, since nobody is watching each cell; a date beyond its range is
refused either way.

**Never fail on what a record holds.** A value that is not of its field's kind
— a timestamp where a date belongs, text where a number does — is shown as
nothing, and marked; it does not break the view.

**Fill a selection from one cell.** Pasting a single value into a larger
selection fills it; pasting a block places it from the active cell, and stops at
the grid's edge.

See also [Schemas](https://ui.publictheta.com/foundations/schema.md), [Numbers](https://ui.publictheta.com/foundations/number-type.md) and
[Dates](https://ui.publictheta.com/foundations/date-type.md).

## Behaviour

Each statement is verified by a test in Chromium, Chromium (touch), Firefox, WebKit, WebKit (touch), unless it names the environments it applies to or is marked open.
- A value of each kind is shown as its kind is, and reads back as itself.
- No value is the empty text, and the empty text is no value.
- Numbers and dates are read as forgivingly as their fields read them.
- Typed, a number beyond its range is held within it, and a date beyond its range is refused.
- Pasted, a value beyond its range is refused, naming the end it is beyond: nobody is there to see it moved.
- Pasted, text is read as written and no further: what looks like arithmetic is not worked out.
- A value that is not of the field's kind is shown as nothing, rather than failing.
- A yes-or-no is read from the words spreadsheets and people use.
- A choice is read by its label or by its value, whatever the case.
- A choice written exactly as a value is that value, whatever else it might be the label of.
- A schema given by reference is shown and read as what it refers to.

## Reference implementation

React: `npx shadcn@latest add https://ui.publictheta.com/r/schema-text.json`
