From 1461bf5134e5d36a6be884d34d0426a6d4a25fac Mon Sep 17 00:00:00 2001 From: simpleStyle <45413090+simplyStyle@users.noreply.github.com> Date: Tue, 8 Nov 2022 09:54:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20input=E7=BB=84=E4=BB=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81name=E5=B1=9E=E6=80=A7=20(#427)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: input组件支持name属性 * feat: input组件支持ref属性获取input实例 * feat: 新增name属性的doc文档 * feat: 新增ref新特性支持获取input实例 --- .../__test__/__snapshots__/input.spec.tsx.snap | 3 +-- src/packages/input/__test__/input.spec.tsx | 15 +++++++++++++-- src/packages/input/demo.taro.tsx | 6 ++++++ src/packages/input/demo.tsx | 6 ++++++ src/packages/input/doc.en-US.md | 9 ++++++++- src/packages/input/doc.md | 9 ++++++++- src/packages/input/doc.zh-TW.md | 9 ++++++++- src/packages/input/input.taro.tsx | 15 +++++++++++++-- src/packages/input/input.tsx | 15 +++++++++++++-- 9 files changed, 76 insertions(+), 11 deletions(-) diff --git a/src/packages/input/__test__/__snapshots__/input.spec.tsx.snap b/src/packages/input/__test__/__snapshots__/input.spec.tsx.snap index aa6f4cf..9c87417 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 c2fb020..967d919 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' ? (