Input Beta
Write a native <input><textarea>tg2Input<tg2-input-container>ngModelformControlNameformFieldtypeplaceholdermaxlengthreadonlyautocomplete
Form systems
The container has no value input or output — every form system Angular supports works the same way it always has, straight on the projected <input>
ngModel
<tg2-input-container label="Title">
<input tg2Input required [(ngModel)]="title" />
</tg2-input-container>Reactive forms
readonly form = new FormGroup({
email: new FormControl('', { nonNullable: true, validators: [Validators.required, Validators.email] })
});<form [formGroup]="form">
<tg2-input-container label="Email">
<input tg2Input type="email" formControlName="email" />
</tg2-input-container>
</form>Signal Forms
import { FormField, form, required } from '@angular/forms/signals';
readonly model = signal({ username: '' });
readonly userForm = form(this.model, path => {
required(path.username, { message: 'Username is required' });
});<tg2-input-container label="Username">
<input tg2Input [formField]="userForm.username" />
</tg2-input-container>No forms library
A plain [value](input)
<tg2-input-container label="Title">
<input tg2Input required [value]="title" (input)="title = $any($event.target).value" />
</tg2-input-container>States
| Large (default) | Medium | |
|---|---|---|
| Default | ||
| Filled | ||
| Disabled | ||
| Read-only | ||
| Error |
Label
"(optional)" is added to the label of any field that isn't required. Mark a field required where your form expects it (the requiredValidators.required{ required: true }required()showOptional="false"
Angular doesn't emit an event when validators change. After setValidators()addValidators()removeValidators()clearValidators()updateValueAndValidity()aria-requirederrors
| Default | Hidden | Optional | Floating |
|---|---|---|---|
Icons and clear button
| Icon left | Icon right | Clearable |
|---|---|---|
Characters remaining and textarea
| Characters remaining | Over the limit | Textarea |
|---|---|---|
A native maxlengthcharacterLimit
Going over the limit is a warning while the user types, not an error: the border, aria-invaliderrorMessagengModel[error]maxlength
Screen readers hear the count after the user pauses typing, through a hidden live region, so it isn't read out on every keystroke.
readonly message = new FormControl('', { validators: [Validators.required, Validators.maxLength(500)] });
<tg2-input-container
label="Message"
characterLimit="500"
showRemainingCharacters
errorMessage="Keep your message to 500 characters">
<textarea tg2Input [formControl]="message"></textarea>
</tg2-input-container>Errors from your own validation
By default the error shows once the Angular control is touched and invalid. If your errors are worked out somewhere else, for example in signals with no validators on the control, set [error]truearia-invalidfalse
readonly firstName = signal('');
readonly firstNameError = computed(() => (this.touched() || this.submitted()) && !this.firstName());
<tg2-input-container label="First name" errorMessage="Enter your first name" [error]="firstNameError()">
<input tg2Input required [ngModel]="firstName()" (ngModelChange)="firstName.set($event)" />
</tg2-input-container>Radius
Set radiussmallmediumlargetg-lighttg-dark
| small (4px) | medium (8px) | large (16px) |
|---|---|---|
API
tg2-input-container
The container has no value input or output — bind your form directive on the native element instead. aria-invalidaria-requiredaria-describedbyrequiredValidators.requiredrequired
Selector: tg2-input-containerTg2InputContainerComponent@trademe/tangram
| Input | Values | Default | Constraints |
|---|---|---|---|
label | string | — | Required. |
showLabel | boolean | true | |
description | string | — | |
errorMessage | string | — | |
error | boolean | — | |
showOptional | boolean | true | |
floatingLabel | boolean | false | |
size | mediumlarge | large | |
iconLeft | TangramIconKind | — | |
iconRight | TangramIconKind | — | |
clearable | boolean | false | |
showRemainingCharacters | boolean | false | |
characterLimit | number | — | |
radius | smallmediumlarge | — | |
theme | tg2-lighttg2-darktg-lighttg-dark | tg2-light |
Content slots: [tg2Input]
sets the label text.label hides the label visually. Screen readers still announce it.showLabel="false" is helper text. The footer shows it when there is no error or character count to show.description shows in the footer when the control is touched and invalid, or whenerrorMessage iserror .true sets the error state directly, for validation outside the Angular forms API. Unset, it follows the control.error adds "(optional)" to the label when the field is not required. SetshowOptional to hide it.false puts the label inside the field. The container ignores it whenfloatingLabel is false.showLabel takessize values and sets the field height. Medium is 38px. Large is 48px, or 56px with a floating label.Tg2InputSizeEnum andiconLeft show a decorative icon before or after the field.iconRight shows a clear button while the field has a value. The button clears the native value and dispatches anclearable event. It does not submit the form.input needsshowRemainingCharacters or acharacterLimit on the native element.maxlength sets the limit for the characters remaining counter. UnlikecharacterLimit , it does not stop typing, so the counter can show how far over the value is. Over the limit is a warning, not an error: pair it with a max length validator andmaxlength to block sending. Unset, it uses the nativeerrorMessage .maxlength sets the corner radius (4px, 8px, 16px). Unset, the theme sets it: 8px, or 3px for tg-light and tg-dark.radius sets the visual design system of the field.theme
tg2Input
Selector: input[tg2Input], textarea[tg2Input]
| Input | Type | Description |
|---|---|---|
id | string | A consumer-supplied id for the native element. When omitted, an id is generated automatically. |
aria-describedby | string | Ids of your own elements that describe the field. They're kept, and the footer's id is added after them. Set it as aria-describedby="…"[aria-describedby]="…"[attr.aria-describedby] |
Try every option interactively on the Code Example page.