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

No way to create tags on mobile #46

Open
ibrahimfarooq17 opened this issue Mar 9, 2023 · 2 comments
Open

No way to create tags on mobile #46

ibrahimfarooq17 opened this issue Mar 9, 2023 · 2 comments

Comments

@ibrahimfarooq17
Copy link

The component doesn't allow any way to create tags using a mobile browser. I tried adding different separators as well, still doesn't work.
Tested on Chrome.

@mo7medhasan
Copy link

to create tags on mobile

you must add button

codesandbox

export default function App() {
  const [selected, setSelected] = useState(["papaya"]);
  const handleButtonClick = () => {
    const InputElement = document.querySelector(`#id .rti--input`);
    if (InputElement) {
      const value = InputElement.value;
      if (!selected.includes(value) && value !== "") {
        setSelected([...selected, value]);
        InputElement.value = "";
      }
    }
  };
  return (
    <div>
      <h1>Add Fruits</h1>

      <pre>{JSON.stringify(selected)}</pre>
      <div id={"id"}>
        <TagsInput value={selected} onChange={setSelected} />

        <button
          type="button"
          onClick={handleButtonClick}
          className="px-6 py-2 text-white bg-primary rounded-md"
        >
          add tage
        </button>
      </div>
 
    </div>
  );
}

@ComradePashka
Copy link

seems you also can simply add same logic to onBlur handler:

            onBlur={(e) => {
                const InputElement = document.querySelector(`[name=${name}]`);
                if (InputElement) {
                    const newValue = InputElement.value;
                    if (!value.includes(newValue) && newValue !== "") {
                        setValue([...value, newValue]);
                        InputElement.value = "";
                    }
                }
            }}

in this case you must pass name to TagInput, but then you don't need extra div-wrapper around TagInput and can simplify selector to find element by name attribute.
this is working in Chrome dev-console with device mode toggled, not yet tested on real mobiles.

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

No branches or pull requests

3 participants