[ui] DomiUi: @domi/ui v1.2.0; on Android the town field is an editable box, so focusing it sends no Autofill request (TextField as=auto)
This commit is contained in:
+1
-1
@@ -6,7 +6,7 @@ One row per feature, with its analysis document (CLAUDE.md §5.1). Gaps live in
|
||||
| Feature | Phase | Status | Analysis | Review |
|
||||
|:--|:--|:--|:--|:--|
|
||||
| Released through Fabrica: `.fabrica/` (app, release and e2e pipelines, tests, Aula pictures), the Aula page's words, the version check, the APK signed in Custos, `domi-rosea://open` from the installer, the showcase pictures on demo data, the phone target | Platform track | Merged to `main` (9b8eb70). Not published: the first release waits for the author (G-F1, G6.1) | [fabrica-release.md](features/fabrica-release.md) | [feature-fabrica-release.md](reviews/feature-fabrica-release.md) |
|
||||
| @domi/ui: the shared buttons and the town search field, vendored v1.0.4 (CPAL-1.0); the licence credit at the foot of every screen | Platform track | Built on `feature/domi-ui`; the look is Mark's to judge from the pictures | [domi-ui.md](features/domi-ui.md) | [feature-domi-ui.md](reviews/feature-domi-ui.md) |
|
||||
| @domi/ui: the shared buttons and the town search field, vendored v1.2.0 (CPAL-1.0); the licence credit at the foot of every screen | Platform track | Built on `feature/domi-ui`; the look is Mark's to judge from the pictures | [domi-ui.md](features/domi-ui.md) | [feature-domi-ui.md](reviews/feature-domi-ui.md) |
|
||||
| Atrium Domi adoption: the inventory (Tauri calls, data, network, accent, icon) and the plan for steps 1–8 of Atrium's Appendix A | Platform track | Plan merged (f4efc9e); step 1 = `domi-app.toml` alone (`feature/atrium-door`), the door skipped by Mark's ruling | [atrium-adoption.md](features/atrium-adoption.md) | [docs-atrium-adoption.md](reviews/docs-atrium-adoption.md), [feature-atrium-door.md](reviews/feature-atrium-door.md) |
|
||||
| The APK for a release, tested on the Wave 10 through the phone queue: `reset: uninstall`, `maxMinutes`, the e2e pipeline's `phone` step, the release APK built and verified | Platform track | Merged (f5d8d2c); the phone test passed on the Wave 10 through the queue, 1 of 1 (2026-11-21). Blocked: `rosea-android` does not exist (G-F7); publication (G-F1) | [android-release-apk.md](features/android-release-apk.md) | [feature-android-release-apk.md](reviews/feature-android-release-apk.md) |
|
||||
| Keep her safe in the apps: true words, Android's own save screen, the page kept between the system bars | Platform track | Merged to `main` 2026-11-17; built on this machine, not distributed. Closes G-T4 and, on Android, G-T5 | [keep-her-safe-apps.md](features/keep-her-safe-apps.md) | [feature-keep-her-safe-apps.md](reviews/feature-keep-her-safe-apps.md) |
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# @domi/ui in Rosea: the shared buttons and the town search
|
||||
|
||||
Status: built on `feature/domi-ui`, 2026-11-23. The brief was Mark's, passed on by the Aula session: adopt `@domi/ui`,
|
||||
the Domi design system (`mnovak/domi-design`), at **v1.0.4** (CPAL-1.0 from v1.0.3). He chose **(a)**: Rosea may
|
||||
the Domi design system (`mnovak/domi-design`), at **v1.2.0** (CPAL-1.0 from v1.0.3). He chose **(a)**: Rosea may
|
||||
carry a public copy. Her buttons
|
||||
and her town search take the new look, and the search field gets *search*, never *send*. Review:
|
||||
[`feature-domi-ui.md`](../reviews/feature-domi-ui.md).
|
||||
@@ -23,7 +23,7 @@ plate in her own colours, and her town search becomes the shared field with a se
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
subgraph vendored["packages/domi-ui = @domi/ui v1.0.4 (vendored, never edited)"]
|
||||
subgraph vendored["packages/domi-ui = @domi/ui v1.2.0 (vendored, never edited)"]
|
||||
btn["components/Button.svelte"]
|
||||
tf["components/TextField.svelte"]
|
||||
css["css/tokens + base + components"]
|
||||
@@ -39,7 +39,7 @@ flowchart LR
|
||||
|
||||
| # | Decision | Why |
|
||||
|:--|:--|:--|
|
||||
| D1 | **A vendored copy as a workspace package**, `packages/domi-ui` (`"@domi/ui": "workspace:*"`). It is made only by the design system's own `node tools/vendor.mjs <rosea>/packages/domi-ui v1.0.4`, which writes `src/` (css, components, lib, index.ts, types.ts, tokens/generated.ts), a `package.json` with no scripts, `LICENSE` (CPAL-1.0), `NOTICE` (the credit), `CHANGELOG.md` and `VERSION`, and refuses a tag that is not CPAL-1.0 (INTEGRATE.md §6a). It is never edited here. ESLint skips the folder. The three `@fontsource-variable` fonts arrive as its npm dependencies (OFL); Rosea never imports them, so none is bundled. | Rosea's repository is public and the design system's is private, so a public build cannot fetch it. Mark allowed the copy, under CPAL-1.0 from v1.0.3 (v1.0.2 was MPL-2.0 and is never used). A bump reruns the tool with the next tag. |
|
||||
| D1 | **A vendored copy as a workspace package**, `packages/domi-ui` (`"@domi/ui": "workspace:*"`). It is made only by the design system's own `node tools/vendor.mjs <rosea>/packages/domi-ui v1.2.0`, which writes `src/` (css, components, lib, index.ts, types.ts, tokens/generated.ts), a `package.json` with no scripts, `LICENSE` (CPAL-1.0), `NOTICE` (the credit), `CHANGELOG.md` and `VERSION`, and refuses a tag that is not CPAL-1.0 (INTEGRATE.md §6a). It is never edited here. ESLint skips the folder. The three `@fontsource-variable` fonts arrive as its npm dependencies (OFL); Rosea never imports them, so none is bundled. | Rosea's repository is public and the design system's is private, so a public build cannot fetch it. Mark allowed the copy, under CPAL-1.0 from v1.0.3 (v1.0.2 was MPL-2.0 and is never used). A bump reruns the tool with the next tag. |
|
||||
| D2 | **Rosea's buttons never hand `Button` a Promise.** Async handlers are called as `() => void save()`. | A Promise would make the button announce "Working" and "Done", the design system's English, not Rosea's copy (CLAUDE.md §7). Rosea's own status lines already speak. Its hidden status regions stay empty. |
|
||||
| D3 | **Water, Touch her and *Move the chair* are the plate written as markup** (`class="domi-btn"`, `use:strike`), as INTEGRATE.md §3 allows. | `Button` sets its own `onkeydown` and `onblur` after the ones passed to it. That dropped the pour by a held Space and its stop on blur, and the rule that a held key is one touch (thorns.md T2); the unit tests caught it. *Move the chair* needs its element, so focus can come back after the sunset. |
|
||||
| D4 | **The town search is `TextField`, `action="search"`,** with Rosea's label, a new seal name *Search towns*, and `sentText=""`. The list follows the typing as before, so the seal and Enter only confirm it. | Nothing is sent anywhere, so the seal never says *send*. `sentText=""` keeps the design system's "Searched" unsaid; the line *One town* already speaks. |
|
||||
@@ -47,6 +47,7 @@ flowchart LR
|
||||
| D6 | **Her system faces stay**: `--domi-font-hand` and `--domi-font-book` point at Rosea's own stacks. No font files are copied. | INTEGRATE.md §0.4; the font is Mark's open question in PALETTE.md. |
|
||||
| D7 | `<html data-domi-room="rosea" data-domi-theme="auto">` | Her room's ground equals her current colours in both themes, and she follows the device, as before. |
|
||||
| D9 | **The licence's credit** (CPAL-1.0 Exhibit B, for Rosea and for the copy): `Built on Domi · https://aula.marek-novak.cz · Copyright (c) 2026 Marek Novák`, in `--ink-soft` at 0.8 rem at the foot of every screen, from the first open on (the gardener, the garden, the Letter). It is the exact text of `DOMI_ATTRIBUTION_TEXT`, as plain text, **not** `DomiCredit`'s link. | INTEGRATE.md §6a and Mark ask for it in the interface. The garden is offline: a link opening a web page would carry the player out of her, and on Android, which has no internet, into a page that never loads. The plain form is the one §6a gives for a native window. CLAUDE.md says *Domi* never appears alone in public; this phrase is the licence's and Mark's own (review finding). |
|
||||
| D10 | **On Android the town field is an editable box** (`TextField as="auto"`, v1.1.0): `contenteditable="plaintext-only"` with `role="textbox"`, the same look and keys. Elsewhere it stays the native search field. | Android's WebView asks Google's Autofill service, over the network, the moment a native text field gets focus. No attribute stops it, and Rosea's missing `INTERNET` permission does not either, because the system's Autofill service makes the request (found by Amicitia). A player typing their town would send a request they never asked for. A unit test holds it on an Android user agent, and the drill (`as="input"`) fails it. |
|
||||
| D8 | **Not converted:** the gardener's choices stay her own picture-chips, not `Radio`. The *Bring her back* file picker stays a `<label>` around the browser's own input, wearing the plate's classes. | The brief was her buttons and the search. A file input cannot be a `Button`. |
|
||||
|
||||
## 3. Risk analysis
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Review: `feature/domi-ui` (2026-11-23)
|
||||
|
||||
Analysis: [`../features/domi-ui.md`](../features/domi-ui.md). Rosea's buttons and her town search take `@domi/ui`'s
|
||||
look, from a vendored copy. The copy is **v1.0.4, CPAL-1.0**, made by the design system's `tools/vendor.mjs` into `packages/domi-ui`. Aula's
|
||||
look, from a vendored copy. The copy is **v1.2.0, CPAL-1.0**, made by the design system's `tools/vendor.mjs` into `packages/domi-ui`. Aula's
|
||||
hold was lifted with that tag; v1.0.1, the copy first tried here, never left this machine.
|
||||
|
||||
## Before and after
|
||||
@@ -74,6 +74,13 @@ differ, for him to judge:
|
||||
public-domain sources of the candidate sentences and the origin of the placeholder art, as the domi-licence
|
||||
session asked. `tauri.conf.json` declares `"license": "CPAL-1.0"` for the bundles.
|
||||
|
||||
10. **Android's Autofill request.** v1.1.0's `TextField as="auto"` draws an editable box on Android, so focusing
|
||||
the town field no longer makes the WebView ask Google's Autofill service. That request is made by the system's
|
||||
service, not Rosea's process, so her missing `INTERNET` permission never stopped it. *Fixed (D10)*, with two
|
||||
unit tests (Android: no native field; elsewhere: the native search field), and the drill fails without it.
|
||||
The Aula pictures' phone uses an Android user agent, so they type into the editable box in a real browser.
|
||||
*Not measured on the Wave 10:* the release APK's next phone run should watch for the Autofill request.
|
||||
|
||||
## Soul, privacy, reachability, offline
|
||||
|
||||
- **Soul:** no words changed except the seal's name, and no gesture changed. The look is Mark's call (above).
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ Rewritten at the end of each session (CLAUDE.md §5.1).
|
||||
|
||||
## Latest — 2026-11-23: @domi/ui, the shared look, and the credit
|
||||
|
||||
- **`feature/domi-ui`**: Rosea's buttons and her town search wear @domi/ui v1.0.4 (CPAL-1.0).
|
||||
- **`feature/domi-ui`**: Rosea's buttons and her town search wear @domi/ui v1.2.0 (CPAL-1.0). On Android the town field is an editable box, so no Autofill request goes to Google.
|
||||
- It is vendored unchanged into `packages/domi-ui` by the design system's `tools/vendor.mjs`.
|
||||
- Her colours, system fonts, art and layout stay.
|
||||
- The licence credit stands at the foot of every screen, in its exact words, as plain text.
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ function watch(page: Page): string[] {
|
||||
|
||||
async function chooseGardenerAndTown(page: Page): Promise<void> {
|
||||
await pastGardener(page);
|
||||
await page.getByRole('searchbox', { name: en.sunset.searchLabel }).fill('prague');
|
||||
await page.getByLabel(en.sunset.searchLabel).fill('prague');
|
||||
await page.getByRole('button', { name: /^Prague/ }).first().click();
|
||||
await storedTown(page, 'Prague');
|
||||
}
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ async function photograph(browser: Browser, theme: 'light' | 'dark', phone: bool
|
||||
await shot(page, '1-gardener');
|
||||
await pastGardener(page);
|
||||
|
||||
const search = page.getByRole('searchbox', { name: en.sunset.searchLabel });
|
||||
const search = page.getByLabel(en.sunset.searchLabel);
|
||||
await expect(search).toBeVisible();
|
||||
await shot(page, '2-town-empty');
|
||||
await search.fill('prague');
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
# Changelog
|
||||
|
||||
## 1.2.0 (2026-11-23)
|
||||
|
||||
- **The seal without a script**: on a static page (Aula), `.domi-field:has(.domi-field__input:placeholder-shown)` lays
|
||||
the seal flat from CSS alone, for `<input>` and `<textarea>`; give it a placeholder (`" "` if none). The seal stays an
|
||||
enabled button there, so the server treats an empty submit as nothing. Fields with `data-state` (the Svelte component)
|
||||
are skipped, so a cleared field keeps its lit "sent" seal. TextField.md, "Without a script". Asked by Aula.
|
||||
- Docs: testing a field in both modes (TextField.md).
|
||||
|
||||
## 1.1.0 (2026-11-23)
|
||||
|
||||
- **TextField `as="editable" | "auto"`**: the field drawn with a contenteditable `role="textbox"` instead of a native
|
||||
`<input>`/`<textarea>`, because on Android the WebView sends an Autofill request to Google whenever a native text
|
||||
field gets focus (found by Amicitia). Same look, seal, keys and states; plain-text paste; label by
|
||||
`aria-labelledby`; `inputmode` from the type; a hidden input for `name`. `auto` = editable on Android only.
|
||||
Passwords always stay native. New `editor` binding; `input` keeps its type. `isAndroid()` exported.
|
||||
- Docs: the credit goes by repo visibility (Mark): apps whose own repo is public, and public repos carrying a copy,
|
||||
show it; apps built from a private repo show none, paid or free.
|
||||
|
||||
## 1.0.4 (2026-11-23)
|
||||
|
||||
- Fix: `Strike.svelte` had no `<script>` block, so a consumer whose tsconfig has `allowJs` off (Ludus) got "Could not
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
This folder is @domi/ui v1.0.4, copied unchanged from domi-design by tools/vendor.mjs.
|
||||
This folder is @domi/ui v1.2.0, copied unchanged from domi-design by tools/vendor.mjs.
|
||||
Licence: Common Public Attribution License 1.0 (LICENSE). Original Code: @domi/ui. Initial Developer: Marek Novák.
|
||||
|
||||
Attribution Information (Exhibit B). Any app built with this code shows, prominently in its user interface when
|
||||
|
||||
@@ -1 +1 @@
|
||||
v1.0.4
|
||||
v1.2.0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@domi/ui",
|
||||
"version": "1.0.4",
|
||||
"description": "The Domi design system: tokens for every Domi app, struck buttons and fields with an integrated send button, Svelte 5 components. Vendored copy of v1.0.4: do not edit here; change domi-design and vendor the next tag.",
|
||||
"version": "1.2.0",
|
||||
"description": "The Domi design system: tokens for every Domi app, struck buttons and fields with an integrated send button, Svelte 5 components. Vendored copy of v1.2.0: do not edit here; change domi-design and vendor the next tag.",
|
||||
"license": "CPAL-1.0",
|
||||
"type": "module",
|
||||
"svelte": "./src/index.ts",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { strike } from '../lib/strike';
|
||||
import { canSend, enterAction, failureText, isSoftKeyboard, type FieldState } from '../lib/keys';
|
||||
import type { IconName } from '../lib/icons';
|
||||
import { caretToEnd, inputmodeFor, insertPlainText, isAndroid, readText, writeText } from '../lib/editable';
|
||||
|
||||
type Action = 'send' | 'search' | 'next' | 'save';
|
||||
|
||||
@@ -55,8 +56,16 @@
|
||||
force?: string;
|
||||
sendForce?: string;
|
||||
class?: string;
|
||||
/** The input element, for focusing it from outside. */
|
||||
/** The input element, for focusing it from outside (null in editable mode: see editor). */
|
||||
input?: HTMLInputElement | HTMLTextAreaElement | null;
|
||||
/**
|
||||
* input (default): a native <input>/<textarea>. editable: a contenteditable box with role="textbox": on Android
|
||||
* the WebView sends an Autofill request to Google whenever a native text field gets focus; an editable box does
|
||||
* not. auto: editable on Android, native elsewhere. Passwords are always native (masking, password managers).
|
||||
*/
|
||||
as?: 'input' | 'editable' | 'auto';
|
||||
/** The editable box in editable mode, for focusing it from outside. */
|
||||
editor?: HTMLElement | null;
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -94,12 +103,16 @@
|
||||
sendForce,
|
||||
class: cls = '',
|
||||
input = $bindable(null),
|
||||
as = 'input',
|
||||
editor = $bindable(null),
|
||||
}: Props = $props();
|
||||
|
||||
const uid = $props.id();
|
||||
const fieldId = $derived(id ?? `domi-field-${uid}`);
|
||||
const hintId = `domi-hint-${uid}`;
|
||||
const errorId = `domi-error-${uid}`;
|
||||
const labelId = `domi-label-${uid}`;
|
||||
const android = isAndroid();
|
||||
|
||||
const words: Record<Action, { label: string; icon: IconName; key: 'send' | 'search' | 'next' | 'done'; busy: string; done: string; fail: string }> = {
|
||||
send: { label: 'Send', icon: 'send', key: 'send', busy: 'Sending', done: 'Sent', fail: 'Could not send. Try again.' },
|
||||
@@ -124,6 +137,10 @@
|
||||
const described = $derived([hint && hintId, message && errorId].filter(Boolean).join(' ') || undefined);
|
||||
const inputType = $derived(type === 'password' && revealed ? 'text' : type);
|
||||
const clears = $derived(clearOnSend ?? action === 'send');
|
||||
const editable = $derived(type !== 'password' && (as === 'editable' || (as === 'auto' && android)));
|
||||
/** The element that takes the text, whichever kind it is. */
|
||||
const box = $derived<HTMLElement | null>(editable ? editor : input);
|
||||
const locked = $derived(disabled || readonly || shown === 'sending');
|
||||
|
||||
function hold(): number {
|
||||
const v = getComputedStyle(document.documentElement).getPropertyValue('--domi-dur-hold');
|
||||
@@ -133,22 +150,22 @@
|
||||
function nextField(from: HTMLElement) {
|
||||
const scope = from.closest('form') ?? document;
|
||||
const all = [...scope.querySelectorAll<HTMLElement>('.domi-field__input, input, textarea, select')].filter(
|
||||
(el) => !el.hasAttribute('disabled') && el.getAttribute('type') !== 'hidden',
|
||||
(el) => !el.hasAttribute('disabled') && el.getAttribute('aria-disabled') !== 'true' && el.getAttribute('type') !== 'hidden',
|
||||
);
|
||||
const i = all.indexOf(from);
|
||||
all[i + 1]?.focus();
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
if (!sendable || !input) return;
|
||||
const el = input;
|
||||
if (!sendable || !box) return;
|
||||
const el = box;
|
||||
const text = value;
|
||||
clearTimeout(timer);
|
||||
failure = '';
|
||||
if (!onsend) {
|
||||
// No handler: behave like the form's own submit (or, for next, move on).
|
||||
if (action === 'next') nextField(el);
|
||||
else el.form?.requestSubmit();
|
||||
else el.closest('form')?.requestSubmit();
|
||||
return;
|
||||
}
|
||||
const result = onsend(text);
|
||||
@@ -168,7 +185,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function done(el: HTMLInputElement | HTMLTextAreaElement) {
|
||||
function done(el: HTMLElement) {
|
||||
if (clears) value = '';
|
||||
if (action === 'next') {
|
||||
auto = 'idle';
|
||||
@@ -194,6 +211,9 @@
|
||||
} else if (r === 'ignore' && e.key === 'Enter' && e.altKey && !multiline) {
|
||||
// Alt+Enter must not submit the form. An Enter that ends an input method's composition is left alone.
|
||||
e.preventDefault();
|
||||
} else if (editable && !multiline && e.key === 'Enter' && !e.isComposing && e.keyCode !== 229) {
|
||||
// A single-line editable box never takes a line break.
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,10 +226,55 @@
|
||||
grow();
|
||||
}
|
||||
|
||||
// Editable mode: the box's text is the value. Typing, paste and drop bring plain text only.
|
||||
function edited() {
|
||||
if (!editor) return;
|
||||
let t = readText(editor);
|
||||
let rewrite = false;
|
||||
if (!multiline && /\n/.test(t)) {
|
||||
t = t.replace(/\r?\n/g, ' ');
|
||||
rewrite = true;
|
||||
}
|
||||
if (maxlength !== undefined && t.length > maxlength) {
|
||||
t = t.slice(0, maxlength);
|
||||
rewrite = true;
|
||||
}
|
||||
if (t === '' && editor.childNodes.length > 0) rewrite = true; // a stray <br> would hide the placeholder
|
||||
if (rewrite) {
|
||||
writeText(editor, t);
|
||||
if (t) caretToEnd(editor);
|
||||
}
|
||||
value = t;
|
||||
typed();
|
||||
}
|
||||
function pasted(e: ClipboardEvent) {
|
||||
if (!editor) return;
|
||||
e.preventDefault();
|
||||
if (locked) return;
|
||||
let t = e.clipboardData?.getData('text/plain') ?? '';
|
||||
if (!multiline) t = t.replace(/\r?\n/g, ' ');
|
||||
insertPlainText(editor, t);
|
||||
edited();
|
||||
}
|
||||
function dropped(e: DragEvent) {
|
||||
if (!editor) return;
|
||||
e.preventDefault();
|
||||
const t = e.dataTransfer?.getData('text/plain') ?? '';
|
||||
if (!t || locked) return;
|
||||
editor.focus();
|
||||
insertPlainText(editor, multiline ? t : t.replace(/\r?\n/g, ' '));
|
||||
edited();
|
||||
}
|
||||
// A value set from outside (bind:value, a field cleared after sending) is written into the box.
|
||||
$effect(() => {
|
||||
const v = value;
|
||||
if (editable && editor && readText(editor) !== v) writeText(editor, v);
|
||||
});
|
||||
|
||||
// field-sizing: content grows the textarea in Chromium (WebView2, Android WebView); elsewhere, grow it here.
|
||||
const sizesItself = typeof CSS !== 'undefined' && CSS.supports?.('field-sizing', 'content');
|
||||
function grow() {
|
||||
if (!multiline || sizesItself || !input) return;
|
||||
if (!multiline || sizesItself || !(input instanceof HTMLTextAreaElement)) return;
|
||||
input.style.height = 'auto';
|
||||
input.style.height = `${input.scrollHeight}px`;
|
||||
}
|
||||
@@ -219,11 +284,16 @@
|
||||
});
|
||||
$effect(() => () => clearTimeout(timer));
|
||||
$effect(() => {
|
||||
if (autofocus) input?.focus();
|
||||
if (autofocus) box?.focus();
|
||||
});
|
||||
|
||||
function focusBox() {
|
||||
if (!box) return;
|
||||
box.focus();
|
||||
if (editable) caretToEnd(box);
|
||||
}
|
||||
function focusInput(e: MouseEvent) {
|
||||
if (e.target === e.currentTarget) input?.focus();
|
||||
if (e.target === e.currentTarget) focusBox();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -233,12 +303,47 @@
|
||||
data-empty={empty ? '' : undefined}
|
||||
data-disabled={disabled ? '' : undefined}
|
||||
>
|
||||
<label class={['domi-field__label', hideLabel && 'domi-sr']} for={fieldId}>
|
||||
{label}{#if optional}<span class="domi-field__optional">{" (optional)"}</span>{/if}
|
||||
</label>
|
||||
{#if editable}
|
||||
<!-- An editable box is not a labelable element: the label names it through aria-labelledby; a click focuses it. -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions -->
|
||||
<span class={['domi-field__label', hideLabel && 'domi-sr']} id={labelId} role="presentation" onclick={focusBox}>
|
||||
{label}{#if optional}<span class="domi-field__optional">{" (optional)"}</span>{/if}
|
||||
</span>
|
||||
{:else}
|
||||
<label class={['domi-field__label', hideLabel && 'domi-sr']} for={fieldId} id={labelId}>
|
||||
{label}{#if optional}<span class="domi-field__optional">{" (optional)"}</span>{/if}
|
||||
</label>
|
||||
{/if}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions -->
|
||||
<div class="domi-field__well" role="presentation" data-force={force} onclick={focusInput}>
|
||||
{#if multiline}
|
||||
{#if editable}
|
||||
<div
|
||||
bind:this={editor}
|
||||
class={['domi-field__input', 'domi-field__input--editable', multiline && 'domi-field__input--lines']}
|
||||
id={fieldId}
|
||||
role="textbox"
|
||||
tabindex={disabled ? -1 : 0}
|
||||
contenteditable={locked ? 'false' : 'plaintext-only'}
|
||||
aria-labelledby={labelId}
|
||||
aria-multiline={multiline ? 'true' : 'false'}
|
||||
aria-describedby={described}
|
||||
aria-invalid={message ? 'true' : undefined}
|
||||
aria-required={required ? 'true' : undefined}
|
||||
aria-readonly={readonly || shown === 'sending' ? 'true' : undefined}
|
||||
aria-disabled={disabled ? 'true' : undefined}
|
||||
aria-placeholder={placeholder}
|
||||
data-placeholder={placeholder}
|
||||
inputmode={inputmode ?? inputmodeFor(type)}
|
||||
enterkeyhint={multiline ? (w.key === 'done' ? 'done' : 'enter') : w.key === 'done' ? 'done' : w.key}
|
||||
spellcheck={spellcheck ?? true}
|
||||
style:--_rows-max={rows}
|
||||
onkeydown={keydown}
|
||||
oninput={edited}
|
||||
onpaste={pasted}
|
||||
ondrop={dropped}
|
||||
></div>
|
||||
{#if name}<input type="hidden" {name} {value} />{/if}
|
||||
{:else if multiline}
|
||||
<textarea
|
||||
bind:this={input}
|
||||
bind:value
|
||||
|
||||
@@ -512,6 +512,43 @@ textarea.domi-field__input {
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
/*
|
||||
* Editable mode (as="editable"): a contenteditable box in place of <input>/<textarea>, so an Android WebView sends no
|
||||
* Autofill request. One line: centred, no wrap, scrolls sideways. Several lines: grows to --_rows-max, then scrolls.
|
||||
*/
|
||||
.domi-field__input--editable {
|
||||
align-self: center;
|
||||
min-height: var(--domi-leading-md);
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
white-space: pre;
|
||||
cursor: text;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
.domi-field__input--editable::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
.domi-field__input--lines {
|
||||
align-self: stretch;
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
min-height: calc(var(--domi-leading-md) + 16px);
|
||||
max-height: calc(var(--domi-leading-md) * var(--_rows-max, 8) + 16px);
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
.domi-field__input--editable:empty::before {
|
||||
content: attr(data-placeholder);
|
||||
color: var(--domi-muted);
|
||||
pointer-events: none;
|
||||
}
|
||||
.domi-field__input--editable[contenteditable='false'] {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/* The seal: the send button set into the right end of the field. */
|
||||
.domi-send {
|
||||
--_s: max(var(--domi-size-send-md), var(--domi-send-target));
|
||||
@@ -606,6 +643,30 @@ textarea.domi-field__input {
|
||||
.domi-field:not([data-empty]) .domi-send:not([aria-disabled='true']) .domi-icon {
|
||||
animation: domi-rise var(--domi-dur-state) var(--domi-ease-release) 1;
|
||||
}
|
||||
/*
|
||||
* Without a script (a static page: Aula): the seal lies flat while the field is empty, from CSS alone. Give the
|
||||
* <input> or <textarea> a placeholder (placeholder=" " if it shows none). The seal stays an enabled, focusable button
|
||||
* here: the server must treat an empty submit as nothing. Fields driven by the Svelte component (they carry
|
||||
* data-state while sending and after) are left to the script, so a cleared field keeps its lit "sent" seal.
|
||||
*/
|
||||
.domi-field:not([data-state]):has(.domi-field__input:placeholder-shown) .domi-send,
|
||||
.domi-field:not([data-state]):has(.domi-field__input:placeholder-shown) .domi-send:hover,
|
||||
.domi-field:not([data-state]):has(.domi-field__input:placeholder-shown) .domi-send:active,
|
||||
.domi-field:not([data-state]):has(.domi-field__input:placeholder-shown) .domi-send:focus-visible {
|
||||
border-color: var(--domi-line);
|
||||
background: transparent;
|
||||
color: var(--domi-disabled);
|
||||
box-shadow: none;
|
||||
cursor: default;
|
||||
transform: none;
|
||||
}
|
||||
.domi-field:not([data-state]):has(.domi-field__input:placeholder-shown) .domi-send::before,
|
||||
.domi-field:not([data-state]):has(.domi-field__input:placeholder-shown) .domi-send::after {
|
||||
animation: none;
|
||||
}
|
||||
.domi-field:not([data-state]):has(.domi-field__input:placeholder-shown) .domi-send .domi-icon {
|
||||
animation: none;
|
||||
}
|
||||
.domi-send[data-state='sending'] {
|
||||
cursor: progress;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ export { default as Icon } from './components/Icon.svelte';
|
||||
export { default as Strike } from './components/Strike.svelte';
|
||||
export { default as DomiCredit } from './components/DomiCredit.svelte';
|
||||
export { DOMI_ATTRIBUTION, DOMI_ATTRIBUTION_TEXT } from './lib/credit';
|
||||
export { isAndroid } from './lib/editable';
|
||||
|
||||
export { strike } from './lib/strike';
|
||||
export { icons, type IconName } from './lib/icons';
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// SPDX-License-Identifier: CPAL-1.0
|
||||
/**
|
||||
* Helpers for TextField's editable mode: a contenteditable box with role="textbox" in place of <input>/<textarea>.
|
||||
* Why: on Android the WebView asks Google's Autofill service (a network request) as soon as a text <input> or
|
||||
* <textarea> gets focus, and no attribute stops it (found by Amicitia). A contenteditable box is not an autofill
|
||||
* target. Plain text only: paste and drop never bring markup.
|
||||
*/
|
||||
|
||||
/** True in an Android WebView or browser, where editable mode avoids the Autofill request. Safe during SSR. */
|
||||
export function isAndroid(): boolean {
|
||||
return typeof navigator !== 'undefined' && /Android/i.test(navigator.userAgent);
|
||||
}
|
||||
|
||||
/** The box's text, with line breaks as \n. An emptied box that only holds a stray line break reads as ''. */
|
||||
export function readText(el: HTMLElement): string {
|
||||
const raw = typeof el.innerText === 'string' ? el.innerText : (el.textContent ?? '');
|
||||
return raw === '\n' ? '' : raw;
|
||||
}
|
||||
|
||||
/** Replaces the box's content with plain text (no markup can enter). */
|
||||
export function writeText(el: HTMLElement, text: string): void {
|
||||
el.textContent = text;
|
||||
}
|
||||
|
||||
/** Puts the caret after the last character. */
|
||||
export function caretToEnd(el: HTMLElement): void {
|
||||
const sel = typeof getSelection === 'function' ? getSelection() : null;
|
||||
if (!sel || typeof document.createRange !== 'function') return;
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(el);
|
||||
range.collapse(false);
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts plain text at the caret. Uses the browser's own insertion where it exists, so undo keeps working;
|
||||
* otherwise inserts a text node at the selection.
|
||||
*/
|
||||
export function insertPlainText(el: HTMLElement, text: string): void {
|
||||
try {
|
||||
if (typeof document.execCommand === 'function' && document.execCommand('insertText', false, text)) return;
|
||||
} catch {
|
||||
// Fall through to the Range insertion.
|
||||
}
|
||||
const sel = typeof getSelection === 'function' ? getSelection() : null;
|
||||
const node = document.createTextNode(text);
|
||||
if (!sel || sel.rangeCount === 0 || !el.contains(sel.getRangeAt(0).commonAncestorContainer)) {
|
||||
el.append(node);
|
||||
return;
|
||||
}
|
||||
const range = sel.getRangeAt(0);
|
||||
range.deleteContents();
|
||||
range.insertNode(node);
|
||||
range.setStartAfter(node);
|
||||
range.collapse(true);
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
}
|
||||
|
||||
/** The soft keyboard a type asks for, as inputmode (an editable box has no type attribute). */
|
||||
export function inputmodeFor(type: string): 'text' | 'email' | 'url' | 'tel' | 'decimal' | 'search' {
|
||||
const map: Record<string, 'email' | 'url' | 'tel' | 'decimal' | 'search'> = {
|
||||
email: 'email',
|
||||
url: 'url',
|
||||
tel: 'tel',
|
||||
number: 'decimal',
|
||||
search: 'search',
|
||||
};
|
||||
return map[type] ?? 'text';
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
/* eslint-disable */
|
||||
export const tokens = {
|
||||
"name": "@domi/ui",
|
||||
"version": "1.0.4",
|
||||
"version": "1.2.0",
|
||||
"note": "GENERATED by tools/build-tokens.mjs. Colours are sRGB hex. Use roles, never the hex in a component.",
|
||||
"themes": {
|
||||
"dark": {
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
// Raw: the towns are handed on as they came, never wrapped in a state Proxy.
|
||||
let results = $state.raw<readonly NamedPlace[]>([]);
|
||||
let input = $state<HTMLInputElement | HTMLTextAreaElement | null>(null);
|
||||
// On Android the field is an editable box, not an <input> (as="auto" below): focus whichever there is.
|
||||
let editor = $state<HTMLElement | null>(null);
|
||||
|
||||
// Only the latest query's answer is shown, however the searches finish.
|
||||
let asked = 0;
|
||||
@@ -52,7 +54,7 @@
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (focusOnOpen) input?.focus();
|
||||
if (focusOnOpen) (input ?? editor)?.focus();
|
||||
});
|
||||
|
||||
const where = (t: NamedPlace): string => [t.region, t.country].filter(Boolean).join(', ');
|
||||
@@ -63,8 +65,11 @@
|
||||
<p class="why">{en.sunset.why}</p>
|
||||
|
||||
<!-- The list already follows the typing; the seal and Enter only confirm it, so they say nothing of their own
|
||||
(sentText) and the status line below speaks (domi-ui.md D4). Nothing is sent anywhere: "search", never "send". -->
|
||||
(sentText) and the status line below speaks (domi-ui.md D4). Nothing is sent anywhere: "search", never "send".
|
||||
as="auto": on Android an editable box, because a native field makes the WebView ask Google's Autofill service
|
||||
the moment it gets focus, whatever the app's permissions (domi-ui.md D10). -->
|
||||
<TextField
|
||||
as="auto"
|
||||
id="{uid}-search"
|
||||
type="search"
|
||||
label={en.sunset.searchLabel}
|
||||
@@ -76,6 +81,7 @@
|
||||
onsend={() => {}}
|
||||
bind:value={query}
|
||||
bind:input
|
||||
bind:editor
|
||||
/>
|
||||
<p class="found" role="status" aria-live="polite">{query.trim() === '' ? '' : en.sunset.found(results.length)}</p>
|
||||
|
||||
|
||||
@@ -45,6 +45,20 @@ describe('the garden asks where the sunset is', () => {
|
||||
expect(document.activeElement).toBe(document.body);
|
||||
});
|
||||
|
||||
it('on Android the town field is no native text field, so the WebView asks no Autofill service (domi-ui.md D10)', async () => {
|
||||
vi.spyOn(navigator, 'userAgent', 'get').mockReturnValue('Mozilla/5.0 (Linux; Android 16; WAVE 10C) AppleWebKit/537.36 Chrome/140.0 Mobile Safari/537.36');
|
||||
render(Shell, { sunset: wiring() });
|
||||
const field = await screen.findByRole('textbox', { name: en.sunset.searchLabel });
|
||||
expect(field.getAttribute('contenteditable')).toBe('plaintext-only');
|
||||
expect(document.querySelector('.ask input:not([type="hidden"]), .ask textarea')).toBeNull();
|
||||
});
|
||||
|
||||
it('elsewhere it stays the native search field', async () => {
|
||||
render(Shell, { sunset: wiring() });
|
||||
expect(await screen.findByRole('searchbox', { name: en.sunset.searchLabel })).toBeTruthy();
|
||||
expect(screen.queryByRole('textbox', { name: en.sunset.searchLabel })).toBeNull();
|
||||
});
|
||||
|
||||
it('typing lists towns, choosing one shows its sunset, keeps it, and moves focus to the answer', async () => {
|
||||
const w = wiring();
|
||||
render(Shell, { sunset: w });
|
||||
|
||||
Reference in New Issue
Block a user