Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(ui): reject input on disabled text fields

yhh9124fb6db2d4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cfb92f48e..b67926b81 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Disabled text fields reject queued input.** Text input checks effective entity activity and interaction state before accepting editor events, including disabled ancestors, and releases the editing surface on the next update.
+
- **Removed text fields release OS input focus.** Deleting the focused entity or removing its TextInput component closes the editing surface even though the old component can no longer be updated.
- **Text input surfaces stay with their own apps.** Closing an older app or a preview removes its own text-editor listeners and surface, preserving typing in other running apps. Repeated cleanup releases each surface once.
diff --git a/sdk/src/ui/text/text-input-plugin.ts b/sdk/src/ui/text/text-input-plugin.ts
index f6128bd5c..7fc038006 100644
--- a/sdk/src/ui/text/text-input-plugin.ts
+++ b/sdk/src/ui/text/text-input-plugin.ts
@@ -112,7 +112,8 @@ export class TextInputPlugin implements Plugin {
const fm = app.getResource(FocusManager) as FocusManagerState | null;
if (!fm || fm.focusedEntity === null) return null;
const entity = fm.focusedEntity;
- if (!world.valid(entity) || !world.has(entity, TextInput)) return null;
+ if (!world.isEntityActive(entity) || !world.has(entity, TextInput)) return null;
+ if (world.has(entity, Interactable) && !world.get(entity, Interactable).enabled) return null;
return entity;
}
diff --git a/sdk/tests/text-input-plugin-lifecycle.test.ts b/sdk/tests/text-input-plugin-lifecycle.test.ts
index 868ae23eb..7905cc0f2 100644
--- a/sdk/tests/text-input-plugin-lifecycle.test.ts
+++ b/sdk/tests/text-input-plugin-lifecycle.test.ts
@@ -31,6 +31,8 @@ const { TextInputPlugin } = await import('../src/ui/text/text-input-plugin');
const { FocusManager, FocusManagerState } = await import('../src/ui/input/focusable');
const { UIEvents, UIEventQueue } = await import('../src/ui/core/events');
const { TextInput } = await import('../src/ui/text/text-input');
+const { Disabled } = await import('../src/ecs/component');
+const { Interactable } = await import('../src/ui/input/interactable');
const apps: ReturnType<typeof App.new>[] = [];
function build(plugin: InstanceType<typeof TextInputPlugin>) {
const app = bootMockApp().app;
@@ -119,3 +121,23 @@ it.each(['despawn', 'remove'] as const)('blurs the OS surface when the focused f
for (const listener of surfaces[0].listeners) listener({ kind: 'change' });
expect(app.world.get(next, TextInput).value).toBe('typed');
});
+
+it.each(['entity', 'ancestor', 'interaction'] as const)('rejects queued input after disabling %s', async disabled => {
+ const app = build(new TextInputPlugin());
+ const field = app.world.spawn();
+ app.world.insert(field, TextInput, { value: 'original' });
+ app.getResource(FocusManager).focus(field);
+ await app.tick(1 / 60);
+ if (disabled === 'interaction') app.world.insert(field, Interactable, { enabled: false });
+ else if (disabled === 'entity') app.world.insert(field, Disabled);
+ else {
+ const parent = app.world.spawn();
+ app.world.setParent(field, parent);
+ app.world.insert(parent, Disabled);
+ }
+ for (const listener of surfaces[0].listeners) listener({ kind: 'change' });
+ expect(app.world.get(field, TextInput).value).toBe('original');
+ await app.tick(1 / 60);
+ expect(surfaces[0].blur).toHaveBeenCalledOnce();
+ expect(app.world.get(field, TextInput).focused).toBe(false);
+});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 3751546bc..e59f7dea6 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'fix(ui): reject input on disabled text fields':
+ { note: 'Disabled text fields reject queued input.' },
'fix(ui): blur removed text input surfaces':
{ note: 'Removed text fields release OS input focus.' },
'fix(ui): isolate text input cleanup per app':