arco-design-vue
arco-design-vue copied to clipboard
自动补全 AutoComplete 与 选择器 Select 可否像 输入框 Input 一样提供focus和blur method
- [ ] I'm sure this does not appear in the issue list of the repository
Basic Info
What are the similar cases of this feature
同上
What problem does this feature solve?
很多场景有这个需要,如通过快捷键控制组件的focus,blur
several workarounds before the feature release for others who got the same situation
- refOfAutoComplete.value.$.subTree.children.default()[0].props.ref.value.focus()
- document.querySelector('input')!.focus()
- refOfAutoComplete.value.$el.nextElementSibling.firstElementChild.focus()
@selegiline 我同样的需求,用原生js实现的,自动补全这个组件很难改动了。
🫵 欢迎PR 【贡献指南】(有任何遇到到问题可直接回复 🥰)
https://github.com/arco-design/arco-design-vue/blob/0e1e0827a50c15d5e8f4fb4cba0cc5c05fcbe286/packages/web-vue/components/auto-complete/auto-complete.tsx#L157
这里已经有 inputRef,直接开放该方法。
setup() {
return {
inputRef
};
}
methods: {
/**
* @zh 使输入框获取焦点
* @en Make the input box focus
* @public
*/
focus() {
(this.inputRef as HTMLInputElement)?.focus();
},
/**
* @zh 使输入框失去焦点
* @en Make the input box lose focus
* @public
*/
blur() {
(this.inputRef as HTMLInputElement)?.blur();
},
},
可以先试一下这样是否可行。