-
Notifications
You must be signed in to change notification settings - Fork 294
feat: 给 searchbar 暴露 input 更多属性 #3416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import React from 'react' | ||
| import { Scan } from '@nutui/icons-react' | ||
| import { SearchBar } from '@nutui/nutui-react' | ||
|
|
||
| const Demo = () => { | ||
| return ( | ||
| <> | ||
| <SearchBar | ||
| placeholder="使用inputProps扩展属性" | ||
| inputProps={{ | ||
| autoComplete: 'off', | ||
| autoCapitalize: 'none', | ||
| spellCheck: false, | ||
| }} | ||
| /> | ||
| <SearchBar | ||
| leftIn={<Scan />} | ||
| placeholder="自定义input类型和属性" | ||
| inputProps={{ | ||
| type: 'search', | ||
| autoComplete: 'on', | ||
| }} | ||
| /> | ||
| <SearchBar | ||
| placeholder="设置自定义属性" | ||
| inputProps={{ | ||
| 'aria-label': '搜索输入框', | ||
| }} | ||
| /> | ||
| </> | ||
| ) | ||
| } | ||
| export default Demo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import React from 'react' | ||
| import { Scan } from '@nutui/icons-react-taro' | ||
| import { SearchBar } from '@nutui/nutui-react-taro' | ||
|
|
||
| const Demo = () => { | ||
| return ( | ||
| <> | ||
| <SearchBar | ||
| placeholder="使用inputProps扩展属性" | ||
| inputProps={{ | ||
| confirmType: 'search', | ||
| password: false, | ||
| maxlength: 20, | ||
| }} | ||
| /> | ||
| <SearchBar | ||
| leftIn={<Scan />} | ||
| placeholder="自定义confirmType为search" | ||
| inputProps={{ | ||
| confirmType: 'search', | ||
| type: 'text', | ||
| }} | ||
| /> | ||
| <SearchBar | ||
| placeholder="设置maxlength为10" | ||
| inputProps={{ | ||
| maxlength: 10, | ||
| }} | ||
| /> | ||
| </> | ||
| ) | ||
| } | ||
| export default Demo | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,7 @@ export const SearchBar: FunctionComponent< | |
| leftIn, | ||
| rightIn, | ||
| tag, | ||
| inputProps, | ||
| onChange, | ||
| onFocus, | ||
| onBlur, | ||
|
|
@@ -189,6 +190,7 @@ export const SearchBar: FunctionComponent< | |
| onBlur={handleBlur} | ||
| onClick={onInputClick} | ||
| onConfirm={onConfirm} | ||
| {...inputProps} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 注意 inputProps 可能覆盖组件自身属性 当前实现中, 建议考虑以下方案之一:
📝 建议的修复方案方案1: 调整展开顺序(推荐) <TaroInput
className={inputCls}
ref={searchInputRef}
+ {...inputProps}
style={{
...style,
...{ color: `${innerTag ? 'transparent' : '#333'}` },
}}
value={value}
placeholder={placeholder || locale.placeholder}
disabled={disabled || readOnly}
maxlength={maxLength}
autoFocus={autoFocus}
onInput={handleInput}
onFocus={handleFocus}
onBlur={handleBlur}
onClick={onInputClick}
onConfirm={onConfirm}
- {...inputProps}
/>方案2: 过滤冲突属性 + const {
+ maxlength: _maxlength,
+ disabled: _disabled,
+ value: _value,
+ placeholder: _placeholder,
+ ...safeInputProps
+ } = inputProps || {}
<TaroInput
// ... 其他属性
- {...inputProps}
+ {...safeInputProps}
/>Also applies to: 213-213 |
||
| /> | ||
| ) : ( | ||
| <TaroInput | ||
|
|
@@ -208,6 +210,7 @@ export const SearchBar: FunctionComponent< | |
| onBlur={handleBlur} | ||
| onClick={onInputClick} | ||
| onConfirm={onConfirm} | ||
| {...inputProps} | ||
| /> | ||
| )} | ||
| </> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
示例中的 maxlength 属性可能导致混淆
Demo 中使用
inputProps={{ maxlength: 20 }}和maxlength: 10,但 SearchBar 组件已经提供了maxLengthprop。由于 inputProps 在最后展开(如 searchbar.taro.tsx 实现所示),这里的maxlength会覆盖组件的maxLengthprop。建议:
cursor-spacing、confirm-hold等这与 searchbar.taro.tsx 中标识的 prop 覆盖问题相关。
Also applies to: 26-28
🤖 Prompt for AI Agents