deploy: ebd4cc0010
This commit is contained in:
58
node_modules/@vueuse/integrations/useFocusTrap.mjs
generated
vendored
58
node_modules/@vueuse/integrations/useFocusTrap.mjs
generated
vendored
@@ -1,58 +0,0 @@
|
||||
import { unrefElement, tryOnScopeDispose } from '@vueuse/core';
|
||||
import { ref, watch } from 'vue-demi';
|
||||
import { createFocusTrap } from 'focus-trap';
|
||||
|
||||
function useFocusTrap(target, options = {}) {
|
||||
let trap;
|
||||
const { immediate, ...focusTrapOptions } = options;
|
||||
const hasFocus = ref(false);
|
||||
const isPaused = ref(false);
|
||||
const activate = (opts) => trap && trap.activate(opts);
|
||||
const deactivate = (opts) => trap && trap.deactivate(opts);
|
||||
const pause = () => {
|
||||
if (trap) {
|
||||
trap.pause();
|
||||
isPaused.value = true;
|
||||
}
|
||||
};
|
||||
const unpause = () => {
|
||||
if (trap) {
|
||||
trap.unpause();
|
||||
isPaused.value = false;
|
||||
}
|
||||
};
|
||||
watch(
|
||||
() => unrefElement(target),
|
||||
(el) => {
|
||||
if (!el)
|
||||
return;
|
||||
trap = createFocusTrap(el, {
|
||||
...focusTrapOptions,
|
||||
onActivate() {
|
||||
hasFocus.value = true;
|
||||
if (options.onActivate)
|
||||
options.onActivate();
|
||||
},
|
||||
onDeactivate() {
|
||||
hasFocus.value = false;
|
||||
if (options.onDeactivate)
|
||||
options.onDeactivate();
|
||||
}
|
||||
});
|
||||
if (immediate)
|
||||
activate();
|
||||
},
|
||||
{ flush: "post" }
|
||||
);
|
||||
tryOnScopeDispose(() => deactivate());
|
||||
return {
|
||||
hasFocus,
|
||||
isPaused,
|
||||
activate,
|
||||
deactivate,
|
||||
pause,
|
||||
unpause
|
||||
};
|
||||
}
|
||||
|
||||
export { useFocusTrap };
|
||||
Reference in New Issue
Block a user