diff --git a/packages/console/src/components/TextInput/index.module.scss b/packages/console/src/components/TextInput/index.module.scss index 1f76b0fc2..c8e0c8df8 100644 --- a/packages/console/src/components/TextInput/index.module.scss +++ b/packages/console/src/components/TextInput/index.module.scss @@ -71,6 +71,16 @@ height: 18px; } } + + &[type='number'] { + -moz-appearance: textfield; + + &::-webkit-outer-spin-button, + &::-webkit-inner-spin-button { + -webkit-appearance: none; + margin: 0; + } + } } &.disabled { diff --git a/packages/console/src/components/TextInput/index.tsx b/packages/console/src/components/TextInput/index.tsx index a83ab7ec4..34e3d736e 100644 --- a/packages/console/src/components/TextInput/index.tsx +++ b/packages/console/src/components/TextInput/index.tsx @@ -1,6 +1,15 @@ +import { type Nullable } from '@silverhand/essentials'; import classNames from 'classnames'; -import type { HTMLProps, ForwardedRef, ReactElement } from 'react'; -import { cloneElement, forwardRef } from 'react'; +import { + type HTMLProps, + type ReactElement, + useImperativeHandle, + useRef, + cloneElement, + forwardRef, + type Ref, + useEffect, +} from 'react'; import * as styles from './index.module.scss'; @@ -20,10 +29,36 @@ function TextInput( disabled, className, readOnly, + type = 'text', ...rest }: Props, - reference: ForwardedRef + reference: Ref> ) { + const innerRef = useRef(null); + useImperativeHandle(reference, () => innerRef.current); + + useEffect(() => { + if (type !== 'number') { + return; + } + + const input = innerRef.current; + + if (!input) { + return; + } + + const handleWheel = (event: WheelEvent) => { + event.preventDefault(); + }; + + input.addEventListener('wheel', handleWheel, { passive: false }); + + return () => { + input.removeEventListener('wheel', handleWheel); + }; + }, [type]); + return (
{icon && {icon}} - + {suffix && cloneElement(suffix, { className: classNames([suffix.props.className, styles.suffix]), diff --git a/packages/console/src/pages/ApiResourceDetails/ApiResourceSettings/index.tsx b/packages/console/src/pages/ApiResourceDetails/ApiResourceSettings/index.tsx index 923c39fd0..51dacae51 100644 --- a/packages/console/src/pages/ApiResourceDetails/ApiResourceSettings/index.tsx +++ b/packages/console/src/pages/ApiResourceDetails/ApiResourceSettings/index.tsx @@ -68,7 +68,11 @@ function ApiResourceSettings() { diff --git a/packages/console/src/pages/Connectors/components/ConfigForm/index.tsx b/packages/console/src/pages/Connectors/components/ConfigForm/index.tsx index 29c000e23..87487764f 100644 --- a/packages/console/src/pages/Connectors/components/ConfigForm/index.tsx +++ b/packages/console/src/pages/Connectors/components/ConfigForm/index.tsx @@ -51,7 +51,10 @@ function ConfigForm({ formItems }: Props) { const errorMessage = errors[item.key]?.message; const buildCommonProperties = () => ({ - ...register(item.key, { required: item.required }), + ...register(item.key, { + required: item.required, + valueAsNumber: item.type === ConnectorConfigFormItemType.Number, + }), placeholder: item.placeholder, hasError, });