vue3-enter-to-tab 0.0.1 → 3.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 CHANGED
@@ -1,34 +1,131 @@
1
- # vue3-enter-to-tab
1
+ # `vue3-enter-to-tab` composable
2
2
 
3
3
  [![npm package][npm-img]][npm-url]
4
- [![Build Status][build-img]][build-url]
4
+ [![Release](https://github.com/l3d00m/vue3-enter-to-tab/actions/workflows/release.yml/badge.svg)](https://github.com/l3d00m/vue3-enter-to-tab/actions/workflows/release.yml)
5
+ [![ci](https://github.com/l3d00m/vue3-enter-to-tab/actions/workflows/ci.yml/badge.svg)](https://github.com/l3d00m/vue3-enter-to-tab/actions/workflows/ci.yml)
5
6
 
6
- TODO description
7
+ A Vue 3 composable to convert enter key to tab key. Especially useful when inputting forms using a numpad.
7
8
 
8
- ## Credits
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
- NPM:
13
+ Requires Vue >=3.3 and Node >=18.
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
- ```ts
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 form = ref<HTMLElement | null>(null)
59
+ const { vPreventEnterTab, isEnterToTabEnabled } = useEnterToTab(form, {
60
+ autoClickButton: false,
61
+ initialState: false,
62
+ })
63
+ // Read and change the status using that ref
64
+ isEnterToTabEnabled.value = true
65
+ </script>
66
+ ```
67
+
68
+ ### Minimal example with options API
69
+
70
+ The code has not been tested yet and it is recommended to use the composition API instead.
71
+
72
+ ```vue
73
+ <template>
74
+ <div ref="form"></div>
75
+ </template>
76
+
77
+ <script lang="ts">
78
+ import { defineComponent, ref } from 'vue'
24
79
  import { useEnterToTab } from 'vue3-enter-to-tab'
25
80
 
26
- myPackage('hello')
27
- //=> 'hello from my package'
81
+ export default defineComponent({
82
+ setup() {
83
+ useEnterToTab(this.$refs.form)
84
+ },
85
+ })
86
+ </script>
87
+ ```
88
+
89
+ ## API: `useEnterToTab(element, options?)`
90
+
91
+ ### Input `element`
92
+
93
+ Type: `HTMLElement | null`
94
+
95
+ The parent element. This is where the event listener will be attached.
96
+
97
+ 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>`.
98
+
99
+ ### Input `options`
100
+
101
+ ```ts
102
+ interface UseEnterToTabOptions {
103
+ autoClickButton?: boolean
104
+ initialState?: boolean
105
+ }
28
106
  ```
29
107
 
30
- **Note**: This directive doesn't work on textarea elements.
108
+ #### autoClickButton
109
+
110
+ 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).
111
+
112
+ Disable this if you don't want to click buttons automatically and instead just focus them like other inputs.
113
+
114
+ Default: `true`
115
+
116
+ #### initialState
117
+
118
+ Initial state of the function.
119
+
120
+ Default: `true`
121
+
122
+ ### Output `vPreventEnterTab`
123
+
124
+ 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
125
 
32
- Any contribution is welcome. Visit my web page [here](https://www.ajomuch92.site/#/).
126
+ ### Output `isEnterToTabEnabled`
33
127
 
128
+ Ref to read and change the status of the function.
34
129
 
130
+ [npm-img]: https://img.shields.io/npm/v/vue3-enter-to-tab
131
+ [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 const useEnterToTab: (element: MaybeRefOrGetter<HTMLElement | null | undefined>, { autoClickButton }?: {
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 const useEnterToTab = (element, { autoClickButton = true } = {}) => {
4
- const isEnterToTabEnabled = ref(true);
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.1",
3
+ "version": "3.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",
@@ -21,7 +22,7 @@
21
22
  "url": "https://github.com/l3d00m"
22
23
  },
23
24
  "engines": {
24
- "node": ">=16.0"
25
+ "node": ">=18.0"
25
26
  },
26
27
  "keywords": [],
27
28
  "bugs": {
@@ -29,12 +30,16 @@
29
30
  },
30
31
  "homepage": "https://github.com/l3d00m/vue3-enter-to-tab#readme",
31
32
  "devDependencies": {
32
- "@types/node": "20.8.2",
33
- "prettier": "3.0.3",
33
+ "@semantic-release/commit-analyzer": "11.1.0",
34
+ "@semantic-release/release-notes-generator": "12.1.0",
35
+ "@types/node": "20.9.0",
36
+ "conventional-changelog-conventionalcommits": "^7.0.2",
37
+ "prettier": "3.1.0",
38
+ "semantic-release": "^22.0.7",
34
39
  "ts-node": "10.9.1",
35
40
  "typescript": "5.2.2"
36
41
  },
37
- "packageManager": "yarn@3.6.4",
42
+ "packageManager": "yarn@4.0.1",
38
43
  "dependencies": {
39
44
  "@vueuse/core": ">9.x",
40
45
  "vue": ">=3.3 <4"