Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

setFocus() in searchbar ionic4

async function focusElement(ref) {
  if (ref) {
    const el = await ref.getInputElement();
    el.focus();
  } else {
    console.log("focusElement got no ref");
  }
}

// Component:

function SomeComponent() {
const someRef = React.useRef()

return (
<button onClick={ () => {
    focusElement(someRef.current)
  }
>
   focus
</button>
<IonInput ref={someRef} />
)

}
Source by forum.ionicframework.com #
 
PREVIOUS NEXT
Tagged: #searchbar
ADD COMMENT
Topic
Name
2+6 =