Skip to content
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

feat(SearchBar): support autoFocus #6714

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/search-bar/demos/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default () => {
</DemoBlock>

<DemoBlock title='获取焦点后显示取消按钮'>
<SearchBar placeholder='请输入内容' showCancelButton />
<SearchBar placeholder='请输入内容' showCancelButton autoFocus />
</DemoBlock>

<DemoBlock title='取消按钮长显'>
Expand Down
2 changes: 1 addition & 1 deletion src/components/search-bar/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Narrow down the information pool to get targeted information quickly and easily.
| showCancelButton | Whether to display the cancel button on the right side of the search input | `boolean \| ((focus: boolean, value: string) => boolean)` | `false` |
| value | Input value | `string` | - |

In addition, the following native attributes are supported: `onCompositionStart` `onCompositionEnd`
In addition, the following native attributes are supported: `onCompositionStart` `onCompositionEnd` `autoFocus`

### CSS Variables

Expand Down
2 changes: 1 addition & 1 deletion src/components/search-bar/index.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
| showCancelButton | 是否在搜索框右侧显示取消按钮 | `boolean \| ((focus: boolean, value: string) => boolean)` | `false` |
| value | 输入值 | `string` | - |

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

### CSS 变量

Expand Down
8 changes: 7 additions & 1 deletion src/components/search-bar/search-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ export type SearchBarRef = InputRef

export type SearchBarProps = Pick<
InputProps,
'onFocus' | 'onBlur' | 'onClear' | 'onCompositionStart' | 'onCompositionEnd'
| 'onFocus'
| 'onBlur'
| 'onClear'
| 'onCompositionStart'
| 'onCompositionEnd'
| 'autoFocus'
> & {
value?: string
defaultValue?: string
Expand Down Expand Up @@ -133,6 +138,7 @@ export const SearchBar = forwardRef<SearchBarRef, SearchBarProps>(
value={value}
onChange={setValue}
maxLength={mergedProps.maxLength}
autoFocus={mergedProps.autoFocus}
placeholder={mergedProps.placeholder}
clearable={mergedProps.clearable}
onlyShowClearWhenFocus={mergedProps.onlyShowClearWhenFocus}
Expand Down
Loading