Creates an input.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
options |
InputOptions |
Options object to use. |
||
options.bg |
Sprite | Graphics | Texture | string |
Background of the Input.
|
||
options.textStyle |
PixiTextStyle |
Text style of the Input. |
||
options.placeholder |
string |
Placeholder of the Input. |
||
options.TextClass |
PixiTextClass |
<optional> |
Text |
Class used to draw the text and the placeholder,
e.g. |
options.value |
string |
Value of the Input. |
||
options.maxLength |
number |
Max length of the Input, in UTF-16 code units. Also applied to pasted text and keyboard suggestions, which the native limit does not cover. |
||
options.secure |
boolean |
<optional> |
false |
Draws each character as |
options.align |
'left' | 'center' | 'right' |
<optional> |
'left' |
Align of the text, when it fits. |
options.padding |
Padding |
Padding of the Input. |
||
options.padding.top |
number |
Top padding of the Input. |
||
options.padding.right |
number |
Right padding of the Input. |
||
options.padding.bottom |
number |
Bottom padding of the Input. |
||
options.padding.left |
number |
Left padding of the Input. |
||
options.cleanOnFocus |
boolean |
<optional> |
false |
Clear the value each time editing starts. |
options.inputAttributes |
Record<string, string> |
Attributes for the hidden native field,
merged over the defaults that turn off autocomplete, autocapitalize, autocorrect and spellcheck and
tell password managers to ignore the field. Use it for |
||
options.addMask |
boolean |
<optional> |
false |
Add mask to the Input text, so it is cut off when it does not fit. |
options.nineSliceSprite |
Array |
NineSliceSprite values for bg ([left, top, right, bottom]).
|
Example
new Input({
bg: Sprite.from('input.png'),
placeholder: 'Enter text',
padding: {
top: 11,
right: 11,
bottom: 11,
left: 11
} // alternatively you can use [11, 11, 11, 11] or [11, 11] or just 11
});
Extends
- InputTouch
Members
onChange Signal<(text: string) => void>
Fires every time the user changes the text: typing, deleting, pasting, a keyboard suggestion.
Not fired when Input#value is set from code or cleared by cleanOnFocus; during an IME
composition that goes over maxLength it waits until the composition is committed and cut.
onEnter Signal<(text: string) => void>
Fires once when editing ends — Enter, Escape, or focus leaving the input (a press elsewhere, Tab, a dismissed keyboard) — with the current value.
True while the browser is composing text in the field (IME, or an Android keyboard composing a word).
- Default Value:
- false
Shared ticker callback that drives the caret blink; kept as a field so destroy() can detach it.
Methods
Any press anywhere on the page forgets the component's own, so a blur that follows a press elsewhere, however quickly, ends the session. The component's pointerdown runs after this and marks the press again when it was on the component.
| Name | Type | Description |
|---|---|---|
e |
Event |
the press, anywhere on the page. |
Ends the session when focus genuinely leaves — a click elsewhere, Tab, a dismissed keyboard. A press on the component itself also blurs the hidden field, because the canvas takes focus; that would end and restart editing on every caret move, losing the selection and emitting onEnter, so focus is handed back instead. The press is recognised by time rather than by a held flag: touch browsers move focus on the tap gesture, after the release, and a cancelled pointer never reports a release at all.
The composed text is committed; apply anything that had to wait for it, such as the maxLength cut.
Mirrors the hidden native input, which is the only thing that knows what the text
actually is. Reconstructing it from keydown cannot work on mobile: on-screen
keyboards report Unidentified there and only send the real characters on input,
and composition, autocorrect and suggestions have no keydown representation at all.
Handles the keys that control the editing session itself. Text content is handled by Input.onInput, so this deliberately does not insert or delete characters.
| Name | Type | Description |
|---|---|---|
e |
KeyboardEvent |
the native keyboard event. |
Detaches and removes the hidden DOM input, if one is currently mounted.
Pushes a programmatic edit into the hidden field, so it does not overwrite the change on the next input.
Inherited Properties
From class InputTouch
A drag on the hidden field counts once it has moved past the threshold.
Set around the synthetic click() on focus so it is not mistaken for a tap on the field.
- Default Value:
- false
Index a press on the hidden field went down on, while a drag-selection on it is possible.
True once a press on the hidden field has dragged, so the click that ends it is not taken as a tap.
- Default Value:
- false
Whether presses should land on the hidden field itself rather than on the canvas. On touch devices the field has to stay the touch target: its long-press callout is the only paste path on iOS. Taps on it are mapped onto the drawn text by Input.onFieldClick.
From class InputSelection
Frames since the drag-selection last auto-scrolled.
- Default Value:
- 0
contextSelection [number, number, SelectionDirection] | undefined protected inherited
Selection a right-button press settled on, to put back after the context-menu request collapses it.
Index the pointer went down on while editing; set while a drag-selection is in progress.
Local x of the pointer during a drag-selection, on the canvas or the hidden field, for auto-scrolling.
performance.now() of the last press, drag or release on the component, so a blur of the
hidden field that the press caused can be told apart from focus genuinely leaving.
- Default Value:
- -
Selection to apply once the hidden field exists, set by a pointer press before editing began.
Multi-click counting; see TapCounter.
From class InputText
Whether the drawn text is wider than the space it has.
Prefix widths of the displayed text at each grapheme boundary, measured once per text and style.
How far the text is shifted left, in local units, so the caret stays inside the visible width when the text is wider than it. Zero while the text fits or the input is idle.
- Default Value:
- 0
Left edge of the drawn text in local coordinates, whatever its anchor.
Width available to the text: the background less the horizontal padding.
From class InputView
Sets the background: a texture name, a Texture, a Sprite or a Graphics. A texture name or Texture
becomes a NineSliceSprite when nineSliceSprite is set. The previous background is destroyed.
Sets height of a Input. If nineSliceSprite is set, then height will be set to nineSliceSprite. If nineSliceSprite is not set, then height will control components height as Container.
Set paddings
Bottom side padding
- Default Value:
- 0
Left side padding
- Default Value:
- 0
Right side padding
- Default Value:
- 0
Top side padding
- Default Value:
- 0
Masks the drawn text with * and switches the hidden field to type="password". Can be toggled
while editing, e.g. for a show/hide password button; the caret and selection are kept.
Sets the input text.
Sets width of a Input. If nineSliceSprite is set, then width will be set to nineSliceSprite. If nineSliceSprite is not set, then width will control components width as Container.
What is drawn: the value itself, or one mask character per code unit when secure.
selectionDirection SelectionDirection protected inherited
Which end of the mirrored selection holds the caret.
- Default Value:
- "none"
End of the mirrored selection; equal to InputView#selectionStart for a plain caret.
- Default Value:
- 0
Mirror of the hidden field's selection, in UTF-16 code units of Input.value. Collapsed (start === end) when there is just a caret.
- Default Value:
- 0
Inherited Methods
From class InputTouch
The caret index nearest to a point on the hidden field. The field sits at the component's global position, so an offset into it is an offset in global space.
| Name | Type | Description |
|---|---|---|
clientX |
number |
horizontal position in the viewport. |
clientY |
number |
vertical position in the viewport. |
Returns:
| Type | Description |
|---|---|
| number |
The local x of a point on the hidden field; see Input.indexAtClient.
| Name | Type | Description |
|---|---|---|
clientX |
number |
horizontal position in the viewport. |
clientY |
number |
vertical position in the viewport. |
Returns:
| Type | Description |
|---|---|
| number |
A tap on the hidden field placed the native caret by the field's own layout, which never matches the canvas; move it to where the tap landed on the drawn text instead.
| Name | Type | Description |
|---|---|---|
e |
MouseEvent |
the click on the field. |
A press on the hidden field may become a drag-selection; the field's own drag would select nothing on touch devices, or select by its invisible layout.
| Name | Type | Description |
|---|---|---|
e |
PointerEvent |
the press on the field. |
| Name | Type | Description |
|---|---|---|
e |
PointerEvent |
From class InputSelection
Selects the whole value. Only takes effect while the input is being edited.
Keeps a drag-selection held past an edge of overflowing text moving, one character every few frames, as a native field auto-scrolls; the text follows the focus end.
| Name | Type | Description |
|---|---|---|
dt |
number |
ticker delta, in frames. |
Clamps a local x to the visible text area while the text overflows, so a drag past an edge selects up to the edge and auto-scrolls from there, rather than jumping into the hidden text.
| Name | Type | Description |
|---|---|---|
localX |
number |
x in the component's local space. |
Returns:
| Type | Description |
|---|---|
| number |
Counts taps in a quick sequence at one spot, as a multi-click. Pixi's detail does this
per pointer id, and touch browsers issue a new id for every touch, so it stays at 1 there.
| Name | Type | Description |
|---|---|---|
e |
FederatedPointerEvent |
the tap. |
Returns:
| Type | Description |
|---|---|
| number |
Counts a tap at a position; see Input.countTap. The canvas path passes global coordinates and the hidden-field path client coordinates, which never mix on one device.
| Name | Type | Default | Description |
|---|---|---|---|
x |
number |
horizontal position of the tap. |
|
y |
number |
vertical position of the tap. |
|
touch |
boolean | false |
whether it is a finger, which gets a wider spot and a shorter window. |
Returns:
| Type | Description |
|---|---|
| number |
Sets a drag-selection from its anchor to a focus index, with the direction the drag went.
| Name | Type | Description |
|---|---|---|
anchor |
number |
index the drag started from. |
focus |
number |
index the drag is at now. |
The caret index nearest to a pointer, snapped to grapheme boundaries so a click can never land inside a surrogate pair or combining sequence.
| Name | Type | Description |
|---|---|---|
e |
FederatedPointerEvent |
pointer event in global coordinates. |
Returns:
| Type | Description |
|---|---|
| number |
Restores the selection a right-button press settled on. The browser adjusts the document selection as part of showing a context menu, after the press, which collapses the hidden field's selection; it is put back once the menu request has been processed.
| Name | Type | Description |
|---|---|---|
e |
FederatedPointerEvent |
| Name | Type | Description |
|---|---|---|
e |
FederatedPointerEvent |
Handles a tap during editing: a double click selects a word, a triple click the whole value.
| Name | Type | Description |
|---|---|---|
e |
FederatedPointerEvent |
the tap. |
clicks |
click count from TapCounter: 2 selects a word, 3 the whole value. |
Selects the run of like characters (word, whitespace or punctuation) around an index, as a double click does in a native field.
| Name | Type | Description |
|---|---|---|
index |
number |
position in Input.value to expand from. |
Sets the selection on the hidden field and mirrors it back.
| Name | Type | Default | Description |
|---|---|---|---|
start |
number |
first selected index. |
|
end |
number |
index after the last selected one; equal to |
|
direction |
SelectionDirection | 'none' |
which end holds the caret, for Shift-extension. |
Copies the hidden field's selection into the component and moves the drawn caret and selection highlight to match. The browser owns caret movement — arrows, Home/End, Shift-selection, word jumps — so this is read back rather than reimplemented.
From class InputText
Redraws the selection highlight behind the selected range, or clears it when collapsed.
Returns:
| Type | Description |
|---|---|
| 0 | 1 | 0.5 |
X of the drawn caret: the focus end of the selection, measured along the displayed text.
The caret index nearest to an x in local coordinates, see Input.indexAt.
| Name | Type | Description |
|---|---|---|
localX |
number |
x in the component's local space. |
Returns:
| Type | Description |
|---|---|
| number |
Width of a string in the text field's style. Only ever used as a ratio against the full string, so the unit does not matter — which also keeps bitmap and canvas text on one path.
| Name | Type | Description |
|---|---|---|
text |
string |
string to measure. |
Returns:
| Type | Description |
|---|---|
| number |
Horizontal offset from Input.textLeft to the caret position before index.
| Name | Type | Description |
|---|---|---|
index |
number |
position in the displayed text. |
Returns:
| Type | Description |
|---|---|
| number |
Widths of every grapheme prefix of the displayed text, in the text's style. Measured once per text and style rather than on every pointer move, which would be quadratic in the length.
Returns:
| Type | Description |
|---|---|
| { boundaries : number[], widths : number[] } |
Shifts overflowing text so the caret stays inside the visible width, scrolling only as far as needed in the caret's direction, as a native field does. Idle text shows its start.
From class InputView
| Name | Type | Attributes | Description |
|---|---|---|---|
value |
number | Optional<Size, "height"> | ||
height |
number |
<optional> |
| Name | Type | Description |
|---|---|---|
bg |
ViewType |