Skip to content

Input 入力フィールド ​

単行テキストの入力です。パスワードタイプ、3 段階のサイズ、無効 / 読み取り専用、クリアボタン、文字数上限をサポートします。

契約元: lh-ui-core/specs/input.json · ゴールデンケース: lh-ui-core/cases/input.json(8 件、hypium テストに翻訳済み)

基本的な使い方 ​

value は制御され、placeholder は color.text.placeholder トークンを取ります。

9:41Input 基本

HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません

typescript
LhInput({
  value: this.text,
  placeholder: '内容を入力してください',
  clearable: true,
  onValueChange: (value: string) => { this.text = value },
})

フォーカスとサイズ ​

フォーカス時にボーダーが color.focus に切り替わり、input.focusRingWidth の幅のフォーカスリングが重ねられます。 3 段階のサイズが input.height / paddingHorizontal / fontSize トークンに対応します。

9:41Input フォーカスとサイズ

HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません

状態とクリア ​

disabled は入力を無効にし無効な見た目を表示します。clearable は値があるときクリアボタンを表示し、 クリックで onValueChange('') を発火します。maxlength を超えると新しい入力は切り詰められます。

9:41Input 状態
✕

HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません

API ​

Props ​

プロパティ説明型デフォルト値
value現在のテキスト値(制御)string''
placeholderプレースホルダーのテキストstring''
type入力タイプ。パスワードタイプは ArkUI の InputType.Password にマッピングLhInputTypeText
size入力フィールドのサイズ。サイズトークンに対応LhInputSizeMedium
disabled無効にするかどうか。無効時は入力に反応せず、onValueChange を発火しないbooleanfalse
readonly読み取り専用にするかどうか。フォーカスはできるが入力を受け付けないbooleanfalse
clearableクリアボタンを表示するかどうか(値があるとき)booleanfalse
maxlength最大文字数。超えると切り詰め。undefined の場合は制限しないnumber?undefined
onValueChangeテキストの変化時に発火。disabled / readonly の場合は発火しない(value: string) => void空の関数
onFocusフォーカスを取得した時に発火() => void空の関数
onBlurフォーカスを失った時に発火() => void空の関数

LhInputType ​

値端側の実装
TextArkUI InputType.Normal
PasswordArkUI InputType.Password(マスク表示)

LhInputSize ​

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

トークン对照 ​

トークン用途
input.height.{small,medium,large}3 段階の高さ
input.paddingHorizontal.{small,medium,large}3 段階の水平パディング
input.fontSize.{small,medium,large}3 段階のフォントサイズ
input.borderRadius / input.borderWidth円角とボーダー幅
input.focusRingWidthフォーカスリングの幅
input.clearIconSizeクリアボタンのサイズ(16vp)
color.text.primary / color.text.placeholder入力テキスト / プレースホルダーのテキストの色
color.background.default / color.background.disabled背景色 / 無効時の背景色
color.border.base / color.focusボーダー色 / フォーカス色
color.disabled.text無効時のテキスト色

ゴールデンケース对照 ​

cases/input.json の 8 件のアサーションと hypium テストの対応関係(entry/src/test/Input.test.ets):

case idアサーションローカルのテスト
input-emits-onvaluechange入力が onValueChange を発火disabled_is_not_interactive(ゲートの反転アサーション)
clearable-emits-empty-valueクリアが空値のコールバックを発火clear_icon_uses_token(クリアアイコンがトークンを消費)
disabled-blocks-input無効状態は入力に反応しないdisabled_is_not_interactive
readonly-blocks-input読み取り専用状態は入力に反応しないreadonly_still_enabled_in_appearance
placeholder-uses-placeholder-tokenプレースホルダーのテキストがプレースホルダートークンを取るplaceholder_uses_placeholder_token
focus-uses-focus-tokenフォーカス状態が focus トークンを取るfocus_uses_focus_token
small-size-uses-small-tokens小型が small サイズトークンを消費small_size_uses_small_tokens
maxlength-truncates-input上限を超えると切り詰めmaxlength_truncates_input

このほかダーク専用として dark_colors_come_from_dark_tokens / dimensions_are_identical_in_dark_mode があります。 実行方法: DevEco Studio で entry/src/test を右クリック → Run Tests。

lh-ui ネイティブ血脈 · HarmonyOS 端(ArkTS + ArkUI)