Skip to content

Commit 4ddee37

Browse files
committed
chore: use rc-util focus
1 parent 6358fcf commit 4ddee37

File tree

4 files changed

+7
-36
lines changed

4 files changed

+7
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"prepare": "husky install"
4545
},
4646
"dependencies": {
47-
"@rc-component/util": "^1.3.0",
47+
"@rc-component/util": "^1.4.0",
4848
"clsx": "^2.1.1"
4949
},
5050
"devDependencies": {

src/Input.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ import type { HolderRef } from './BaseInput';
1212
import BaseInput from './BaseInput';
1313
import useCount from './hooks/useCount';
1414
import type { ChangeEventInfo, InputProps, InputRef } from './interface';
15-
import type { InputFocusOptions } from './utils/commonUtils';
16-
import { resolveOnChange, triggerFocus } from './utils/commonUtils';
15+
import { resolveOnChange } from './utils/commonUtils';
16+
import {
17+
triggerFocus,
18+
type InputFocusOptions,
19+
} from '@rc-component/util/lib/Dom/focus';
1720

1821
const Input = forwardRef<InputRef, InputProps>((props, ref) => {
1922
const {

src/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type {
66
ReactElement,
77
ReactNode,
88
} from 'react';
9-
import type { InputFocusOptions } from './utils/commonUtils';
109
import type { LiteralUnion } from './utils/types';
10+
import type { InputFocusOptions } from '@rc-component/util/lib/Dom/focus';
1111

1212
export interface CommonInputProps {
1313
prefix?: ReactNode;

src/utils/commonUtils.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -90,35 +90,3 @@ export function resolveOnChange<
9090
}
9191
onChange(event as React.ChangeEvent<E>);
9292
}
93-
94-
export interface InputFocusOptions extends FocusOptions {
95-
cursor?: 'start' | 'end' | 'all';
96-
}
97-
98-
export function triggerFocus(
99-
element?: HTMLInputElement | HTMLTextAreaElement,
100-
option?: InputFocusOptions,
101-
) {
102-
if (!element) return;
103-
104-
element.focus(option);
105-
106-
// Selection content
107-
const { cursor } = option || {};
108-
if (cursor) {
109-
const len = element.value.length;
110-
111-
switch (cursor) {
112-
case 'start':
113-
element.setSelectionRange(0, 0);
114-
break;
115-
116-
case 'end':
117-
element.setSelectionRange(len, len);
118-
break;
119-
120-
default:
121-
element.setSelectionRange(0, len);
122-
}
123-
}
124-
}

0 commit comments

Comments
 (0)