ProductPromotion
Logo

Angular.JS

made by https://0x3d.site

GitHub - joshuawwright/ngx-autosize-input: is an Angular directive that automatically adjusts the width of an input element. Its is unique because it both shrinks and increases the width.
is an Angular directive that automatically adjusts the width of an input element. Its is unique because it both shrinks and increases the width. - joshuawwright/ngx-autosize-input
Visit Site

GitHub - joshuawwright/ngx-autosize-input: is an Angular directive that automatically adjusts the width of an input element. Its is unique because it both shrinks and increases the width.

GitHub - joshuawwright/ngx-autosize-input: is an Angular directive that automatically adjusts the width of an input element. Its is unique because it both shrinks and increases the width.

ngx-autosize-input

An Angular directive that automatically adjusts the width of an input element to its content. Unlike other auto-grow directives, it is unique because it both shrinks and increases the width based on the content.

npm npm License GitHub stars npm Downloads Status Checks codecov

Versions

The major version will match the Angular major version going forward (Angular 10+). For example version 10, will work for Angular 10.

Stack Blitz Demo

https://stackblitz.com/edit/angular-ivy-dtjmsk?file=src/app/hello.component.ts

Installation

npm install ngx-autosize-input

Add AutoSizeInputModule to your @NgModule imports:

import {AutoSizeInputModule} from 'ngx-autosize-input';

@NgModule({
  imports: [
    AutoSizeInputModule
  ]
})

The input options can be set from a provider (see below), or from the template (skip to the next section).

import {AUTO_SIZE_INPUT_OPTIONS, AutoSizeInputModule, AutoSizeInputOptions} from 'ngx-autosize-input';

const CUSTOM_AUTO_SIZE_INPUT_OPTIONS: AutoSizeInputOptions = {
  extraWidth: 0,
  includeBorders: false,
  includePadding: true,
  includePlaceholder: true,
  maxWidth: -1,
  minWidth: -1,
  setParentWidth: false,
  usePlaceHolderWhenEmpty: false,
}

@NgModule({
  imports: [
    AutoSizeInputModule
  ],
  providers: [
    { provide: AUTO_SIZE_INPUT_OPTIONS, useValue: CUSTOM_AUTO_SIZE_INPUT_OPTIONS }
  ]
})

Use Example

Use directly in your HTML templates on an input element:

<input autoSizeInput>

Using Bootstrap

If using Bootstrap, set the directive to include borders so that the text is not cut off.

<input autoSizeInput [includeBorders]=true>

Parameters

The following parameters customize the directive.

[extraWidth]

Add extra width, in units of pixels.

Default Value: 0px

Example (add 10px):

<input autoSizeInput [extraWidth]="10">

[includePlaceholder]

Set placeholder text width as minimum width; Note that [minimumWidth] will override this property.

Default Value: true

Example (turn off placeholder):

<input autoSizeInput [includePlaceholder]="false">

[includeBorders]

Includes border width, so that text is not cut off. Note only even left and right borders are supported at this time.

Default Value: false

Example (turn on include borders):

<input autoSizeInput [includeBorders]="true">

[includePadding]

Includes padding width, so that text is not cut off.

Default Value: true

Example (turn off include padding):

<input autoSizeInput [includePadding]="false">

[minWidth]

Sets minimum width, in units of pixels.

Default Value: 0

Example (50px minimum width):

<input autoSizeInput [minWidth]="50">

[maxWidth]

Sets maximum width, in units of pixels.

Default Value: 0

Example (100px maximum width):

<input autoSizeInput [maxWidth]="100">

[setParentWidth]

Sets parent width automatically, instead of input width. Useful when you need to update a parent's width.

Default Value: false

Example (input wrapped in an Angular Material form field component):

<mat-form-field> // This will be resized
   <input autoSizeInput [setParentWidth]="true">
</mat-form-field>

[usePlaceholderWhenEmpty]

Sets width to placeholder width, only when value is empty.

Default Value: false

Example (turn on placeholder when empty):

<input autoSizeInput [usePlaceholderWhenEmpty]="true">

[useValueProperty]

If the value of the form control is an object but the input value is formatted setting this value to true will use the value property of the input instead of retreiving the value from the form control or model. This option is not globally configurable and must be set on each input.

Default Value: false

Example (ngbTypeahead with inputFormatter): search$ returns an array of objects { firstName: string; lastName: string; }[] and formatInput transforms the selected object to `${firstName} ${lastName}`. The value applied to the form control will be the object selected so in-order to get the actual string value in the input we need to look at the value property.

<input autoSizeInput [useValueProperty]="true" formControlName="fullName" [ngbTypeahead]="search$" [inputFormatter]="formatInput">

Author

Joshua Wright

License

This project is licensed under the MIT license. See the License file for more info.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory