Documentation v8.0.25

Preview Purchase

Overview

Autosizeis a small, stand-alone script to automatically adjust textarea height. For full documentation please check the plugin's site.

Usage

Autosize's Javascript files are bundled in the global plugin bundles and globally included in all pages:
<link href="assets/plugins/global/plugins.bundle.css" rel="stylesheet" type="text/css"/>
<script src="assets/plugins/global/plugins.bundle.js"></script>

Initialization

  • Autosize's Javascript is globally included and bundled without our plugins bundle.
  • Autosize's is initialized by adding data-kt-autosize="true"HTML attribute within any textareaHTML element.
  • Autosize instances can also be controlled programmatically. See below for more info.
  • Autosize also supports event hooks. Please refer to the official documentationfor more info.

Basic Example

Here's an example of the textareaautomatically resizing base on the amount of text written in it.
Combine our extended .form-controlCSS classes to create quick and solid textarealayouts.
<!--begin::basic autosize textarea-->
<div class="rounded border d-flex flex-column p-10">
    <label for="" class="form-label">Basic autosize textarea</label>
    <textarea class="form-control" data-kt-autosize="true"></textarea>
</div>
<!--end::basic autosize textarea-->

<!--begin::solid autosize textarea-->
<div class="rounded border d-flex flex-column p-10">
    <label for="" class="form-label">Solid autosize textarea</label>
    <textarea class="form-control form-control form-control-solid" data-kt-autosize="true"></textarea>
</div>
<!--end::solid autosize textarea-->

Markup Reference

Autosize uses HTML attributes to initialize the autosize function. Here are the references for each below
HTML Attribute references
Name Type Description
data-kt-autosize mandatory Enables the current element as the Autosize component. Accepts trueor falsevalues.

Methods

All Autosize components can be initialized automatically through HTML attributes. However, it can also be programmatically intialized by ignoring the HTML attribute and manually initializing it via Javascript.
Name Description
Static Methods
Initialization Initializes Autosize instances by selecting the element required. This method can be used to initialize dynamicly populated Autosize instances(e.g: after Ajax request).
// Single node
const autosize_element = document.querySelector('#kt_autosize');
autosize(autosize_element);

// Nodelist
const autosize_elements = document.querySelectorAll('.kt_autosize');
autosize(autosize_elements);

// jQuery
autosize($('.kt_autosize'));
Public Methods
update Triggers the height adjustment for an assigned textarea element. Autosize will automatically adjust the textarea height on keyboard and window resize events. There is no efficient way for Autosize to monitor for when another script has changed the textarea value or for changes in layout that impact the textarea element.
// Change value
autosize_element.vlaue = "some value";
autosize.update(autosize_element);
destroy Removes Autosize and reverts any changes it made to the textarea element.
autosize.destroy(autosize_element);

Explore Metronic

Demo1

Demo2

Demo3

Demo4

Demo5

Demo6

Demo7

Demo8

Demo9

Demo10

demo
Coming soon

Demo11

Demo12

demo
Coming soon

Demo13

Demo14

demo
Coming soon

Demo15

demo
Coming soon

Demo16

demo
Coming soon

Demo17

demo
Coming soon

Demo18

demo
Coming soon

Demo19

demo
Coming soon

Demo20

demo
Coming soon