|
11 | 11 | rounded="lg"
|
12 | 12 | border-color="gray.400"
|
13 | 13 | d="inline-block"
|
14 |
| - @activate="handleActivate" |
15 |
| - @deactivate="handleDeactivate" |
16 |
| - :allow-outside-click="false" |
17 |
| - :initial-focus-ref="() => initialFocusRef" |
18 |
| - #default="{ hasFocus, deactivate }" |
| 14 | + #default="{ enabled, deactivate }" |
19 | 15 | pos="relative"
|
20 | 16 | v-if="isActive"
|
21 | 17 | >
|
|
26 | 22 | right="10px"
|
27 | 23 | @click="deactivate"
|
28 | 24 | ></c-close-button>
|
29 |
| - <chakra.pre> Focus trap enabled: {{ hasFocus }} </chakra.pre> |
| 25 | + <chakra.pre> Focus trap enabled: {{ enabled }} </chakra.pre> |
30 | 26 | <chakra.p mb="2">Inside focus trap</chakra.p>
|
31 | 27 | <c-button color-scheme="teal"> Login </c-button>
|
32 | 28 | <c-button :ref="initialFocus" color-scheme="yellow" mx="2"
|
|
35 | 31 | <c-button left-icon="user" color-scheme="red"
|
36 | 32 | >Delete account</c-button
|
37 | 33 | >
|
38 |
| - <chakra.pre> Focus trap enabled: {{ hasFocus }} </chakra.pre> |
| 34 | + <chakra.pre> Focus trap enabled: {{ enabled }} </chakra.pre> |
39 | 35 | <chakra.p mb="2">Inside focus trap</chakra.p>
|
40 | 36 | <c-button color-scheme="teal"> Login </c-button>
|
41 | 37 | <c-button color-scheme="yellow" mx="2">Initial focus!</c-button>
|
42 | 38 | <c-button left-icon="user" color-scheme="red"
|
43 | 39 | >Delete account</c-button
|
44 | 40 | >
|
45 |
| - <chakra.pre> Focus trap enabled: {{ hasFocus }} </chakra.pre> |
| 41 | + <chakra.pre> Focus trap enabled: {{ enabled }} </chakra.pre> |
46 | 42 | <chakra.p mb="2">Inside focus trap</chakra.p>
|
47 | 43 | <c-button color-scheme="teal"> Login </c-button>
|
48 | 44 | <c-button color-scheme="yellow" mx="2">Initial focus!</c-button>
|
49 | 45 | <c-button left-icon="user" color-scheme="red"
|
50 | 46 | >Delete account</c-button
|
51 | 47 | >
|
52 |
| - <chakra.pre> Focus trap enabled: {{ hasFocus }} </chakra.pre> |
| 48 | + <chakra.pre> Focus trap enabled: {{ enabled }} </chakra.pre> |
53 | 49 | <chakra.p mb="2">Inside focus trap</chakra.p>
|
54 | 50 | <c-button color-scheme="teal"> Login </c-button>
|
55 | 51 | <c-button color-scheme="yellow" mx="2">Initial focus!</c-button>
|
56 | 52 | <c-button left-icon="user" color-scheme="red"
|
57 | 53 | >Delete account</c-button
|
58 | 54 | >
|
59 |
| - <chakra.pre> Focus trap enabled: {{ hasFocus }} </chakra.pre> |
| 55 | + <chakra.pre> Focus trap enabled: {{ enabled }} </chakra.pre> |
60 | 56 | <chakra.p mb="2">Inside focus trap</chakra.p>
|
61 | 57 | <c-button color-scheme="teal"> Login </c-button>
|
62 | 58 | <c-button color-scheme="yellow" mx="2">Initial focus!</c-button>
|
|
90 | 86 | </chakra.div>
|
91 | 87 | </template>
|
92 | 88 |
|
93 |
| -<script lang="ts"> |
94 |
| -import { useRef } from '@chakra-ui/vue-utils' |
95 |
| -import { defineComponent, ref, watch } from 'vue' |
96 |
| -import { CFocusLock } from '../src/c-focus-lock' |
| 89 | +<script lang="ts" setup> |
| 90 | +import { chakra } from "@chakra-ui/vue-next" |
| 91 | +import { useRef } from "@chakra-ui/vue-utils" |
| 92 | +import { ref } from "vue" |
| 93 | +import { CFocusLock } from "../src/c-focus-lock" |
97 | 94 |
|
98 |
| -if (!document.getElementById('new-target')) { |
99 |
| - const target = document.createElement('div') |
100 |
| - target.style.display = 'inline-block' |
101 |
| - target.style.position = 'absolute' |
102 |
| - target.style.top = '50px' |
103 |
| - target.style.left = '250px' |
| 95 | +if (!document.getElementById("new-target")) { |
| 96 | + const target = document.createElement("div") |
| 97 | + target.style.display = "inline-block" |
| 98 | + target.style.position = "absolute" |
| 99 | + target.style.top = "50px" |
| 100 | + target.style.left = "250px" |
104 | 101 |
|
105 |
| - target.id = 'new-target' |
| 102 | + target.id = "new-target" |
106 | 103 | document.body.appendChild(target)
|
107 | 104 | }
|
| 105 | +const isActive = ref(false) |
| 106 | +const [finalFocus, finalFocusRef] = useRef() |
| 107 | +const [initialFocus, initialFocusRef] = useRef() |
108 | 108 |
|
109 |
| -export default defineComponent({ |
110 |
| - components: { |
111 |
| - CFocusLock, |
112 |
| - }, |
113 |
| - setup() { |
114 |
| - const isActive = ref(false) |
115 |
| - const [finalFocus, finalFocusRef] = useRef() |
116 |
| - const [initialFocus, initialFocusRef] = useRef() |
117 |
| -
|
118 |
| - const handleActivate = () => { |
119 |
| - console.log('focuslock activated') |
120 |
| - } |
121 |
| -
|
122 |
| - const handleDeactivate = () => { |
123 |
| - console.log('focuslock deactivated') |
124 |
| - isActive.value = false |
125 |
| - setTimeout(() => {}) |
126 |
| - } |
127 |
| -
|
128 |
| - watch(isActive, () => { |
129 |
| - setTimeout(() => { |
130 |
| - isActive.value = !isActive.value |
131 |
| - }, 3000) |
132 |
| - }) |
| 109 | +const handleActivate = () => { |
| 110 | + console.log("focuslock activated") |
| 111 | +} |
133 | 112 |
|
134 |
| - return { |
135 |
| - isActive, |
136 |
| - handleActivate, |
137 |
| - handleDeactivate, |
138 |
| - finalFocus, |
139 |
| - finalFocusRef, |
140 |
| - initialFocus, |
141 |
| - initialFocusRef, |
142 |
| - } |
143 |
| - }, |
144 |
| -}) |
| 113 | +const handleDeactivate = () => { |
| 114 | + console.log("focuslock deactivated") |
| 115 | + isActive.value = false |
| 116 | + setTimeout(() => {}) |
| 117 | +} |
145 | 118 | </script>
|
0 commit comments