UNPKG

@ark-ui/vue

Version:

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

62 lines (57 loc) 2.11 kB
'use strict'; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } }); const vue = require('vue'); const focusTrap = require('@zag-js/focus-trap'); const factory = require('../factory.cjs'); const useForwardExpose = require('../../utils/use-forward-expose.cjs'); const cleanProps = require('../../utils/clean-props.cjs'); const _sfc_main = /* @__PURE__ */ vue.defineComponent({ __name: "focus-trap", props: { disabled: { type: Boolean, default: void 0 }, initialFocus: { type: [String, Boolean, Function], default: void 0 }, fallbackFocus: { type: [String, Function], default: void 0 }, returnFocusOnDeactivate: { type: Boolean, default: void 0 }, setReturnFocus: { type: [String, Boolean, Function], default: void 0 }, asChild: { type: Boolean } }, emits: ["activate", "deactivate"], setup(__props, { emit: __emit }) { const props = __props; const emits = __emit; const nodeRef = vue.ref(null); let cleanup; vue.watchEffect(() => { if (props.disabled) return; if (!nodeRef.value) return; const node = nodeRef.value.$el ? nodeRef.value.$el : nodeRef.value; if (!node) return; const autoFocusNode = node.querySelector("[autofocus], [data-autofocus]"); const trapProps = cleanProps.cleanProps(props); trapProps.initialFocus ||= autoFocusNode ?? void 0; cleanup = focusTrap.trapFocus(node, { ...trapProps, onActivate: () => emits("activate"), onDeactivate: () => emits("deactivate") }); vue.onWatcherCleanup(() => cleanup?.()); }); vue.onBeforeUnmount(() => { cleanup?.(); }); useForwardExpose.useForwardExpose(); return (_ctx, _cache) => { return vue.openBlock(), vue.createBlock(vue.unref(factory.ark).div, { ref_key: "nodeRef", ref: nodeRef, "as-child": _ctx.asChild }, { default: vue.withCtx(() => [ vue.renderSlot(_ctx.$slots, "default") ]), _: 3 }, 8, ["as-child"]); }; } }); exports.default = _sfc_main;