Skip to content

Commit

Permalink
feat: added focus-trap to step element
Browse files Browse the repository at this point in the history
resolves #88
  • Loading branch information
fatihsolhan committed Feb 9, 2024
1 parent e7e55cc commit 7d9fd21
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
},
"dependencies": {
"@popperjs/core": "^2.11.5",
"@vueuse/integrations": "^10.7.2",
"vue": "^3.2.21"
},
"peerDependencies": {
Expand Down
10 changes: 10 additions & 0 deletions src/components/VOnboardingStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<script lang="ts">
import { OnboardingState, STATE_INJECT_KEY } from '@/types';
import { createPopper } from '@popperjs/core';
import { useFocusTrap } from '@vueuse/integrations/useFocusTrap';
import merge from 'lodash.merge';
import { Ref, computed, defineComponent, inject, nextTick, ref, watch } from 'vue';
import useGetElement from '../composables/useGetElement';
Expand Down Expand Up @@ -92,6 +93,15 @@ export default defineComponent({
const { updatePath, path } = useSvgOverlay();
const stepElement = ref<HTMLElement>();
const focusTrap = useFocusTrap(stepElement)
watch(show, async (value) => {
await nextTick()
if (value) {
focusTrap.activate()
} else {
focusTrap.deactivate()
}
})
const attachElement = async () => {
await nextTick()
const element = useGetElement(step?.value?.attachTo?.element);
Expand Down
3 changes: 3 additions & 0 deletions src/css/v-onboarding.sass
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
&:hover
background-color: #4338CA

&:focus
outline-color: #312e81

&.v-onboarding-btn-secondary
border-color: #D4D4D8
color: #3F3F46
Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import pkg from "./package.json";
const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
'focus-trap'
];
export default defineConfig({
test: {
Expand Down
41 changes: 41 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,11 @@
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"
integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==

"@types/web-bluetooth@^0.0.20":
version "0.0.20"
resolved "https://registry.yarnpkg.com/@types/web-bluetooth/-/web-bluetooth-0.0.20.tgz#f066abfcd1cbe66267cdbbf0de010d8a41b41597"
integrity sha512-g9gZnnXVq7gM7v3tJCWV/qw7w+KeOlSHAhgF9RytFyifW6AF61hdT2ucrYhPq9hLs5JIryeupHV3qGk95dH9ow==

"@vitejs/plugin-vue@^1.9.4":
version "1.10.2"
resolved "https://registry.yarnpkg.com/@vitejs/plugin-vue/-/plugin-vue-1.10.2.tgz#d718479e2789d8a94b63e00f23f1898ba239253a"
Expand Down Expand Up @@ -940,6 +945,37 @@
optionalDependencies:
"@vue/compiler-dom" "^3.0.1"

"@vueuse/core@10.7.2":
version "10.7.2"
resolved "https://registry.yarnpkg.com/@vueuse/core/-/core-10.7.2.tgz#78917803a29a0bca1803a6521fdf7ff873f6e72c"
integrity sha512-AOyAL2rK0By62Hm+iqQn6Rbu8bfmbgaIMXcE3TSr7BdQ42wnSFlwIdPjInO62onYsEMK/yDMU8C6oGfDAtZ2qQ==
dependencies:
"@types/web-bluetooth" "^0.0.20"
"@vueuse/metadata" "10.7.2"
"@vueuse/shared" "10.7.2"
vue-demi ">=0.14.6"

"@vueuse/integrations@^10.7.2":
version "10.7.2"
resolved "https://registry.yarnpkg.com/@vueuse/integrations/-/integrations-10.7.2.tgz#763de1337d3925be9097aac9a725eec39d4c8e69"
integrity sha512-+u3RLPFedjASs5EKPc69Ge49WNgqeMfSxFn+qrQTzblPXZg6+EFzhjarS5edj2qAf6xQ93f95TUxRwKStXj/sQ==
dependencies:
"@vueuse/core" "10.7.2"
"@vueuse/shared" "10.7.2"
vue-demi ">=0.14.6"

"@vueuse/metadata@10.7.2":
version "10.7.2"
resolved "https://registry.yarnpkg.com/@vueuse/metadata/-/metadata-10.7.2.tgz#ba0187ce138c287fd80301afc5b0d6a97e563633"
integrity sha512-kCWPb4J2KGrwLtn1eJwaJD742u1k5h6v/St5wFe8Quih90+k2a0JP8BS4Zp34XUuJqS2AxFYMb1wjUL8HfhWsQ==

"@vueuse/shared@10.7.2":
version "10.7.2"
resolved "https://registry.yarnpkg.com/@vueuse/shared/-/shared-10.7.2.tgz#746441fbc08072371dd600a55883422c83fd0cab"
integrity sha512-qFbXoxS44pi2FkgFjPvF4h7c9oMDutpyBdcJdMYIMg9XyXli2meFMuaKn+UMgsClo//Th6+beeCgqweT/79BVA==
dependencies:
vue-demi ">=0.14.6"

JSONStream@^1.0.4:
version "1.3.5"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
Expand Down Expand Up @@ -5631,6 +5667,11 @@ void-elements@^3.1.0:
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-3.1.0.tgz#614f7fbf8d801f0bb5f0661f5b2f5785750e4f09"
integrity sha1-YU9/v42AHwu18GYfWy9XhXUOTwk=

vue-demi@>=0.14.6:
version "0.14.7"
resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.14.7.tgz#8317536b3ef74c5b09f268f7782e70194567d8f2"
integrity sha512-EOG8KXDQNwkJILkx/gPcoL/7vH+hORoBaKgGe+6W7VFMvCYJfmF2dGbvgDroVnI8LU7/kTu8mbjRZGBU1z9NTA==

vue-docgen-api@^4.30.0:
version "4.44.23"
resolved "https://registry.yarnpkg.com/vue-docgen-api/-/vue-docgen-api-4.44.23.tgz#e6763b43b6a4083fb871c6ecc8e8cb4538b3846f"
Expand Down

0 comments on commit 7d9fd21

Please sign in to comment.