vue3-enter-to-tab 0.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -12
- package/lib/index.d.ts +5 -4
- package/lib/index.js +4 -7
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,34 +1,130 @@
|
|
|
1
|
-
# vue3-enter-to-tab
|
|
1
|
+
# `vue3-enter-to-tab` composable
|
|
2
2
|
|
|
3
3
|
[![npm package][npm-img]][npm-url]
|
|
4
|
-
[](https://github.com/l3d00m/vue3-enter-to-tab/actions/workflows/release.yml)
|
|
5
|
+
[](https://github.com/l3d00m/vue3-enter-to-tab/actions/workflows/ci.yml)
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
A Vue 3 composable to convert the enter key to tab key on form inputs. Especially useful when using numpads for inputting forms.
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
https://github.com/ajomuch92/vue-enter-to-tab
|
|
9
|
+
This is a fork of [ajomuch92/vue-enter-to-tab](https://github.com/ajomuch92/vue-enter-to-tab) and has been converted from a mixin to a Vue3 composable. It also features new options.
|
|
11
10
|
|
|
12
11
|
## Install
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
Requires Vue 3.3 or higher.
|
|
15
14
|
|
|
16
15
|
```bash
|
|
16
|
+
# npm
|
|
17
17
|
npm i --save vue3-enter-to-tab
|
|
18
|
+
# yarn
|
|
18
19
|
yarn add vue3-enter-to-tab
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
## Usage
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
### Minimal example with composition API
|
|
25
|
+
|
|
26
|
+
```vue
|
|
27
|
+
<template>
|
|
28
|
+
<div ref="form"></div>
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<script setup lang="ts">
|
|
32
|
+
import { ref } from 'vue'
|
|
33
|
+
import { useEnterToTab } from 'vue3-enter-to-tab'
|
|
34
|
+
|
|
35
|
+
// Get ref to the parent element
|
|
36
|
+
const form = ref<HTMLElement | null>(null)
|
|
37
|
+
|
|
38
|
+
useEnterToTab(form)
|
|
39
|
+
</script>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Full example
|
|
43
|
+
|
|
44
|
+
See documentation below.
|
|
45
|
+
|
|
46
|
+
```vue
|
|
47
|
+
<template>
|
|
48
|
+
<div ref="form">
|
|
49
|
+
<input />
|
|
50
|
+
<input v-prevent-enter-tab />
|
|
51
|
+
</div>
|
|
52
|
+
</template>
|
|
53
|
+
|
|
54
|
+
<script setup lang="ts">
|
|
55
|
+
import { useEnterToTab } from 'vue3-enter-to-tab'
|
|
56
|
+
import { ref } from 'vue'
|
|
57
|
+
|
|
58
|
+
const { vPreventEnterTab, isEnterToTabEnabled } = useEnterToTab(form, {
|
|
59
|
+
autoClickButton: false,
|
|
60
|
+
initialState: false,
|
|
61
|
+
})
|
|
62
|
+
// Read and change the status using that ref
|
|
63
|
+
isEnterToTabEnabled.value = true
|
|
64
|
+
</script>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Minimal example with options API
|
|
68
|
+
|
|
69
|
+
The code has not been tested yet and it is recommended to use the composition API instead.
|
|
70
|
+
|
|
71
|
+
```vue
|
|
72
|
+
<template>
|
|
73
|
+
<div ref="form"></div>
|
|
74
|
+
</template>
|
|
75
|
+
|
|
76
|
+
<script lang="ts">
|
|
77
|
+
import { defineComponent, ref } from 'vue'
|
|
24
78
|
import { useEnterToTab } from 'vue3-enter-to-tab'
|
|
25
79
|
|
|
26
|
-
|
|
27
|
-
|
|
80
|
+
export default defineComponent({
|
|
81
|
+
setup() {
|
|
82
|
+
useEnterToTab(this.$refs.form)
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
</script>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## API: `useEnterToTab(element, options?)`
|
|
89
|
+
|
|
90
|
+
### Input `element`
|
|
91
|
+
|
|
92
|
+
Type: `HTMLElement | null`
|
|
93
|
+
|
|
94
|
+
The parent element. This is where the event listener will be attached.
|
|
95
|
+
|
|
96
|
+
Enter key will be converted for all children input of this element, except for those with the `v-prevent-enter-tab` directive and not including `<textarea>`.
|
|
97
|
+
|
|
98
|
+
### Input `options`
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
interface UseEnterToTabOptions {
|
|
102
|
+
autoClickButton?: boolean
|
|
103
|
+
initialState?: boolean
|
|
104
|
+
}
|
|
28
105
|
```
|
|
29
106
|
|
|
30
|
-
|
|
107
|
+
#### autoClickButton
|
|
108
|
+
|
|
109
|
+
If the next element is a button, it will be clicked. Activating this has the advantage that it's not necessary to press enter twice to click a button (often to submit the form).
|
|
110
|
+
|
|
111
|
+
Disable this if you don't want to click buttons automatically and instead just focus them like other inputs.
|
|
112
|
+
|
|
113
|
+
Default: `true`
|
|
114
|
+
|
|
115
|
+
#### initialState
|
|
116
|
+
|
|
117
|
+
Initial state of the function.
|
|
118
|
+
|
|
119
|
+
Default: `true`
|
|
120
|
+
|
|
121
|
+
### Output `vPreventEnterTab`
|
|
122
|
+
|
|
123
|
+
Directive to use in those inputs you want to avoid use enter as tab. Inputs with this directive will act as normal when pressing enter.
|
|
31
124
|
|
|
32
|
-
|
|
125
|
+
### Output `isEnterToTabEnabled`
|
|
33
126
|
|
|
127
|
+
Ref to read and change the status of the function.
|
|
34
128
|
|
|
129
|
+
[npm-img]: https://img.shields.io/npm/v/vue3-enter-to-tab
|
|
130
|
+
[npm-url]: https://www.npmjs.com/package/vue3-enter-to-tab
|
package/lib/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { MaybeRefOrGetter } from 'vue';
|
|
2
|
+
export interface UseEnterToTabOptions {
|
|
3
|
+
autoClickButton?: boolean;
|
|
4
|
+
initialState?: boolean;
|
|
5
|
+
}
|
|
2
6
|
type HTMLElementWithPrevent = HTMLElement & {
|
|
3
7
|
preventEnterTab?: boolean;
|
|
4
8
|
};
|
|
5
|
-
export declare
|
|
6
|
-
autoClickButton?: boolean | undefined;
|
|
7
|
-
}) => {
|
|
9
|
+
export declare function useEnterToTab(element: MaybeRefOrGetter<HTMLElement | null | undefined>, options?: UseEnterToTabOptions): {
|
|
8
10
|
isEnterToTabEnabled: import("vue").Ref<boolean>;
|
|
9
11
|
vPreventEnterTab: {
|
|
10
12
|
beforeMount: (el: HTMLElementWithPrevent) => boolean;
|
|
11
13
|
};
|
|
12
|
-
setEnterToTabEnabled: (value: boolean) => void;
|
|
13
14
|
};
|
|
14
15
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useEventListener } from '@vueuse/core';
|
|
2
2
|
import { ref, toValue, nextTick } from 'vue';
|
|
3
|
-
export
|
|
4
|
-
const
|
|
3
|
+
export function useEnterToTab(element, options = {}) {
|
|
4
|
+
const { autoClickButton = true, initialState = true } = options;
|
|
5
|
+
const isEnterToTabEnabled = ref(initialState);
|
|
5
6
|
useEventListener(element, 'keydown', async (e) => {
|
|
6
7
|
const { ctrlKey, code, altKey, shiftKey } = e;
|
|
7
8
|
const target = e.target;
|
|
@@ -39,15 +40,11 @@ export const useEnterToTab = (element, { autoClickButton = true } = {}) => {
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
});
|
|
42
|
-
const setEnterToTabEnabled = (value) => {
|
|
43
|
-
isEnterToTabEnabled.value = value;
|
|
44
|
-
};
|
|
45
43
|
const vPreventEnterTab = {
|
|
46
44
|
beforeMount: (el) => (el.preventEnterTab = true),
|
|
47
45
|
};
|
|
48
46
|
return {
|
|
49
47
|
isEnterToTabEnabled,
|
|
50
48
|
vPreventEnterTab,
|
|
51
|
-
setEnterToTabEnabled,
|
|
52
49
|
};
|
|
53
|
-
}
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue3-enter-to-tab",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc --project tsconfig.json",
|
|
11
|
-
"typecheck": "tsc --noEmit"
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"release": "semantic-release"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
14
15
|
"type": "git",
|
|
@@ -29,8 +30,12 @@
|
|
|
29
30
|
},
|
|
30
31
|
"homepage": "https://github.com/l3d00m/vue3-enter-to-tab#readme",
|
|
31
32
|
"devDependencies": {
|
|
33
|
+
"@semantic-release/commit-analyzer": "11.0.0",
|
|
34
|
+
"@semantic-release/release-notes-generator": "12.0.0",
|
|
32
35
|
"@types/node": "20.8.2",
|
|
36
|
+
"conventional-changelog-conventionalcommits": "^6.1.0",
|
|
33
37
|
"prettier": "3.0.3",
|
|
38
|
+
"semantic-release": "^22.0.5",
|
|
34
39
|
"ts-node": "10.9.1",
|
|
35
40
|
"typescript": "5.2.2"
|
|
36
41
|
},
|