- @lion/checkbox-group@0.11.3 - @lion/fieldset@0.13.10 - @lion/form-core@0.2.3 - @lion/form-integrations@0.1.15 - @lion/form@0.6.10 - @lion/input-amount@0.7.10 - @lion/input-date@0.7.10 - @lion/input-datepicker@0.14.12 - @lion/input-email@0.8.10 - @lion/input-iban@0.9.10 - @lion/input-range@0.4.10 - @lion/input@0.7.10 - @lion/radio-group@0.11.3 - @lion/select-rich@0.18.14 - @lion/select@0.7.10 - @lion/switch@0.10.11 - @lion/textarea@0.7.10 - @lion/validate-messages@0.2.2 |
||
|---|---|---|
| .. | ||
| src | ||
| test | ||
| CHANGELOG.md | ||
| index.js | ||
| lion-textarea.js | ||
| package.json | ||
| README.md | ||
Textarea
lion-textarea is a webcomponent that enhances the functionality of the native <input type="textarea"> element.
Its purpose is to provide a way for users to write text that is multiple lines long.
import { html } from 'lit-html';
import { MaxLength, MinLength, Required } from '@lion/form-core';
import { loadDefaultFeedbackMessages } from '@lion/validate-messages';
import './lion-textarea.js';
export default {
title: 'Forms/Textarea',
};
loadDefaultFeedbackMessages();
export const main = () => html`
<lion-textarea label="Stops growing after 4 rows" max-rows="4"></lion-textarea>
`;
Features
- Default rows is 2 and it will grow to max-rows of 6.
max-rowsattribute to set the amount of rows it should resize to, before it will scrollrowsattribute to set the minimum amount of rowsreadonlyattribute to prevent changing the content
How to use
Installation
npm i --save @lion/textarea
import { LionTextare } from '@lion/textarea';
// or
import '@lion/textarea/lion-textarea.js';
Examples
Prefilled
You can prefill the textarea. If you want to prefill on multiline, you will have to add newline characters '\n'.
export const prefilled = () => html`
<lion-textarea
label="Prefilled"
.modelValue=${['batman', 'and', 'robin'].join('\n')}
></lion-textarea>
`;
Disabled
The textarea can be disabled with the disabled attribute.
export const disabled = () => html` <lion-textarea label="Disabled" disabled></lion-textarea> `;
Readonly
readonly attribute indicate that you can't change the content. Compared with disabled attribute, the readonly attribute doesn't prevent clicking or selecting the element.
export const readonly = () => html`
<lion-textarea
label="Readonly"
readonly
.modelValue=${['batman', 'and', 'robin'].join('\n')}
></lion-textarea>
`;
Stop growing
Use the max-rows attribute to make it stop growing after a certain amount of lines.
export const stopGrowing = () => html`
<lion-textarea
label="Stop growing"
max-rows="4"
.modelValue=${['batman', 'and', 'robin'].join('\n')}
></lion-textarea>
`;
Non-growing
To have a fixed size provide rows and max-rows with the same value.
export const nonGrowing = () => html`
<lion-textarea label="Non Growing" rows="3" max-rows="3"></lion-textarea>
`;
Validation
The textarea can have validation.
export const validation = () => {
return html`
<lion-textarea
.validators="${[new Required(), new MinLength(10), new MaxLength(400)]}"
label="String"
.modelValue="${'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'}"
></lion-textarea>
`;
};