Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element focus function not focus correctly #572

Open
Bulldozer323 opened this issue Nov 7, 2021 · 2 comments
Open

Element focus function not focus correctly #572

Bulldozer323 opened this issue Nov 7, 2021 · 2 comments

Comments

@Bulldozer323
Copy link

Bulldozer323 commented Nov 7, 2021

Hello, on mobile device (ios 15.0.2) focus function on element not show keyboard.

Package version – react-imask 6.2.2

To Reproduce:
Open from mobile device – https://codesandbox.io/s/little-thunder-rwkkt?file=/src/App.js and refresh sandbox window if needed, input has active but keyboard not showing.

Code:

import { IMaskInput } from "react-imask";
import { useEffect, useRef } from "react";

export default function App() {
  const inputRef = useRef(null);

  useEffect(() => {
    if (inputRef.current && inputRef.current.element) {
      inputRef.current.element.focus();
    }
  }, [inputRef]);

  return (
    <div className="App">
      <IMaskInput unmask value="123" mask={Number} ref={inputRef} />
    </div>
  );
}

@AdrianoSilvaACIN
Copy link

AdrianoSilvaACIN commented Mar 7, 2023

Hello, I'm having the same problem.

If you focus the input with element.focus() it wont behave as it should but if you click it its fine.

@cutterbl
Copy link

You'll have to try this to be sure, but looking at the latest documentation IMaskInput now can now take a ref and an inputRef. The inputRef is the ref to the inner input itself, whereas ref is a ref to the mask itself. Also, when that ref is applied the inputRef.current is the reference to the actual element, so your code would become:

import { IMaskInput } from "react-imask";
import { useEffect, useRef } from "react";

export default function App() {
  const inputRef = useRef(null);

  useEffect(() => {
      inputRef?.current?.focus();
  }, [inputRef]);

  return (
    <div className="App">
      <IMaskInput unmask value="123" mask={Number} inputRef={inputRef} />
    </div>
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants