scoped
textareaコンポーネントは、複数行のテキスト入力に使用されます。ネイティブの textarea 要素は、コンポーネントの内部でレンダリングされます。ネイティブのtextareaを制御することで、textareaコンポーネントのユーザーエクスペリエンスとインタラクティブ性を向上させることができます。
ネイティブのtextarea要素とは異なり、Ionicのtextareaは要素内部のコンテンツからその値を読み込むことをサポートしていません。textareaの値はvalue属性で設定しなくてはなりません。
textareaコンポーネントはIonicのプロパティに加えて ネイティブのtextareaの属性 に対応します。
ラベルは、textareaを説明するために使用すべきです。視覚的に使用でき、ユーザーがtextareaにフォーカスしたときにスクリーンリーダーによって読み上げられます。これにより、ユーザーがtextareaの意図を理解しやすくなります。Textareaには、ラベルを割り当てるいくつかの方法があります:
label プロパティ: プレーンテキストのラベルに使用
label スロット: カスタムHTMLラベルに使用(実験的)
aria-label: スクリーンリーダーにラベルを提供するために使用されますが、表示されるラベルは追加されません
ラベルは、デフォルトでそのコンテンツの幅を占めます。 開発者は labelPlacement プロパティを使用して、ラベルがどのように配置されるかを制御することができます。
プレーンテキストのラベルは label プロパティを通して渡されるべきですが、カスタム HTML が必要な場合は、代わりに label スロットを通して渡すことができます。
この機能は、Web Component slotsのシミュレート版に依存しているため、実験的なものとみなされていることに注意してください。その結果、シミュレートされた動作はネイティブのスロットの動作と完全に一致するとは限りません。
ラベルの表示が必要ない場合でも、開発者はaria-labelを指定して、textareaがスクリーンリーダーにアクセスできるようにすべきです。
Filled Textareas
Material Designでは、テキストエリアの塗りつぶしスタイルが用意されています。アイテムの fill プロパティは "solid" または "outline" のいずれかに設定することができます。
iOSでは、Textareasのmodeをmdに設定することで、Filled Textareasを使うことができます。
コンポーネント間のスタイリングの競合のため、fillを使用するTextareaはion-item内で使用すべきではありません。
Helper & Error Text
ヘルパーテキストとエラーテキストは、helperText と errorText プロパティを使って textarea 内で使用することができます。エラーテキストは、ion-invalid と ion-touched クラスが ion-textarea に追加されていない限り表示されません。これにより、ユーザがデータを入力する前にエラーが表示されることはありません。
Angularでは、これはフォームバリデーションによって自動的に行われます。JavaScript、React、Vueでは、独自のバリデーションに基づいてクラスを手動で追加する必要があります。
Textarea Counter
textareaカウンターは、textareaの下に表示されるテキストで、textareaが受け付ける合計文字数のうち、何文字が入力されたかをユーザーに通知します。カウンターを追加する場合、デフォルトの動作は、表示される値を inputLength / maxLength としてフォーマットすることです。この動作は、counterFormatterプロパティにフォーマッタ関数を渡すことでカスタマイズすることができます。
autoGrowプロパティがtrueに設定されている場合、テキストエリアはその内容に基づいて拡大・縮小します。
clearOnEditプロパティをtrueに設定すると、テキストエリアが編集削除された後、再度入力されるとクリアされます。
startとendスロットは、textareaの両側にアイコン、ボタン、またはプレフィックス/サフィックステキストを配置するために使用できます。
この機能は、Web Component slotsのシミュレート版に依存しているため、実験的なものとみなされていることに注意してください。その結果、シミュレートされた動作はネイティブのスロットの動作と完全に一致するとは限りません。
ほとんどの場合、これらのスロットに配置されたIconコンポーネントにはaria-hidden="true"を設定すべきです。詳細については、Icon accessibility docsを参照してください。
スロットコンテンツが操作対象である場合、Buttonなどのインタラクティブ要素でラップする必要があります。これにより、コンテンツにタブで移動できるようになります。
TextareaChangeEventDetail
interface TextareaChangeEventDetail {
value?: string | null;
}
TextareaCustomEvent
必須ではありませんが、このコンポーネントから発行される Ionic イベントでより強く型付けを行うために、CustomEvent インターフェースの代わりにこのインターフェースを使用することが可能です。
interface TextareaCustomEvent extends CustomEvent {
detail: TextareaChangeEventDetail;
target: HTMLIonTextareaElement;
}
| Description | If true, the textarea container will grow and shrink based on the contents of the textarea. |
| Attribute | auto-grow |
| Type | boolean |
| Default | false |
| Description | Indicates whether and how the text value should be automatically capitalized as it is entered/edited by the user. Available options: "off", "none", "on", "sentences", "words", "characters". |
| Attribute | autocapitalize |
| Type | string |
| Default | 'none' |
| Description | Sets the autofocus attribute on the native input element.
This may not be sufficient for the element to be focused on page load. See managing focus for more information. |
| Attribute | autofocus |
| Type | boolean |
| Default | false |
| Description | If true, the value will be cleared after focus upon edit. |
| Attribute | clear-on-edit |
| Type | boolean |
| Default | false |
| Description | The color to use from your application's color palette. Default options are: "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", and "dark". For more information on colors, see theming. |
| Attribute | color |
| Type | "danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string | undefined |
| Default | undefined |
| Description | The visible width of the text control, in average character widths. If it is specified, it must be a positive integer. |
| Attribute | cols |
| Type | number | undefined |
| Default | undefined |
| Description | If true, a character counter will display the ratio of characters used and the total character limit. Developers must also set the maxlength property for the counter to be calculated correctly. |
| Attribute | counter |
| Type | boolean |
| Default | false |
| Description | Set the amount of time, in milliseconds, to wait to trigger the ionInput event after each keystroke. |
| Attribute | debounce |
| Type | number | undefined |
| Default | undefined |
| Description | If true, the user cannot interact with the textarea. |
| Attribute | disabled |
| Type | boolean |
| Default | false |
| Description | A hint to the browser for which enter key to display. Possible values: "enter", "done", "go", "next", "previous", "search", and "send". |
| Attribute | enterkeyhint |
| Type | "done" | "enter" | "go" | "next" | "previous" | "search" | "send" | undefined |
| Default | undefined |
errorText
| Description | Text that is placed under the textarea and displayed when an error is detected. |
| Attribute | error-text |
| Type | string | undefined |
| Default | undefined |
| Description | The fill for the item. If "solid" the item will have a background. If "outline" the item will be transparent with a border. Only available in md mode. |
| Attribute | fill |
| Type | "outline" | "solid" | undefined |
| Default | undefined |
helperText
| Description | Text that is placed under the textarea and displayed when no error is detected. |
| Attribute | helper-text |
| Type | string | undefined |
| Default | undefined |
| Description | A hint to the browser for which keyboard to display. Possible values: "none", "text", "tel", "url", "email", "numeric", "decimal", and "search". |
| Attribute | inputmode |
| Type | "decimal" | "email" | "none" | "numeric" | "search" | "tel" | "text" | "url" | undefined |
| Default | undefined |
| Description | The visible label associated with the textarea.
Use this if you need to render a plaintext label.
The label property will take priority over the label slot if both are used. |
| Attribute | label |
| Type | string | undefined |
| Default | undefined |
| Description | Where to place the label relative to the textarea. "start": The label will appear to the left of the textarea in LTR and to the right in RTL. "end": The label will appear to the right of the textarea in LTR and to the left in RTL. "floating": The label will appear smaller and above the textarea when the textarea is focused or it has a value. Otherwise it will appear on top of the textarea. "stacked": The label will appear smaller and above the textarea regardless even when the textarea is blurred or has no value. "fixed": The label has the same behavior as "start" except it also has a fixed width. Long text will be truncated with ellipses ("..."). |
| Attribute | label-placement |
| Type | "end" | "fixed" | "floating" | "stacked" | "start" |
| Default | 'start' |
| Description | This attribute specifies the maximum number of characters that the user can enter. |
| Attribute | maxlength |
| Type | number | undefined |
| Default | undefined |
| Description | This attribute specifies the minimum number of characters that the user can enter. |
| Attribute | minlength |
| Type | number | undefined |
| Default | undefined |
| Description | The mode determines which platform styles to use.
This is a virtual property that is set once during initialization and will not update if you change its value after the initial render. |
| Attribute | mode |
| Type | "ios" | "md" |
| Default | undefined |
| Description | The name of the control, which is submitted with the form data. |
| Attribute | name |
| Type | string |
| Default | this.inputId |
| Description | Instructional text that shows before the input has a value. |
| Attribute | placeholder |
| Type | string | undefined |
| Default | undefined |
| Description | If true, the user cannot modify the value. |
| Attribute | readonly |
| Type | boolean |
| Default | false |
| Description | If true, the user must fill in a value before submitting a form. |
| Attribute | required |
| Type | boolean |
| Default | false |
| Description | The number of visible text lines for the control. |
| Attribute | rows |
| Type | number | undefined |
| Default | undefined |
| Description | The shape of the textarea. If "round" it will have an increased border radius. |
| Attribute | shape |
| Type | "round" | undefined |
| Default | undefined |
| Description | If true, the element will have its spelling and grammar checked. |
| Attribute | spellcheck |
| Type | boolean |
| Default | false |
| Description | The value of the textarea. |
| Attribute | value |
| Type | null | string | undefined |
| Default | '' |
| Description | Indicates how the control wraps text. |
| Attribute | wrap |
| Type | "hard" | "off" | "soft" | undefined |
| Default | undefined |