Textarea テキストエリア
複数行テキストの入力です。高さは行数と内容に伴って伸び、文字数カウントと文字数上限をサポートします。
契約元:
lh-ui-core/specs/textarea.json· ゴールデンケース:lh-ui-core/cases/textarea.json(6 件、hypium テストに翻訳済み)
基本的な使い方
rows が初期の表示行数を決定し、最小の高さは textarea.minHeight トークンを取ります。
HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません
typescript
LhTextarea({
value: this.remark,
placeholder: '備考内容を入力してください',
rows: 3,
onValueChange: (value: string) => { this.remark = value },
})文字数カウント
showCount を true にすると右下に文字数カウントを表示します。maxlength を設定すると 現在 / 上限 を表示し、 設定しない場合は現在の長さのみを表示します。
11/50
0
HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません
API
Props
| プロパティ | 説明 | 型 | デフォルト値 |
|---|---|---|---|
value | 現在のテキスト値(制御) | string | '' |
placeholder | プレースホルダーのテキスト | string | '' |
rows | 初期の表示行数。高さは行数と内容に伴って伸びる | number | 3 |
disabled | 無効にするかどうか。無効時は入力に反応せず、onValueChange を発火しない | boolean | false |
readonly | 読み取り専用にするかどうか。フォーカスはできるが入力を受け付けない | boolean | false |
showCount | 右下に文字数カウントを表示するかどうか | boolean | false |
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。

