x-ui-design 1.0.22 → 1.0.24

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.
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import React, {
4
+ forwardRef,
4
5
  KeyboardEvent,
5
6
  MouseEvent,
6
7
  useEffect,
@@ -17,15 +18,7 @@ import { ErrorIcon } from '../Icons/Icons';
17
18
  import { applyMask, MASK_CHAR, MASK_REGEX, stripMask } from '../../helpers/mask';
18
19
  import './style.css';
19
20
 
20
- export interface MyInputHandle {
21
- focus: () => void;
22
- blur: () => void;
23
- input: HTMLInputElement | null;
24
- nativeElement: HTMLInputElement | null;
25
- setSelectionRange: (start: number, end: number) => void;
26
- }
27
-
28
- const InputComponent = ({
21
+ const InputComponent = forwardRef(({
29
22
  size = 'large',
30
23
  error,
31
24
  suffix,
@@ -53,9 +46,8 @@ const InputComponent = ({
53
46
  defaultValue,
54
47
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
55
48
  child,
56
- ref,
57
49
  ...props
58
- }: InputProps) => {
50
+ }: InputProps, ref) => {
59
51
  const inputRef = useRef<HTMLInputElement>(null);
60
52
  const lastKeyPressed = useRef<string | null>(null);
61
53
  const internalValue = mask ? applyMask(stripMask(`${value ?? ''}`, mask, maskChar), mask, maskChar).masked : value ?? '';
@@ -63,25 +55,22 @@ const InputComponent = ({
63
55
  const [iconRenderVisible, setIconRenderVisible] = useState(false);
64
56
  const animationRef = useRef<number | null>(null);
65
57
 
66
- useImperativeHandle<HTMLInputElement, HTMLInputElement>(ref, () => {
67
- if (inputRef.current) {
68
- const input = inputRef.current;
69
-
70
- (input as any).setSelectionRangeCustom = (start: number, end: number) => {
71
- input.setSelectionRange(start, end);
72
- };
73
-
74
- (input as any).nativeElement = input;
75
-
76
- return input;
58
+ useImperativeHandle(ref, () => ({
59
+ focus: () => {
60
+ console.info('focusing');
61
+ inputRef.current?.focus()
62
+ },
63
+ blur: () => {
64
+ inputRef.current?.blur()
65
+ },
66
+ input: inputRef.current,
67
+ nativeElement: inputRef.current,
68
+ setSelectionRange: (start: number, end: number) => {
69
+ if (inputRef.current) {
70
+ inputRef.current.setSelectionRange(start, end);
71
+ }
77
72
  }
78
-
79
- return {
80
- focus: () => inputRef.current?.focus(),
81
- blur: () => inputRef.current?.blur(),
82
- setSelectionRange: () => {},
83
- } as any;
84
- }, [inputRef]);
73
+ }), [ref]);
85
74
 
86
75
  useEffect(() => {
87
76
  setMaskValue(mask ? applyMask(stripMask(`${value ?? ''}`, mask, maskChar), mask, maskChar).masked : (value ?? ''));
@@ -219,7 +208,7 @@ const InputComponent = ({
219
208
  ) : null}
220
209
  </div>
221
210
  );
222
- };
211
+ });
223
212
 
224
213
  InputComponent.displayName = 'Input';
225
214
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-ui-design",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "license": "ISC",
5
5
  "author": "Gabriel Boyajyan",
6
6
  "main": "dist/index.js",
package/src/app/page.tsx CHANGED
@@ -13,6 +13,8 @@ export default function Home() {
13
13
 
14
14
  useEffect(() => {
15
15
  if (ref.current) {
16
+ console.log(ref.current);
17
+
16
18
  ref.current.focus();
17
19
  }
18
20
  }, [])