Skip to content

Commit 56f3a8e

Browse files
authored
feat: 给 searchbar 暴露 input 更多属性 (#3416)
1 parent 89d5c97 commit 56f3a8e

File tree

12 files changed

+134
-1
lines changed

12 files changed

+134
-1
lines changed

src/packages/searchbar/demo.taro.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Demo4 from './demos/taro/demo4'
1212
import Demo5 from './demos/taro/demo5'
1313
import Demo6 from './demos/taro/demo6'
1414
import Demo7 from './demos/taro/demo7'
15+
import Demo8 from './demos/taro/demo8'
1516
import Demo10 from './demos/taro/demo10'
1617

1718
const SearchBarDemo = () => {
@@ -25,6 +26,7 @@ const SearchBarDemo = () => {
2526
title5: '自定义图标设置',
2627
title6: '数据改变监听',
2728
title7: '自定义设置',
29+
title8: 'InputProps扩展属性',
2830
},
2931
'zh-TW': {
3032
title1: '基礎用法',
@@ -35,6 +37,7 @@ const SearchBarDemo = () => {
3537
title5: '自定義圖標設定',
3638
title6: '數據改變監聽',
3739
title7: '自定義設定',
40+
title8: 'InputProps擴展屬性',
3841
},
3942
'en-US': {
4043
title1: 'Basic Usage',
@@ -45,6 +48,7 @@ const SearchBarDemo = () => {
4548
title5: 'Custom Icon Settings',
4649
title6: 'Data Change Monitoring',
4750
title7: 'Custom Settings',
51+
title8: 'InputProps Extension Attributes',
4852
},
4953
})
5054

@@ -71,6 +75,8 @@ const SearchBarDemo = () => {
7175
<Demo6 />
7276
</>
7377
)}
78+
<View className="h2">{translated.title8}</View>
79+
<Demo8 />
7480
<View className="h2">{translated.title6}</View>
7581
<Demo7 />
7682
</ScrollView>

src/packages/searchbar/demo.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Demo4 from './demos/h5/demo4'
88
import Demo5 from './demos/h5/demo5'
99
import Demo6 from './demos/h5/demo6'
1010
import Demo7 from './demos/h5/demo7'
11+
import Demo8 from './demos/h5/demo8'
1112
import Demo10 from './demos/h5/demo10'
1213

1314
const SearchBarDemo = () => {
@@ -21,6 +22,7 @@ const SearchBarDemo = () => {
2122
title5: '自定义图标设置',
2223
title6: '数据改变监听',
2324
title7: '自定义设置',
25+
title8: 'InputProps扩展属性',
2426
},
2527
'zh-TW': {
2628
title1: '基礎用法',
@@ -31,6 +33,7 @@ const SearchBarDemo = () => {
3133
title5: '自定義圖標設定',
3234
title6: '數據改變監聽',
3335
title7: '自定義設定',
36+
title8: 'InputProps擴展屬性',
3437
},
3538
'en-US': {
3639
title1: 'Basic Usage',
@@ -41,6 +44,7 @@ const SearchBarDemo = () => {
4144
title5: 'Custom Icon Settings',
4245
title6: 'Data Change Monitoring',
4346
title7: 'Custom Settings',
47+
title8: 'InputProps Extension Attributes',
4448
},
4549
})
4650

@@ -61,6 +65,8 @@ const SearchBarDemo = () => {
6165
<Demo5 />
6266
<h2>{translated.title7}</h2>
6367
<Demo6 />
68+
<h2>{translated.title8}</h2>
69+
<Demo8 />
6470
<h2>{translated.title6}</h2>
6571
<Demo7 />
6672
</div>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react'
2+
import { Scan } from '@nutui/icons-react'
3+
import { SearchBar } from '@nutui/nutui-react'
4+
5+
const Demo = () => {
6+
return (
7+
<>
8+
<SearchBar
9+
placeholder="使用inputProps扩展属性"
10+
inputProps={{
11+
autoComplete: 'off',
12+
autoCapitalize: 'none',
13+
spellCheck: false,
14+
}}
15+
/>
16+
<SearchBar
17+
leftIn={<Scan />}
18+
placeholder="自定义input类型和属性"
19+
inputProps={{
20+
type: 'search',
21+
autoComplete: 'on',
22+
}}
23+
/>
24+
<SearchBar
25+
placeholder="设置自定义属性"
26+
inputProps={{
27+
'aria-label': '搜索输入框',
28+
}}
29+
/>
30+
</>
31+
)
32+
}
33+
export default Demo
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react'
2+
import { Scan } from '@nutui/icons-react-taro'
3+
import { SearchBar } from '@nutui/nutui-react-taro'
4+
5+
const Demo = () => {
6+
return (
7+
<>
8+
<SearchBar
9+
placeholder="使用inputProps扩展属性"
10+
inputProps={{
11+
confirmType: 'search',
12+
password: false,
13+
maxlength: 20,
14+
}}
15+
/>
16+
<SearchBar
17+
leftIn={<Scan />}
18+
placeholder="自定义confirmType为search"
19+
inputProps={{
20+
confirmType: 'search',
21+
type: 'text',
22+
}}
23+
/>
24+
<SearchBar
25+
placeholder="设置maxlength为10"
26+
inputProps={{
27+
maxlength: 10,
28+
}}
29+
/>
30+
</>
31+
)
32+
}
33+
export default Demo

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ import { SearchBar } from '@nutui/nutui-react'
7878

7979
:::
8080

81+
82+
### InputProps Extension Attributes
83+
84+
`SearchBar`'s `inputProps` property can extend the attributes of the underlying input element, supporting all attributes of the native input element.
85+
86+
:::demo
87+
88+
<CodeBlock src='h5/demo8.tsx'></CodeBlock>
89+
90+
:::
91+
8192
### Data change monitoring
8293

8394
`SearchBar`'s `onChange` You can get the input content.
@@ -88,6 +99,7 @@ import { SearchBar } from '@nutui/nutui-react'
8899

89100
:::
90101

102+
91103
## SearchBar
92104

93105
### Props
@@ -113,6 +125,7 @@ import { SearchBar } from '@nutui/nutui-react'
113125
| onClear | triggered when clicking clear | `(event: MouseEvent<HTMLDivElement>) => void` | `-` |
114126
| onSearch | trigger when confirming search | `(val: string) => void` | `-` |
115127
| onInputClick | triggered when clicking the input area | `(event: MouseEvent<HTMLInputElement>) => void` | `-` |
128+
| inputProps | Extend the underlying input element attributes, supporting all attributes of the native input element | `Partial<InputHTMLAttributes<HTMLInputElement>>` | `-` |
116129

117130
## Theming
118131

src/packages/searchbar/doc.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ import { SearchBar } from '@nutui/nutui-react'
7676

7777
:::
7878

79+
### InputProps扩展属性
80+
81+
`SearchBar``inputProps` 属性可以扩展底层输入框的属性,支持传入原生input元素的所有属性。
82+
83+
:::demo
84+
85+
<CodeBlock src='h5/demo8.tsx'></CodeBlock>
86+
87+
:::
88+
7989
### 数据改变监听
8090

8191
`SearchBar``onChange` 可获取输入的内容。
@@ -86,6 +96,8 @@ import { SearchBar } from '@nutui/nutui-react'
8696

8797
:::
8898

99+
100+
89101
## SearchBar
90102

91103
### Props
@@ -106,6 +118,7 @@ import { SearchBar } from '@nutui/nutui-react'
106118
| right | 搜搜框右侧区域 | `ReactNode` | `-` |
107119
| leftIn | 输入框内左侧区域 | `ReactNode` | `<Search />` |
108120
| rightIn | 输入框内右侧区域 | `ReactNode` | `-` |
121+
| inputProps | 扩展底层输入框属性,支持传入原生input元素的所有属性 | `Partial<InputHTMLAttributes<HTMLInputElement>>` | `-` |
109122
| onChange | 输入内容时触发 | `(value: string, event: ChangeEvent<HTMLInputElement>) => void` | `-` |
110123
| onFocus | 聚焦时触发 | `(value: string, event: FocusEvent<HTMLInputElement>) => void` | `-` |
111124
| onBlur | 失焦时触发 | `(value: string, event: FocusEvent<HTMLInputElement>) => void` | `-` |

src/packages/searchbar/doc.taro.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ import { SearchBar } from '@nutui/nutui-react-taro'
7878

7979
:::
8080

81+
### InputProps扩展属性
82+
83+
`SearchBar``inputProps` 属性可以扩展底层TaroInput组件的属性,支持传入TaroInput组件的所有属性。
84+
85+
:::demo
86+
87+
<CodeBlock src='taro/demo8.tsx'></CodeBlock>
88+
89+
:::
90+
8191
### 数据改变监听
8292

8393
`SearchBar``onChange` 可获取输入的内容。
@@ -108,6 +118,7 @@ import { SearchBar } from '@nutui/nutui-react-taro'
108118
| right | 搜搜框右侧区域 | `ReactNode` | `-` |
109119
| leftIn | 输入框内左侧区域 | `ReactNode` | `<Search />` |
110120
| rightIn | 输入框内右侧区域 | `ReactNode` | `-` |
121+
| inputProps | 扩展底层TaroInput组件属性,支持传入TaroInput组件的所有属性 | `Partial<InputProps>` | `-` |
111122
| onChange | 输入内容时触发 | `(value: string, event: ChangeEvent<HTMLInputElement>) => void` | `-` |
112123
| onFocus | 聚焦时触发 | `(value: string, event: FocusEvent<HTMLInputElement>) => void` | `-` |
113124
| onBlur | 失焦时触发 | `(value: string, event: FocusEvent<HTMLInputElement>) => void` | `-` |

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ import { SearchBar } from '@nutui/nutui-react'
7878

7979
:::
8080

81+
### InputProps擴展屬性
82+
83+
`SearchBar``inputProps` 屬性可以擴展底層輸入框的屬性,支持傳入原生input元素的所有屬性。
84+
85+
:::demo
86+
87+
<CodeBlock src='h5/demo8.tsx'></CodeBlock>
88+
89+
:::
90+
8191
### 數據改變監聽
8292

8393
`SearchBar``onChange` 可獲取輸入的內容。
@@ -108,6 +118,7 @@ import { SearchBar } from '@nutui/nutui-react'
108118
| right | 搜搜框右側區域 | `ReactNode` | `-` |
109119
| leftIn | 輸入框內左側區域 | `ReactNode` | `<Search />` |
110120
| rightIn | 輸入框內右側區域 | `ReactNode` | `-` |
121+
| inputProps | 擴展底層輸入框屬性,支持傳入原生input元素的所有屬性 | `Partial<InputHTMLAttributes<HTMLInputElement>>` | `-` |
111122
| onChange | 輸入內容時觸發 | `(value: string, event: ChangeEvent<HTMLInputElement>) => void` | `-` |
112123
| onFocus | 聚焦時觸發 | `(value: string, event: FocusEvent<HTMLInputElement>) => void` | `-` |
113124
| onBlur | 失焦時觸發 | `(value: string, event: FocusEvent<HTMLInputElement>) => void` | `-` |

src/packages/searchbar/searchbar.taro.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const SearchBar: FunctionComponent<
6565
leftIn,
6666
rightIn,
6767
tag,
68+
inputProps,
6869
onChange,
6970
onFocus,
7071
onBlur,
@@ -189,6 +190,7 @@ export const SearchBar: FunctionComponent<
189190
onBlur={handleBlur}
190191
onClick={onInputClick}
191192
onConfirm={onConfirm}
193+
{...inputProps}
192194
/>
193195
) : (
194196
<TaroInput
@@ -208,6 +210,7 @@ export const SearchBar: FunctionComponent<
208210
onBlur={handleBlur}
209211
onClick={onInputClick}
210212
onConfirm={onConfirm}
213+
{...inputProps}
211214
/>
212215
)}
213216
</>

src/packages/searchbar/searchbar.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const SearchBar: FunctionComponent<
5858
leftIn,
5959
rightIn,
6060
tag,
61+
inputProps,
6162
onChange,
6263
onFocus,
6364
onBlur,
@@ -186,6 +187,7 @@ export const SearchBar: FunctionComponent<
186187
onFocus={handleFocus}
187188
onBlur={handleBlur}
188189
onClick={handleInputClick}
190+
{...inputProps}
189191
/>
190192
)
191193
}

0 commit comments

Comments
 (0)