Skip to content

Textarea テキストエリア ​

複数行テキストの入力です。高さは行数と内容に伴って伸び、文字数カウントと文字数上限をサポートします。

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

基本的な使い方 ​

rows が初期の表示行数を決定し、最小の高さは textarea.minHeight トークンを取ります。

9:41Textarea 基本

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

typescript
LhTextarea({
  value: this.remark,
  placeholder: '備考内容を入力してください',
  rows: 3,
  onValueChange: (value: string) => { this.remark = value },
})

文字数カウント ​

showCount を true にすると右下に文字数カウントを表示します。maxlength を設定すると 現在 / 上限 を表示し、 設定しない場合は現在の長さのみを表示します。

9:41Textarea 文字数カウント
11/50
0

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

API ​

Props ​

プロパティ説明型デフォルト値
value現在のテキスト値(制御)string''
placeholderプレースホルダーのテキストstring''
rows初期の表示行数。高さは行数と内容に伴って伸びるnumber3
disabled無効にするかどうか。無効時は入力に反応せず、onValueChange を発火しないbooleanfalse
readonly読み取り専用にするかどうか。フォーカスはできるが入力を受け付けないbooleanfalse
showCount右下に文字数カウントを表示するかどうかbooleanfalse
maxlength最大文字数。超えると切り詰め。showCount の際に分母になるnumber?undefined
onValueChangeテキストの変化時に発火。disabled / readonly の場合は発火しない(value: string) => void空の関数
onFocusフォーカスを取得した時に発火() => void空の関数
onBlurフォーカスを失った時に発火() => void空の関数

トークン对照 ​

トークン用途
textarea.minHeight内容がないときの最小の高さ(72vp、約 3 行)
textarea.paddingHorizontal / textarea.paddingVerticalパディング(12 / 12vp)
textarea.fontSize入力のフォントサイズ(14)
textarea.countFontSize文字数カウントのフォントサイズ(12)
textarea.borderRadius / textarea.borderWidth円角とボーダー幅
textarea.focusRingWidthフォーカスリングの幅
typography.lineHeight.primary行の高さ(1.8)
color.text.primary / color.text.placeholder入力テキスト / プレースホルダーのテキストの色
color.background.default / color.background.disabled背景色 / 無効時の背景色
color.border.base / color.focusボーダー色 / フォーカス色

ゴールデンケース对照 ​

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

case idアサーションローカルのテスト
input-emits-onvaluechange入力が onValueChange を発火disabled_is_not_interactive(ゲートの反転アサーション)
disabled-blocks-input無効状態は入力に反応しないdisabled_is_not_interactive
showcount-renders-count文字数カウントが 現在 / 上限 をレンダリングshowcount_renders_count_with_maxlength
showcount-without-maxlength-renders-length-only上限がないときは長さのみ表示showcount_renders_length_only_without_maxlength
focus-uses-focus-tokenフォーカス状態が focus トークンを取るfocus_uses_focus_token
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)