Skip to content

Commit c20801d

Browse files
authored
feat(Textarea): 增加 ref 属性 (#3229)
* feat(Textarea): 增加 ref 属性 * feat: add get functions * fix: 暴露 nativeElement
1 parent f8d88d3 commit c20801d

File tree

16 files changed

+256
-131
lines changed

16 files changed

+256
-131
lines changed

src/packages/input/doc.en-US.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ import { Input } from '@nutui/nutui-react'
148148
| onClear | Triggered when the clear button is clicked | `(value: string) => void` | `-` |
149149
| onClick | Triggered when the input container is clicked | `(value: MouseEvent<HTMLDivElement>) => void` | `-` |
150150

151+
### Ref
152+
153+
You can get Ref of Input.
154+
155+
| Event | Description | Arguments |
156+
| --- | --- | --- |
157+
| clear | clear the value of input | `-` |
158+
| focus | focus the input | `-` |
159+
| blur | blur the input | `-` |
160+
| get | get the input ref | `-` |
161+
151162
## Theming
152163

153164
### CSS Variables

src/packages/input/doc.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ import { Input } from '@nutui/nutui-react'
151151

152152
此外还支持以下原生属性:`onCompositionStart` `onCompositionEnd`
153153

154+
### Ref
155+
156+
通过 ref 可以获取到 Input 实例并调用实例方法。
157+
158+
| 方法名 | 说明 | 参数 |
159+
| --- | --- | --- |
160+
| clear | 清除容器中的数据 | `-` |
161+
| focus | 使容器获取焦点 | `-` |
162+
| blur | 使容器失去焦点 | `-` |
163+
| get | 获取当前容器 | `-` |
164+
154165
## 主题定制
155166

156167
### 样式变量

src/packages/input/doc.taro.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ import { Input } from '@nutui/nutui-react-taro'
151151

152152
此外还支持 Taro 中的 [Input 属性](https://docs.taro.zone/docs/components/forms/input/)
153153

154+
### Ref
155+
156+
通过 ref 可以获取到 Input 实例并调用实例方法。
157+
158+
| 方法名 | 说明 | 参数 |
159+
| --- | --- | --- |
160+
| clear | 清除容器中的数据 | `-` |
161+
| focus | 使容器获取焦点 | `-` |
162+
| blur | 使容器失去焦点 | `-` |
163+
| get | 获取当前容器 | `-` |
164+
154165
## 主题定制
155166

156167
### 样式变量

src/packages/input/doc.zh-TW.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ import { Input } from '@nutui/nutui-react'
148148
| onClear | 点击清空按钮时触发 | `(value: string) => void` | `-` |
149149
| onClick | 点击 input 容器触发 | `(value: MouseEvent<HTMLDivElement>) => void` | `-` |
150150

151+
### Ref
152+
153+
通過 ref 可以獲取到 Input 實例並調用實例方法。
154+
155+
| 方法名 | 說明 | 參數 |
156+
| --- | --- | --- |
157+
| clear | 清除容器中的數據 | `-` |
158+
| focus | 使容器獲取焦點 | `-` |
159+
| blur | 使容器失去焦點 | `-` |
160+
| get | 獲取當前容器 | `-` |
161+
151162
## 主题定制
152163

153164
### 样式变量

src/packages/input/input.taro.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const Input = forwardRef((props: Partial<TaroInputProps>, ref) => {
8888
blur: () => {
8989
inputRef.current?.blur()
9090
},
91+
get: () => inputRef.current,
9192
get nativeElement() {
9293
return inputRef.current
9394
},

src/packages/input/input.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export const Input = forwardRef(
8585
clear: () => setValue(''),
8686
focus: () => inputRef.current?.focus(),
8787
blur: () => inputRef.current?.blur(),
88+
get: () => inputRef.current,
8889
get nativeElement() {
8990
return inputRef.current
9091
},

src/packages/textarea/doc.en-US.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ import { TextArea } from '@nutui/nutui-react'
9595
| onFocus | Triggered when focusing | `(event: FocusEvent<HTMLTextAreaElement>) => void` | `-` |
9696
| onBlur | Triggered when out of focus | `(event: FocusEvent<HTMLTextAreaElement>) => void` | `-` |
9797

98+
### Ref
99+
100+
You can get Ref of Textarea.
101+
102+
| Event | Description | Arguments |
103+
| --- | --- | --- |
104+
| clear | clear the value of textarea | `-` |
105+
| focus | focus the textarea | `-` |
106+
| blur | blur the textarea | `-` |
107+
| nativeElement | get the textarea ref | `-` |
108+
98109
## Theming
99110

100111
### CSS Variables

src/packages/textarea/doc.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ import { TextArea } from '@nutui/nutui-react'
9595
| onFocus | 聚焦时触发 | `(event: FocusEvent<HTMLTextAreaElement>) => void` | `-` |
9696
| onBlur | 失焦时触发 | `(event: FocusEvent<HTMLTextAreaElement>) => void` | `-` |
9797

98+
### Ref
99+
100+
通过 ref 可以获取到 Textarea 实例并调用实例方法。
101+
102+
| 方法名 | 说明 | 参数 |
103+
| --- | --- | --- |
104+
| clear | 清除容器中的数据 | `-` |
105+
| focus | 使容器获取焦点 | `-` |
106+
| blur | 使容器失去焦点 | `-` |
107+
| nativeElement | 获取当前容器 | `-` |
108+
98109
## 主题定制
99110

100111
### 样式变量

src/packages/textarea/doc.taro.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ import { TextArea } from '@nutui/nutui-react-taro'
9595
| onFocus | 聚焦时触发 | `(event) => void` | `-` |
9696
| onBlur | 失焦时触发 | `(event) => void` | `-` |
9797

98+
### Ref
99+
100+
通过 ref 可以获取到 Textarea 实例并调用实例方法。
101+
102+
| 方法名 | 说明 | 参数 |
103+
| --- | --- | --- |
104+
| clear | 清除容器中的数据 | `-` |
105+
| focus | 使容器获取焦点 | `-` |
106+
| blur | 使容器失去焦点 | `-` |
107+
| nativeElement | 获取当前容器 | `-` |
108+
98109
## 主题定制
99110

100111
### 样式变量

src/packages/textarea/doc.zh-TW.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ import { TextArea } from '@nutui/nutui-react'
9494
| onFocus | 聚焦時觸發 | `(event) => void` | `-` |
9595
| onBlur | 失焦時觸發 | `(event) => void` | `-` |
9696

97+
### Ref
98+
99+
通過 ref 可以獲取到 Textarea 實例並調用實例方法。
100+
101+
| 方法名 | 說明 | 參數 |
102+
| --- | --- | --- |
103+
| clear | 清除容器中的數據 | `-` |
104+
| focus | 使容器獲取焦點 | `-` |
105+
| blur | 使容器失去焦點 | `-` |
106+
| nativeElement | 獲取當前容器 | `-` |
107+
97108
## 主題定制
98109

99110
### 樣式變量

0 commit comments

Comments
 (0)