b16b9ccd5a782593421364a1b68b43bfe69bf2dca6d3f42244b4b8a2e3170d86883ce4a56750ef3d99fc5cfe8d99f8f0bf169aad4ea6c2b08297c632758701 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { ref } from 'vue';
  2. const usePopperContentFocusTrap = (props, emit) => {
  3. const trapped = ref(false);
  4. const focusStartRef = ref();
  5. const onFocusAfterTrapped = () => {
  6. emit("focus");
  7. };
  8. const onFocusAfterReleased = (event) => {
  9. var _a;
  10. if (((_a = event.detail) == null ? void 0 : _a.focusReason) !== "pointer") {
  11. focusStartRef.value = "first";
  12. emit("blur");
  13. }
  14. };
  15. const onFocusInTrap = (event) => {
  16. if (props.visible && !trapped.value) {
  17. if (event.target) {
  18. focusStartRef.value = event.target;
  19. }
  20. trapped.value = true;
  21. }
  22. };
  23. const onFocusoutPrevented = (event) => {
  24. if (!props.trapping) {
  25. if (event.detail.focusReason === "pointer") {
  26. event.preventDefault();
  27. }
  28. trapped.value = false;
  29. }
  30. };
  31. const onReleaseRequested = () => {
  32. trapped.value = false;
  33. emit("close");
  34. };
  35. return {
  36. focusStartRef,
  37. trapped,
  38. onFocusAfterReleased,
  39. onFocusAfterTrapped,
  40. onFocusInTrap,
  41. onFocusoutPrevented,
  42. onReleaseRequested
  43. };
  44. };
  45. export { usePopperContentFocusTrap };
  46. //# sourceMappingURL=use-focus-trap.mjs.map