All files / src/components/zd-textarea textarea.ts

100% Statements 18/18
100% Branches 0/0
100% Functions 0/0
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 11893x 93x           93x       3x         3x         3x                   3x         3x         3x         3x         3x         3x         3x           3x           3x           3x         3x                                                               93x  
import { InputFactory } from '../zd-input/input-factory';
import { TextInput } from '../zd-text-input/text-input';
import { ITextarea } from './interfaces';
 
/**
 * Base class for Textarea component.
 */
export class Textarea extends TextInput implements ITextarea {
	/**
	 * Automatically grow the textarea depending on amount of text.
	 */
	public autoGrow = false;
 
	/**
	 * Changes the background-color of the input.
	 */
	public backgroundColor = '';
 
	/**
	 * Applied when using clearable and the input is dirty.
	 */
	public clearIcon = 'clear';
 
	/**
	 * Creates counter for input length; if no number is specified, it defaults to 25. Does not apply any validation.
	 */
	public counter?: boolean | string | number;
 
	/**
	 * Applies the alternate filled input style.
	 */
	public filled = false;
 
	/**
	 * Displays linear progress bar.
	 */
	public loading: boolean | string = false;
 
	/**
	 * Remove resize handle.
	 */
	public resize = false;
 
	/**
	 * Adds a border radius to the input.
	 */
	public rounded = false;
 
	/**
	 * Height value for each row. Requires the use of the auto-grow prop.
	 */
	public rowHeight: number | string = 24;
 
	/**
	 * Default row count.
	 */
	public rows: number | string = 5;
 
	/**
	 * Define o número máximo de linhas quando o `autoGrow` está definido
	 */
	public maxRows: number | string = 10;
 
	/**
	 * Defines the component height. Possible values for this property can be
	 * <samp>'auto', '100%', '400px' or 400</samp>
	 */
	public height: string | number = 'auto';
 
	/**
	 * Defines the component min height. Possible values for this property can be
	 * <samp>'auto', '100%', '400px' or 400</samp>
	 */
	public minHeight: string | number = 'auto';
 
	/**
	 * Defines the component max height. Possible values for this property can be
	 * <samp>'auto', '100%', '400px' or 400</samp>
	 */
	public maxHeight: string | number = 'none';
 
	/**
	 * Set component height to fill all space available
	 */
	public fillHeight = false;
 
	/* istanbul ignore next */
	/**
	 * Create a new Textarea.
	 * @param props Textarea properties
	 */
	constructor(props: ITextarea) {
		super(props);
		this.autoGrow = this.getInitValue('autoGrow', props.autoGrow, this.autoGrow);
		this.backgroundColor = this.getInitValue('backgroundColor', props.backgroundColor, this.backgroundColor);
		this.clearIcon = this.getInitValue('clearIcon', props.clearIcon, this.clearIcon);
		this.counter = this.getInitValue('counter', props.counter, this.counter);
		this.filled = this.getInitValue('filled', props.filled, this.filled);
		this.loading = this.getInitValue('loading', props.loading, this.loading);
		this.resize = this.getInitValue('resize', props.resize, this.resize);
		this.rounded = this.getInitValue('rounded', props.rounded, this.reverse);
		this.rowHeight = this.getInitValue('rowHeight', props.rowHeight, this.rowHeight);
		this.rows = this.getInitValue('rows', props.rows, this.rows);
		this.maxRows = this.getInitValue('maxRows', props.maxRows, this.maxRows);
		this.height = this.getInitValue('height', props.height, this.height);
		this.minHeight = this.getInitValue('minHeight', props.minHeight, this.minHeight);
		this.maxHeight = this.getInitValue('maxHeight', props.maxHeight, this.maxHeight);
		this.fillHeight = this.getInitValue('fillHeight', props.fillHeight, this.fillHeight);
		this.createAccessors();
 
		if (this.counter && !Number.isNaN(parseInt(this.counter.toString(), 10))) {
			this.addValidation('maxLength', { limit: parseInt(this.counter.toString(), 10) });
		}
	}
}
 
InputFactory.register('ZdTextarea', Textarea);