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

Focus removed from input elements #87

Open
Energiz3r opened this issue Jan 8, 2024 · 1 comment
Open

Focus removed from input elements #87

Energiz3r opened this issue Jan 8, 2024 · 1 comment

Comments

@Energiz3r
Copy link

Energiz3r commented Jan 8, 2024

I'm using Tailwind-css on react, and can replicate with this code:

import React from "react";
import ScrollContainer from "react-indiana-drag-scroll";

const Component = (args: any) => {
  return (
    <ScrollContainer className="scroll-container flex" horizontal>
      <div className="bg-red-300 p-24">Stuff</div>
      <div className="bg-green-300 p-24">Things</div>
      <div className="bg-red-300 p-24">
        <input type="text" />
      </div>
      <div className="bg-green-300 p-24">Things</div>
      <div className="bg-red-300 p-24">Stuff</div>
      <div className="bg-green-300 p-24">Things</div>
    </ScrollContainer>
  );
};

In situations where the container is wider than the parent and scrolling is enabled, I cannot select the input - it's like the click is ignored. If the container doesn't overflow, and therefore there is no scrolling, it works as expected. The input's onClick event does fire however, and this hacky workaround fixes the issue:

<input onClick={(e) => e.target.focus()} />

So it seems something is causing the input to un-focus after the ScrollContainer is clicked.

Cheers

@Norserium
Copy link
Owner

@Energiz3r, what's the version do you use? Try to ignore input elements.

import React from "react";
import ScrollContainer from "react-indiana-drag-scroll";

const Component = (args: any) => {
  return (
    <ScrollContainer className="scroll-container flex" ignoreElements="input" horizontal>
      <div className="bg-red-300 p-24">Stuff</div>
      <div className="bg-green-300 p-24">Things</div>
      <div className="bg-red-300 p-24">
        <input type="text" />
      </div>
      <div className="bg-green-300 p-24">Things</div>
      <div className="bg-red-300 p-24">Stuff</div>
      <div className="bg-green-300 p-24">Things</div>
    </ScrollContainer>
  );
};

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

2 participants