UNPKG

@ark-ui/vue

Version:

A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.

48 lines (45 loc) 1.69 kB
import { defineComponent, ref, onMounted, onBeforeUnmount, createBlock, openBlock, unref, mergeProps, withCtx, renderSlot } from 'vue'; import { autoresizeTextarea } from '@zag-js/auto-resize'; import { useForwardExpose } from '../../utils/use-forward-expose.js'; import { ark } from '../factory.js'; import { useFieldContext } from './use-field-context.js'; import { unrefElement } from '../../utils/unref-element.js'; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "field-textarea", props: { modelValue: {}, autoresize: { type: Boolean }, asChild: { type: Boolean } }, emits: ["update:modelValue"], setup(__props, { emit: __emit }) { const props = __props; const field = useFieldContext(); const emit = __emit; const textareaRef = ref(); onMounted(() => { const node = unrefElement(textareaRef); if (!node || !props.autoresize) return; const cleanup = autoresizeTextarea(node); onBeforeUnmount(() => cleanup?.()); }); useForwardExpose(); return (_ctx, _cache) => { return openBlock(), createBlock(unref(ark).textarea, mergeProps({ ref_key: "textareaRef", ref: textareaRef }, unref(field).getTextareaProps(), { value: _ctx.modelValue, onInput: _cache[0] || (_cache[0] = (event) => emit("update:modelValue", event.target.value)), style: props.autoresize ? { resize: "none", overflow: "hidden" } : void 0, "as-child": _ctx.asChild }), { default: withCtx(() => [ renderSlot(_ctx.$slots, "default") ]), _: 3 }, 16, ["value", "style", "as-child"]); }; } }); export { _sfc_main as default };