How to focus on component

Fairy

I am using 'keen-ui' library in my project. Here is special component for select item. I want to handle event from another component and set focus on this, but I don't know how to.

Another components, that have inside <input/> tag can be focused like this.$refs[component name].$el.children[0].children[1].focus, where children[0].children[1] is <input/> element. This is ugly, but if the component doesn't contain input tag, we can not do even this.

Roy J

Examining the widgets, I see that they contain a div with tabindex="0", which means they can receive focus.

If you have a ref on the component, you should be able to do something like

const focusableEl = this.$refs.uiselect.querySelector('[tabindex="0"]');
focusableEl.dispatchEvent(new Event('focus'));

and the widget will light up. I actually did that from the console to test it out. Interestingly, blur did not work for me.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to focus certain component

How to focus input on a child component from parent?

How to call minimize() and focus() in a React component?

How to detect when focus is gained in a TextEdit component

How to focus an input field that is in another component?

How to remove focus from one magicsuggest component and set focus on second magicsuggest component

React: How to I get a React component button to lose focus?

How to manage focus on multiple inputs in grandchild component in React/Typescript

How can I focus on an element within an imported React component?

How can I test the focus of a text field in a Vue component?

How to enable li focus in Angular while reusing a nav component?

How to enable focus on input element inside mat-select component?

How to focus a input field, which is located in a child component

how to set focus for AutoComplete component from PrimeNG library in Angular

How to focus the next field of input, in react-native component

How to focus deep nested input from root component in Angular 5?

How can I focus on a react-select component at will?

how to display different values on focus and on blur in autocomplete component

How can I focus a Search component programmatically in Semantic UI React?

How to focus on a specific input text after the component is rendered?

how blur or focus vuejs component based on a vuex state

How to use $refs in vue child component to shift focus?

How to change focus to another component when Enter key is pressed

How to set focus on a button when react component renders?

How to focus on input field loaded from component in Svelte?

React: How to capture focus when a focused child component unmounts

Set Focus for component in VueJS

Set component focus with RTTI

To focus on a component containing an input