Skip to content

Input 輸入框 ​

受控單行輸入框,支援尺寸、停用、唯讀、清除、密碼遮罩與最大長度。

契約源:lh-ui-core/specs/input.json · 黃金用例:cases/input.json(8 條,已翻譯為 JVM 單測 + Compose UI Test)

基本用法 ​

9:41Input

HTML 模擬預覽(Android / Compose 外觀),非真機渲染

kotlin
var value by remember { mutableStateOf("") }
LhInput(
  value = value,
  placeholder = "請輸入內容",
  onValueChange = { value = it },
)

尺寸與焦點 ​

三檔尺寸對應到 input.height / input.paddingHorizontal / input.fontSize 令牌;聚焦時描邊取 color.focus 並加寬到 input.focusRingWidth。

9:41Input 尺寸

HTML 模擬預覽(Android / Compose 外觀),非真機渲染

API ​

Props ​

屬性說明類型預設值
value受控值(必填)String—
onValueChange值變更回呼(必填)(String) -> Unit—
placeholder佔位文字String?null
type輸入類型(明文 / 密碼)LhInputTypeText
lhSize尺寸LhInputSizeMedium
disabled是否停用Booleanfalse
readonly是否唯讀(不可編輯但不停用樣式)Booleanfalse
clearable是否顯示清除按鈕Booleanfalse
maxlength最大長度(超長截斷)IntInt.MAX_VALUE
lhOnFocus / lhOnBlur聚焦 / 失焦回呼(() -> Unit)?null
prefix / suffix前綴 / 後綴插槽@Composable (() -> Unit)?null
modifier修飾符ModifierModifier

LhInputSize ​

值heightpaddingHorizontalfontSize
Smallinput.height.small(32dp)input.paddingHorizontal.small(12dp)input.fontSize.small(13sp)
Mediuminput.height.medium(40dp)input.paddingHorizontal.medium(16dp)input.fontSize.medium(14sp)
Largeinput.height.large(48dp)input.paddingHorizontal.large(20dp)input.fontSize.large(16sp)

令牌對照 ​

令牌用途
input.height.{small,medium,large}三檔高度
input.paddingHorizontal.{small,medium,large}三檔橫向內邊距
input.fontSize.{small,medium,large}三檔字級
input.borderRadius / input.borderWidth / input.focusRingWidth圓角 / 描邊寬 / 焦點描邊寬
input.clearIconSize清除圖示尺寸
color.focus焦點描邊色
color.text.placeholder佔位文字色
color.border.base預設描邊色
color.disabled.{bg,text,border}停用態三色

黃金用例對照 ​

case id斷言本地測試
input-emits-onvaluechange輸入觸發 onValueChangeLhInputTest.input_emits_onValueChange(Compose UI Test)
clearable-emits-empty-value清除按鈕發射空值LhInputTest.clearable_emits_empty_value
disabled-blocks-input停用態不可輸入LhInputTest.disabled_blocks_input
readonly-blocks-input唯讀態不可輸入LhInputTest.readonly_blocks_input
placeholder-uses-placeholder-token佔位色取佔位令牌LhInputDefaultsTest.placeholder_uses_placeholder_token
focus-uses-focus-token聚焦消費焦點令牌(失焦取中性描邊)LhInputDefaultsTest.focus_uses_focus_tokens + unfocused_uses_neutral_tokens
small-size-uses-small-tokens小號消費 small 尺寸令牌LhInputDefaultsTest.small_size_uses_small_tokens
maxlength-truncates-input超長輸入截斷LhInputTest.maxlength_truncates_input
bash
./gradlew :components:input:test                              # JVM 部分
./gradlew :components:input:connectedAndroidTest              # 互動部分(需裝置)