Sha256: a4481415b31752b617c4e4af5bf296192ba47a209aa965071e177b57cdb504b3

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 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;
        textarea.style.height = `${newHeight}px`;

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
coveragebook_components-0.7.1 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.7.0 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.6.5 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.6.4 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js
coveragebook_components-0.6.3 app/components/coco/app/elements/seamless_textarea/seamless_textarea.js