Skip to content

Commit 010a711

Browse files
author
xingyan
committed
feat(CategorySearch): 支持配置是否自动聚焦搜索框
1 parent 4615813 commit 010a711

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

packages/devui-vue/devui/category-search/src/category-search-types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ export const categorySearchProps = {
203203
appendToBody: {
204204
type: Boolean,
205205
default: true
206+
},
207+
inputAutofocus: {
208+
type: Boolean,
209+
default: true
206210
}
207211
};
208212
export type CategorySearchProps = ExtractPropTypes<typeof categorySearchProps>;

packages/devui-vue/devui/category-search/src/composables/use-category-search.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export function useCategorySearch(props: CategorySearchProps, ctx: SetupContext)
173173

174174
const onSearchKeyTagClick = () => {
175175
innerSearchKey.value = searchKeyCache;
176-
inputRef.value.focus();
176+
props.inputAutofocus && inputRef.value.focus();
177177
ctx.emit('searchKeyChange', innerSearchKey.value);
178178
};
179179

@@ -209,7 +209,7 @@ export function useCategorySearch(props: CategorySearchProps, ctx: SetupContext)
209209
}
210210
currentSelectTag.value.title = setTitle(currentSelectTag.value, currentSelectTag.value.type || '', '');
211211
inputRef.value.openMenu();
212-
inputRef.value.focus();
212+
props.inputAutofocus && inputRef.value.focus();
213213
}, DROPDOWN_ANIMATION_TIMEOUT);
214214
};
215215

@@ -482,7 +482,7 @@ export function useCategorySearch(props: CategorySearchProps, ctx: SetupContext)
482482

483483
function finishChoose() {
484484
currentSelectTag.value = undefined;
485-
inputRef.value.focus();
485+
props.inputAutofocus && inputRef.value.focus();
486486
}
487487

488488
function afterDropdownClosed() {
@@ -665,7 +665,7 @@ export function useCategorySearch(props: CategorySearchProps, ctx: SetupContext)
665665
}
666666
} else if (!isInit) {
667667
// 初始化不聚焦,避免展开下拉
668-
inputRef.value.focus();
668+
props.inputAutofocus && inputRef.value.focus();
669669
}
670670
}
671671

packages/devui-vue/docs/components/category-search/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ export default defineComponent({
372372
| extend-config | [ExtendConfig](#extendconfig) | -- | 可选,配置右侧扩展按钮功能 | [自定义扩展按钮](#自定义扩展按钮) |
373373
| tag-max-width | `number` | -- | 可选,单个过滤条件的最大宽度,超过则显示省略号,不设置则不限制 | [自定义展示模板](#自定义展示模板) |
374374
| append-to-body | `boolean` | true | 可选,下拉菜单是否 append to body | |
375+
| input-autofocus | `boolean` | true | 可选,是否允许自动聚焦搜索框,规避有滚动条场景下自动聚焦导致的位移 |
375376

376377
### CategorySearch 事件
377378

0 commit comments

Comments
 (0)