import { Component } from '@angular/core';
import { WrInput, WrInputGroup, WrInputPrefix, WrInputSuffix, WrPasswordToggle } from 'ngwr/input';
@Component({ imports: [WrInput, WrInputGroup, WrInputPrefix, WrInputSuffix, WrPasswordToggle] })
export class MyComponent {}Input
A directive that styles a native <input> or <textarea>.
Installation
Import the class, and @use the entry point in your global styles: without it the component renders unstyled.
Basic usage
<input wrInput placeholder="Type here…" [(ngModel)]="text" />Types
Set any native type.
<input wrInput type="email" placeholder="[email protected]" />
<input wrInput type="number" placeholder="0" />
<input wrInput type="search" placeholder="Search" />Prefix & suffix
Wrap the input in <wr-input-group> and mark its siblings with wrInputPrefix or wrInputSuffix.
<wr-input-group>
<span wrInputPrefix>$</span>
<input wrInput type="number" [(ngModel)]="amount" />
<span wrInputSuffix>USD</span>
</wr-input-group>Rounded
<input wrInput rounded placeholder="Rounded" />Password reveal
<wr-password-toggle [for]> switches its input between password and text.
<wr-input-group>
<input wrInput type="password" [(ngModel)]="password" #pwInput />
<wr-password-toggle [for]="pwInput" />
</wr-input-group>Input masking — with ngx-mask
ngwr ships no mask. Put ngx-mask on the same <input>.
pnpm add ngx-maskimport { provideEnvironmentNgxMask } from 'ngx-mask';
bootstrapApplication(AppComponent, {
providers: [provideEnvironmentNgxMask({ thousandSeparator: ',', decimalMarker: '.' })],
});
// In a component:
import { NgxMaskDirective } from 'ngx-mask';
@Component({
imports: [NgxMaskDirective, WrInput, FormsModule],
})
export class MyForm {}<!-- Phone (US-style) -->
<input wrInput mask="(000) 000-0000" placeholder="(555) 555-5555" [(ngModel)]="phone" />
<!-- Credit card -->
<input wrInput mask="0000 0000 0000 0000" placeholder="4242 4242 4242 4242" [(ngModel)]="card" />
<!-- Expiry MM/YY -->
<input wrInput mask="00/00" placeholder="12/29" [(ngModel)]="expiry" />
<!-- CVC (3 digits) -->
<input wrInput mask="000" placeholder="123" [(ngModel)]="cvc" />
<!-- Date DD/MM/YYYY -->
<input wrInput mask="00/00/0000" placeholder="31/12/2026" [(ngModel)]="date" />
<!-- Money: separator with two-decimal precision -->
<wr-input-group>
<span wrInputPrefix>$</span>
<input wrInput mask="separator.2" [(ngModel)]="money" placeholder="1,234.56" />
</wr-input-group>Mask tokens: ngx-mask docs.
Disabled
<input wrInput placeholder="Disabled" disabled />In a form
Binds like any native input, so updateOn and { emitEvent: false } work. See Forms.
[wrInput] directive
| Name | Description | Type | Default |
|---|---|---|---|
wrInput | Styles a native <input> or <textarea>. | attribute | — |
size | Control size. | 'sm' | 'md' | 'lg' | 'md' |
rounded | Pill-shaped corners. | boolean | false |
<wr-input-group>
| Name | Description | Type | Default |
|---|---|---|---|
wr-input-group | Wraps the input with its affixes or toggle. | component | — |
rounded | Pill-shaped corners. | boolean | false |
Prefix & suffix directives
| Name | Description | Type | Default |
|---|---|---|---|
[wrInputPrefix] | The affix before the input: left in LTR, right in RTL. | attribute | — |
[wrInputSuffix] | The affix after the input: right in LTR, left in RTL. | attribute | — |
<wr-password-toggle>
| Name | Description | Type | Default |
|---|---|---|---|
forrequired | The linked password <input> reference. | HTMLInputElement | — |
showLabel | Accessible name while the password is hidden. Defaults to the input.showPassword catalog key. | string | null | null |
hideLabel | Accessible name while the password is shown. Defaults to the input.hidePassword catalog key. | string | null | null |
CSS variables
Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/input's own element.
| Variable | Default | Declared on |
|---|---|---|
--wr-input-bg | var(--wr-color-surface) | .wr-input +1 variant override |
--wr-input-border | var(--wr-border-base) | .wr-input +2 variant overrides |
--wr-input-color | var(--wr-color-on-surface) | .wr-input +1 variant override |
--wr-input-font-family | var(--wr-font-family-base) | .wr-input |
--wr-input-font-size | var(--wr-control-font-size-md) | .wr-input +2 variant overrides |
--wr-input-group-affix | var(--wr-color-on-surface-muted) | .wr-input-group |
--wr-input-group-affix-gap | var(--wr-space-xs) | .wr-input-group |
--wr-input-group-bg | var(--wr-color-surface) | .wr-input-group +1 variant override |
--wr-input-group-border | var(--wr-border-base) | .wr-input-group +1 variant override |
--wr-input-group-font-family | var(--wr-font-family-base) | .wr-input-group |
--wr-input-group-font-size | var(--wr-text-sm) | .wr-input-group |
--wr-input-group-font-weight | var(--wr-font-weight-medium) | .wr-input-group |
--wr-input-group-line-height | var(--wr-control-line-height-md) | .wr-input-group |
--wr-input-group-padding-x | var(--wr-control-padding-x-md) | .wr-input-group +1 variant override |
--wr-input-group-radius | var(--wr-control-radius-md) | .wr-input-group +1 variant override |
--wr-input-group-ring | transparent | .wr-input-group +1 variant override |
--wr-input-line-height | var(--wr-control-line-height-md) | .wr-input +2 variant overrides |
--wr-input-padding-x | var(--wr-control-padding-x-md) | .wr-input +3 variant overrides |
--wr-input-padding-y | var(--wr-control-padding-y-md) | .wr-input +2 variant overrides |
--wr-input-placeholder | var(--wr-color-placeholder) | .wr-input |
--wr-input-radius | var(--wr-control-radius-md) | .wr-input +3 variant overrides |
--wr-input-ring | transparent | .wr-input +2 variant overrides |
Dependencies
| Built on | Form |
|---|---|
| Used by | Date Picker, Editor, Number Input, Schema Form, Transfer |
See also
Component Form FieldWraps a form control with a label, a hint and its error messages.Guide FormsBind ngwr controls to any Angular form and show their errors.Component TextareaA multi-line text field that can grow with its content.Component Number InputA number field with stepper buttons and locale formatting.Component SelectPick one or several values from a list, with search and free-text tags.Component Input OTPEnter a one-time code, one character per box.Component FormA plain layout wrapper for a label, a control and its error.