arco-design-vue icon indicating copy to clipboard operation
arco-design-vue copied to clipboard

自动补全 AutoComplete 与 选择器 Select 可否像 输入框 Input 一样提供focus和blur method

Open selegiline opened this issue 3 years ago • 1 comments

Basic Info

What are the similar cases of this feature

同上

What problem does this feature solve?

很多场景有这个需要,如通过快捷键控制组件的focus,blur

selegiline avatar Oct 15 '22 08:10 selegiline

several workarounds before the feature release for others who got the same situation

  1. refOfAutoComplete.value.$.subTree.children.default()[0].props.ref.value.focus()
  2. document.querySelector('input')!.focus()
  3. refOfAutoComplete.value.$el.nextElementSibling.firstElementChild.focus()

selegiline avatar Oct 15 '22 16:10 selegiline

@selegiline 我同样的需求,用原生js实现的,自动补全这个组件很难改动了。

yymjku18 avatar Oct 25 '22 08:10 yymjku18

🫵 欢迎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();
    },
  },

可以先试一下这样是否可行。

hehehai avatar Oct 29 '22 12:10 hehehai