Sha256: 1ece699373bfd3a094401d0f3fe5ca38f6ae473cf61db933f62eada96229d007

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

import { CocoComponent } from "@js/coco";
import { withSizeObserver } from "@js/base/mixins";

export default CocoComponent("appSeamlessTextarea", () => {
  return {
    use: [withSizeObserver()],

    height: null,
    observer: null,
    value: null,

    options: ["multiline", "focus"],

    init() {
      this.value = this.$refs.textarea.value;
      this.$nextTick(() => {
        this.onResize();

        if (this.$options.focus) {
          this.$refs.textarea.focus();
          this.$refs.textarea.selectionStart = this.$refs.textarea.value.length;
        }
      });
    },

    onResize() {
      const textarea = this.$refs.textarea;

      if (textarea) {
        const styles = window.getComputedStyle(textarea);
        const fontSize = styles.getPropertyValue("font-size");

        textarea.style.height = "4px";
        let newHeight = textarea.scrollHeight - parseInt(fontSize, 10) * 0.16;
        textarea.style.height = `${newHeight}px`;

        if (this.height !== newHeight) {
          this.height = newHeight;
        }
      }
    },
  };
});

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
coveragebook_components-0.6.2 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.6.1 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.6.0 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.5.7 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.5.6 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.5.5 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.5.4 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.5.3 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.5.2 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.5.1 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js