Skip to content

Commit

Permalink
feat(SearchBar): support autoFocus
Browse files Browse the repository at this point in the history
  • Loading branch information
Layouwen committed Aug 12, 2024
1 parent 2bb5af4 commit 5b9b21c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
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 @@ -132,6 +137,7 @@ export const SearchBar = forwardRef<SearchBarRef, SearchBarProps>(
})}
value={value}
onChange={setValue}
autoFocus={mergedProps.autoFocus}
maxLength={mergedProps.maxLength}
placeholder={mergedProps.placeholder}
clearable={mergedProps.clearable}
Expand Down

0 comments on commit 5b9b21c

Please sign in to comment.