├── .gitignore ├── .npmignore ├── .travis.yml ├── .zuul.yml ├── README.md ├── capture.gif ├── example ├── sample.css └── sample.js ├── index.css ├── index.js ├── package.json └── tests └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | example/ 2 | 3 | caputure.gif 4 | README.md 5 | 6 | tests 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | node_js: 2 | - '6' 3 | sudo: false 4 | language: node_js 5 | env: 6 | global: 7 | - secure: wW2Q6HyMoyE78pc4/+QOHRy1fDfjtazNJBD4YvH0HAYmumBiqzOlpP4z/ScSaye8DM0oudHj4Gz0luqE84HzbVkP+a7nC0Tls3ia6loadDA0aHlOUkQfTk7jqnWnShKVyVU38KrFm5gB1fVsen3xJ1TtWeCbUHLMoGGcvQGG0duN2P7Wc85vqg9s9EZQTnYBRn4MxCytu2j195Qx5kULm5xaUcs7HbI95Eo+fj9IFZ9eVNd9sh0TNSIkPCpjxmKBR535Fuyz7CTuECRoS9Ne+mQ7PTpmY2oDYYwmg2+ckxzHlEKiepOXLa/41l3G6E26/NlTqPVMvASVuTafFC+Rwxh1tZvr7HZ5aO94WTlGwq1uCsSe12z2GTXFJp6p2lBkQt4nCeRdNylanv6eoorl4naz1X4Qepw2M1oVTqvz5Tn+W0Hn7EuhzrVTg8V3Y1G9UhA+9lCa/SE4z+BXOFN5ln1RqB8atFSR3efaTKdvgii6w36SJ7Jh2w1IP0sgupR5lpQqiMs2TO+2xQmaZiDsA8vksC93EWsrhcPc6N3jTD6TpqXG1KtslhkSWg/rqX0aRX0vJJEYUS0NaHdz4dw2r5LJNO/4qi5qeG4+2xjhfc+U4tt9uE8uXwGMLpcStCw9hMT//PzLXvPuDJitGvsbFyL00ZUhS8CjfDUO8MCwT7w= 8 | - secure: Oprg/DMoMMl3r0Po8q8nOAef8h+Ilf7YPgqbzUQkTDoxZPdWySQ5E0u58GLSQU5e/01gT8wfwD/Dx3dWuPI+ncTYtFnJe5bOKcDRFYcivT5NM5rnhylQIM0J9/JJ4klz1odmjQAbzlevUoCvcacFaVqhqtR8fciqkSOCaURgrZ0kdAfOtMjbB9dn/RZxRl5Snikeoa2VIjW+aDnCx83JGS8QkPkiFICrTVLIDDsW+P2+18BTxKNIcgNwuM7k+Pi7DL7i2aGoLZZrNBkZ6gJjdlruguk3AKqIKzcWI9reUtcm2NzJ3bwXhmeskzwTGu5f8TFfELtsOJroMlAnIdNpuOL/9pgdPNX9PW9gojBFum+dWDZ7jQyzcEo9J3FydlbHZcr2cib66p1ACdxQzEnvCuv8WgV14qp1hRdbXP7sQhphh4XNNAT1tSRu3jGSFsl5zgngVDVAVOrBI4a465jXK39bX2wKr7rtWnK4BFRzB6foVemGkysV2doDa5v7S7UXu49HVsLzso8aonEwh3AaI2asxz0t446p3AtMTG+P5li4lTGQexBP4QO6PJJ/gUrckjepiyXWVA9GDbeRlAO2SVEOep6wsdmCGbWh+EiU36SMIHj9soUeJaDpjgeH/Lev3BvKl3yh8Vxdsv9QOoxs2b6LuEyWxoddgCRvVpihcOw= 9 | -------------------------------------------------------------------------------- /.zuul.yml: -------------------------------------------------------------------------------- 1 | ui: tape 2 | browsers: 3 | - name: chrome 4 | version: latest 5 | os: 'Mac 10.11' 6 | browserify: 7 | - transform: 8 | name: es2020 9 | - transform: sheetify/transform 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # yo-yo-autogrow 2 | 3 | [![Build Status](https://travis-ci.org/tgfjt/yo-yo-autogrow.svg?branch=feature%2Ftest)](https://travis-ci.org/tgfjt/yo-yo-autogrow) 4 | [![npm](https://img.shields.io/npm/v/yo-yo-autogrow.svg?maxAge=2592000)]() 5 | ![API stability](https://img.shields.io/badge/stability-experimental-orange.svg) 6 | ![MIT Licensed](https://img.shields.io/npm/l/yo-yo-autogrow.svg) 7 | 8 | Wrapper ` 70 | 71 | 72 | 73 | ` 74 | } 75 | 76 | module.exports = function (options) { 77 | var t = new TextareaData(options) 78 | var el = textarea(t) 79 | 80 | t.emitter.on('update', function () { 81 | yo.update(el, textarea(t)) 82 | }) 83 | 84 | return el 85 | } 86 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yo-yo-autogrow", 3 | "version": "1.0.1", 4 | "description": "textarea component via yo-yo, automatically adjust height", 5 | "main": "index.js", 6 | "scripts": { 7 | "zuul": "zuul --local --open -- tests/test.js", 8 | "test": "zuul -- tests/test.js", 9 | "start": "budo example/sample.js --live -p 8080 --open -- -t es2020 -t sheetify/transform" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/tgfjt/yo-yo-autogrow.git" 14 | }, 15 | "bugs": { 16 | "url": "https://github.com/tgfjt/yo-yo-autogrow/issues" 17 | }, 18 | "homepage": "https://github.com/tgfjt/yo-yo-autogrow#readme", 19 | "keywords": [ 20 | "yo-yo" 21 | ], 22 | "author": "tgfjt", 23 | "license": "MIT", 24 | "dependencies": { 25 | "namespace-emitter": "^1.0.0", 26 | "sheetify": "^6.0.1", 27 | "xtend": "^4.0.1", 28 | "yo-yo": "^1.2.2" 29 | }, 30 | "devDependencies": { 31 | "budo": "^10.0.3", 32 | "choo": "^4.1.0", 33 | "document-ready": "^2.0.1", 34 | "es2020": "^1.1.8", 35 | "tape": "^4.6.0", 36 | "zuul": "^3.11.0" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape'); 2 | const onReady = require('document-ready') 3 | 4 | const textarea = require('../'); 5 | 6 | test('default properties', function (t) { 7 | t.plan(4) 8 | 9 | const el = textarea() 10 | 11 | onReady(function () { 12 | const textarea = el.querySelector('textarea') 13 | 14 | t.equal(el.querySelector('.AutogrowTextarea-mirror').innerHTML, ' ', 'same value') 15 | t.equal(textarea.getAttribute('placeholder'), '', 'same placeholder') 16 | t.equal(textarea.getAttribute('rows'), '1', 'rows=1') 17 | t.equal(textarea.getAttribute('autocomplete'), 'off', 'autocomplete=ff') 18 | }) 19 | }); 20 | 21 | test('overwrite properties', function (t) { 22 | t.plan(5) 23 | 24 | const el = textarea({ 25 | name: 'test', 26 | value: 'Hi!\nHi!\nHi!', 27 | placeholder: 'autogrow placeholder', 28 | required: true, 29 | autocomplete: 'on' 30 | }) 31 | 32 | onReady(function () { 33 | const textarea = el.querySelector('textarea') 34 | const wrapper = el.querySelector('.AutogrowTextarea') 35 | 36 | t.equal(el.querySelector('.AutogrowTextarea-mirror').innerHTML, 'Hi!\nHi!\nHi! ', 'same value') 37 | t.equal(textarea.name, 'test', 'name=test') 38 | t.equal(textarea.getAttribute('placeholder'), 'autogrow placeholder', 'same placeholder') 39 | t.equal(textarea.getAttribute('required'), 'required', 'required=true') 40 | t.equal(textarea.getAttribute('autocomplete'), 'on', 'autocomplete=on') 41 | }) 42 | }); 43 | 44 | test('be disabled', function (t) { 45 | t.plan(2) 46 | 47 | const el = textarea({ 48 | disabled: true 49 | }) 50 | 51 | onReady(function () { 52 | const textarea = el.querySelector('textarea') 53 | const wrapper = el.querySelector('.AutogrowTextarea') 54 | 55 | t.equal(textarea.getAttribute('disabled'), 'disabled', 'disabled=true') 56 | t.equal(wrapper.classList.contains('is-disabled'), true, 'is-disabled') 57 | }) 58 | }); 59 | 60 | test('adjust height', function (t) { 61 | t.plan(1) 62 | 63 | const el1 = textarea({ 64 | value: 'Hello!' 65 | }) 66 | 67 | const el2 = textarea({ 68 | value: 'Hellow!\nworld!' 69 | }) 70 | 71 | document.body.appendChild(el1) 72 | document.body.appendChild(el2) 73 | 74 | t.ok(el1.clientHeight < el2.clientHeight, 'adjust height via break line') 75 | }); 76 | --------------------------------------------------------------------------------