UI Components
TextField
UI component for single-line text entry.
<TextField>
is a UI component for single-line text entry.
For multi-line text input, see TextView.
<TextFieldhint="Placeholder..." />
<TextFieldhint="Placeholder..." />
<textFieldhint="Type here" />
<textfieldhint="Placeholder..." />
<textFieldhint="Placeholder..." />
<TextFieldhint="Placeholder..." />
Examples β
Formatting text inside a TextField β
If you need to style parts of the text, you can use a combination of a FormattedString
and Span
elements.
<TextField>
<FormattedString>
<Spantext="This text has a " />
<Spantext="red "style="color: red" />
<Spantext="piece of text. " />
<Spantext="Also, this bit is italic, "fontStyle="italic" />
<Spantext="and this bit is bold."fontWeight="bold" />
</FormattedString>
</TextField>
Props β
text β
text: string
Gets or sets the text
of the TextField.
hint β
hint: string
Gets or sets the placeholder text for the TextField.
editable β
editable: boolean
When set to false
the TextField is read-only.
Defaults to true
.
keyboardType β
keyboardType: CoreTypes.KeyboardType | number // "datetime" | "email" | "integer" | "number" | "phone" | "url"
Gets or sets the keyboard type shown when editing this TextField.
On iOS, any valid UIKeyboardType
number works, for example:
keyboardType =8// UIKeyboardType.DecimalPad
See CoreTypes.KeyboardType, UIKeyboardType.
returnKeyType β
returnKeyType: CoreTypes.ReturnKeyType // "done" | "go" | "next" | "search" | "send"
Gets or sets the label of the return key.
isEnabled β
Allows disabling the TextField. A disabled TextField does not react to user gestures or input.
Default value is true
.
maxLength β
maxLength: number
Limits input to the specified number of characters.
secure β
secure: boolean
Hides the entered text when true
. Useful for password input fields.
Defaults to false
.
secureWithoutAutofill β
secureWithoutAutofill: boolean
Prevents iOS 12+ auto suggested strong password handling. iOS only
Defaults to false
.
autocapitalizationType β
autocapitalizationType: CoreTypes.AutocapitalizationType // "allCharacters" | "none" | "sentences" | "words"
Gets or sets the autocapitalization type.
See CoreTypes.AutocapitalizationType
...Inherited β
For additional inherited properties, refer to the API Reference.
Methods β
focus() β
focus(): boolean
Focuses the TextField and returns true
if the focus was succeessful.
dismissSoftInput() β
dismissSoftInput(): void
Hides the on-screen keyboard.
Events β
textChange β
on('textChange', (args:PropertyChangeData) => {
consttextField= args.object asTextField
console.log('TextField text changed:', args.value)
})
Emitted when the input text changes.
Event data type: PropertyChangeData
returnPress β
on('returnPress', (args:EventData) => {
consttextField= args.object asTextField
console.log('TextField return key pressed.')
})
Emitted when the return key is pressed.
focus β
on('focus', (args:EventData) => {
consttextField= args.object asTextField
console.log('TextField has been focused')
})
Emitted when the TextField gains focus.
blur β
on('blur', (args:EventData) => {
consttextField= args.object asTextField
console.log('TextField has been blured')
})
Emitted when the TextField loses focus.
Native component β
- Android:
android.widget.EditText
- iOS:
UITextField