diff --git a/src/packages/input/__test__/__snapshots__/input.spec.tsx.snap b/src/packages/input/__test__/__snapshots__/input.spec.tsx.snap index aa6f4cf6582724b14c38f5ac4d54c754e8e29480..9c8741707b4ab6c9d31f8a7fda3cde1d2aa8889b 100644 --- a/src/packages/input/__test__/__snapshots__/input.spec.tsx.snap +++ b/src/packages/input/__test__/__snapshots__/input.spec.tsx.snap @@ -4,8 +4,6 @@ exports[`input props test 1`] = `
{ const { container } = render( - + ) expect(container.querySelector('.label-string')?.innerHTML).toBe('文本') expect(container.querySelector('.input-text')).toHaveAttribute( @@ -17,6 +22,7 @@ test('input props test', () => { 'value', '初始文本' ) + expect(container.querySelector('.input-text')).toHaveAttribute('name', 'text') expect(container.querySelector('.input-text')).toHaveAttribute('type', 'text') expect(container).toMatchSnapshot() }) @@ -48,6 +54,7 @@ test('disabled test', () => { test('textarea test', () => { const { container } = render( { maxlength="50" /> ) + expect(container.querySelector('.input-text')).toHaveAttribute( + 'name', + 'textarea' + ) expect(container.querySelector('.input-text')).toHaveAttribute( 'maxlength', '50' @@ -159,7 +170,7 @@ test('slotButton test', () => { /> ) expect(container.querySelector('.nut-button__warp')?.innerHTML).toBe( - '发送验证码' + '
发送验证码
' ) }) diff --git a/src/packages/input/demo.taro.tsx b/src/packages/input/demo.taro.tsx index c2fb02048f2e2508d7e126fc8e46bfe37aed8f01..967d9199bbe7b5ebc00c074e5b4dcabc873440c0 100644 --- a/src/packages/input/demo.taro.tsx +++ b/src/packages/input/demo.taro.tsx @@ -159,6 +159,7 @@ const InputDemo = () => {

{translated.basic}

{ />

{translated.title1}

{

{translated.basic}

{ />

{translated.title1}

{ const [value, UpdateValue] = useState('') return ( <> - { + { UpdateValue(val) }}/> @@ -50,29 +50,34 @@ const App = () => { return ( <> { const [value, UpdateValue] = useState('') return ( <> - { + { UpdateValue(val) }}/> @@ -53,29 +53,34 @@ const App = () => { return ( <> { const [value, UpdateValue] = useState('') return ( <> - { + { UpdateValue(val) }}/> @@ -53,29 +53,34 @@ const App = () => { return ( <> , 'onChange' | 'onBlur' | 'onFocus' | 'onClick' > -> = (props) => { +> = forwardRef((props, ref) => { const { locale } = useConfig() const { children, type, + name, defaultValue, placeholder, label, @@ -218,6 +223,10 @@ export const Input: FunctionComponent< } }, [inputValue]) + useImperativeHandle(ref, () => { + return inputRef.current + }) + const inputClass = useCallback(() => { const prefixCls = 'nut-input' return [ @@ -405,6 +414,7 @@ export const Input: FunctionComponent< > {type === 'textarea' ? (