Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text area that grows as you type #179

Open
mhulse opened this issue May 9, 2018 · 0 comments
Open

Text area that grows as you type #179

mhulse opened this issue May 9, 2018 · 0 comments

Comments

@mhulse
Copy link
Owner

mhulse commented May 9, 2018

 .ap_pseudo-input {
    -moz-outline-style: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    border-radius: 0.2rem;
    border: 1px solid #dcdcdc;
    outline: none;
    overflow: auto;
    margin: 0.5rem 0;
    padding: 1rem;
    resize: none;
    width: 100%;
}

.ap_pseudo-input::-webkit-input-placeholder,
.ap_pseudo-input:-moz-placeholder,
.ap_pseudo-input::-moz-placeholder,
.ap_pseudo-input:-ms-input-placeholder { color: #939393; }

/* https://coderwall.com/p/n55a0g/fixing-contenteditable-placeholders-with-3-lines-of-css */
.ap_pseudo-input[contenteditable=true]:empty::before {
    color: #939393;
    content: attr(data-placeholder);
}
/* @TODO May need to show the `textarea` if IE10, due to lack of `contenteditable` support. */
textarea.ap_pseudo-input {
    display: none;
}
<div
    class="ap_pseudo-input ap_js_textarea"
    contenteditable="true"
    data-placeholder="Type or click button to pick activity"
></div>
<textarea class="ap_pseudo-input" placeholder="Type or click button to pick activity"></textarea>
$(function() {

    // https://collectiveidea.com/blog/archives/2017/06/13/adjustable-form-text-area-with-the-contenteditable-tag

    var $textarea = $('.ap_js_textarea');
    var populate = function($this) {

        $this.next().val($this.text());

    }

    if ($textarea.length) {

        $textarea.each(function(key, val) {

            populate($(this));

        });

        $textarea.on('change keyup paste', function(event) {

            populate($(this));

        })

    }

});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant