来源:docs/kit/components/input.md · API 参考

Input

何时使用

最小示例

input = Tessell::Kit::Input.new(
  Tessell::UI::UiKey.root.child(1_u64),
  "",
  "Type here…",
  "Name"
)
input.on_change = ->(value : String) { @name = value; nil }
input.on_submit = ->(value : String) { submit(value); nil }

状态

键盘与编辑

键行为
字符输入 / TextInput在光标处插入,替换选区,触发一次 on_change
Left/Right按 grapheme cluster 移动;有选区时折叠
Shift+Left/Right扩展/收缩选区
Home/End到行首/行尾(Shift 扩展)
Backspace/Delete按 grapheme cluster 删除;有选区时删除选区
Ctrl/Cmd+A全选
Ctrl/Cmd+C/X/V复制/剪切/粘贴;read-only 下禁止剪切/粘贴
Enter触发 on_submit,不插入换行
Escape折叠选区

剪贴板

通过注入的 Kit::Clipboard 实现;默认 MemoryClipboard。平台剪贴板需要应用提供实现:

input.clipboard = MyPlatformClipboard.new

组件不直接调用系统剪贴板 API。

IME / 组合输入

无障碍

主题 token

surface/surface_raised 背景、border/focus/danger 边框、selection 选区、foreground/muted 文本、accent 组合输入。

限制