use-mask-input 3.4.1 → 3.5.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/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +77 -1
- package/dist/index.cjs +9 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +1 -0
- package/src/useHookFormMask.ts +13 -3
- package/src/utils/getMaskOptions.ts +1 -0
package/package.json
CHANGED
package/src/index.tsx
CHANGED
package/src/useHookFormMask.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import inputmask from 'inputmask';
|
|
2
2
|
import { RefCallback } from 'react';
|
|
3
3
|
import {
|
|
4
|
-
FieldValues, Path,
|
|
4
|
+
FieldValues, Path,
|
|
5
|
+
RegisterOptions,
|
|
6
|
+
UseFormRegister,
|
|
5
7
|
} from 'react-hook-form';
|
|
6
|
-
import { flow, getMaskOptions } from './utils';
|
|
7
8
|
import { Mask, Options } from './types';
|
|
9
|
+
import { flow, getMaskOptions } from './utils';
|
|
8
10
|
|
|
9
11
|
export function useHookFormMask<
|
|
10
12
|
T extends FieldValues, D extends RegisterOptions,
|
|
@@ -17,7 +19,15 @@ export function useHookFormMask<
|
|
|
17
19
|
const maskInput = inputmask(getMaskOptions(mask, options as any));
|
|
18
20
|
|
|
19
21
|
const newRef = flow((_ref: HTMLElement) => {
|
|
20
|
-
if (_ref)
|
|
22
|
+
if (_ref) {
|
|
23
|
+
const { nodeName } = _ref;
|
|
24
|
+
|
|
25
|
+
if (nodeName !== 'INPUT') {
|
|
26
|
+
maskInput.mask(_ref.querySelector('input') as HTMLElement);
|
|
27
|
+
} else {
|
|
28
|
+
maskInput.mask(_ref);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
21
31
|
return _ref;
|
|
22
32
|
}, ref) as RefCallback<HTMLElement>;
|
|
23
33
|
|