Skip to content

Commit

Permalink
feat(Search): add blur method
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Nov 21, 2020
1 parent 2833bc0 commit d26282e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/search/README.md
Expand Up @@ -148,6 +148,7 @@ Use [ref](https://v3.vuejs.org/guide/component-template-refs.html) to get Search
| Name | Description | Attribute | Return value |
| ----- | ------------------- | --------- | ------------ |
| focus | Trigger input focus | - | - |
| blur | Trigger input blur | - | - |

### Slots

Expand Down
1 change: 1 addition & 0 deletions src/search/README.zh-CN.md
Expand Up @@ -164,6 +164,7 @@ export default {
| 方法名 | 说明 | 参数 | 返回值 |
| ------ | -------------- | ---- | ------ |
| focus | 获取输入框焦点 | - | - |
| blur | 取消输入框焦点 | - | - |

### Slots

Expand Down
8 changes: 7 additions & 1 deletion src/search/index.js
Expand Up @@ -88,6 +88,12 @@ export default createComponent({
}
};

const blur = () => {
if (filedRef.value) {
filedRef.value.blur();
}
};

const fieldPropNames = [
'leftIcon',
'rightIcon',
Expand Down Expand Up @@ -116,7 +122,7 @@ export default createComponent({
);
};

useExpose({ focus });
useExpose({ focus, blur });

return () => (
<div
Expand Down
2 changes: 2 additions & 0 deletions types/search.d.ts
Expand Up @@ -2,4 +2,6 @@ import { VanComponent } from './component';

export class Search extends VanComponent {
focus(): void;

blur(): void;
}

0 comments on commit d26282e

Please sign in to comment.