Skip to content

Textarea テキストエリア ​

コントロールドな複数行入力フィールド。@Binding var value で双方向バインディングし、プレースホルダーテキストと文字数カウントを重ねて表示します。

契約ソース:lh-ui-core/specs/textarea.json · ゴールデンケース:lh-ui-core/cases/textarea.json(6 件、XCTest に翻訳済み、macOS ホストだけで実行可能)

基本形 ​

最小の高さは textarea.minHeight、パディングは textarea.paddingHorizontal / paddingVertical を取ります。 フォーカス時に枠線を color.focus に切り替えます。

9:41Textarea 基本

HTML シミュレーションプレビュー(iOS / SwiftUI の外観)であり、実機でのレンダリングではありません

swift
@State private var text = ""

LhTextarea(value: $text, placeholder: "内容を入力してください") { newValue in
  // onValueChange
}

文字数カウント ​

showCount = true のとき右下にカウントを表示します。maxlength を設定すると 現在/上限 という形式になります(ゴールデンケース showcount-renders-count)。未設定なら現在の長さのみを表示します(showcount-without-maxlength-renders-length-only)。

9:41Textarea カウント
3/10

HTML シミュレーションプレビュー(iOS / SwiftUI の外観)であり、実機でのレンダリングではありません

swift
LhTextarea(value: $text, showCount: true, maxlength: 10)

API ​

プロパティ ​

プロパティ説明型デフォルト値
value入力内容(コントロールドな双方向バインディング)String—
placeholderプレースホルダーテキストString""
rows期待する行数(最小の高さに影響)Int3
disabled無効にするかどうか(コールバックを発火しない)Boolfalse
readonly読み取り専用かどうか(onValueChange を発火しない、フォーカススタイルは保持)Boolfalse
showCount文字数カウントを表示するかどうかBoolfalse
maxlength最大字数(超過すると切り詰め)Int?nil
onValueChange内容変化のコールバック。payload は新しい値((String) -> Void)?nil
lhOnFocusフォーカス時のコールバック(() -> Void)?nil
lhOnBlurフォーカス外れのコールバック(() -> Void)?nil

色 ​

状態枠線文字 / プレースホルダー
デフォルトcolor.border.base(textarea.borderWidth)color.text.primary / color.text.placeholder
フォーカスcolor.focus(textarea.focusRingWidth)同上
無効color.disabled.bordercolor.disabled.text

トークン対応表 ​

トークン用途
textarea.minHeight最小の高さ
textarea.paddingHorizontal / textarea.paddingVerticalパディング
textarea.fontSizeフォントサイズ
textarea.countFontSizeカウント文字のフォントサイズ
textarea.borderRadius / textarea.borderWidth角丸と枠線の太さ
textarea.focusRingWidthフォーカスリングの幅
color.focusフォーカス時の枠線色
color.text.{primary,placeholder,disabled}文字とプレースホルダーの色
color.border.base / color.disabled.border枠線色
color.background.default / color.disabled.bg底色

ゴールデンケース対応表 ​

case idアサーションローカルテスト
input-emits-onvaluechange入力で onValueChange("青花瓷") を発火testDefaultIsEditable
disabled-blocks-input無効状態は onValueChange を発火しないtestDisabledBlocksInput
showcount-renders-countカウントが 3/10 を表示しカウントフォントサイズトークンを消費testShowCountRendersCount
showcount-without-maxlength-renders-length-only上限なしだと 3 のみ表示testShowCountWithoutMaxlengthRendersLengthOnly
focus-uses-focus-tokenフォーカスは focus トークンを消費し lhOnFocus を発火testFocusUsesFocusToken
maxlength-truncates-input字数超過で切り詰めtestMaxlengthTruncatesInput

さらに関連テスト:testLayoutUsesTextareaTokens / testReadonlyBlocksInputButKeepsFocusStyle / testDarkColorsComeFromDarkTokens / testDimensionsAreIdenticalInDarkMode / testTextareaViewInitAcceptsConstant。

bash
swift test --filter LhTextareaTests    # macOS ホストだけで実行可能、シミュレーター不要

lh-ui ネイティブ血脈 · iOS 端(Swift + SwiftUI)