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

Tab acts unexpectedly #255

Open
stavlocker opened this issue Oct 10, 2018 · 1 comment
Open

Tab acts unexpectedly #255

stavlocker opened this issue Oct 10, 2018 · 1 comment

Comments

@stavlocker
Copy link

stavlocker commented Oct 10, 2018

Hi. There are problems with how tab behaves:

  • Tab should have it's default behaviour just like it does with normal inputs. The caret navigation shouldn't be mixed with the tab navigation. At least there should be an option to control this. Currently you can't even tab forward as react-typeahead intentionally does for some odd reason. A fix to this would be Optionally propagate keydown events #140 but it was never merged due to there not being documentation & tests (which isn't that big of a deal).

  • Tab for some reason selects the first option available. But, for example if my options are "foo 1", "foo 2", and "foo 3", and I type "foo 2" it will select "foo 1" which for some reason shows as the first option. Also, for some reason custom options are ignored even when the option is on.

This is terrible UX and makes it really hard to use.

P.S: If this project is abandoned, please just say so in the README.md to save people a lot of time.

@stavlocker stavlocker changed the title Combobox behaviour / add new option option Allow custom values option doesn't work correctly Oct 10, 2018
@stavlocker stavlocker changed the title Allow custom values option doesn't work correctly Cannot tab through typeahead input Oct 10, 2018
@stavlocker
Copy link
Author

stavlocker commented Oct 11, 2018

Here's my temporary solution, a.k.a the hackiest hack I ever hacked together:

class TypeaheadHack extends React.Component {
    componentDidMount = () => {
        ReactDOM.findDOMNode(this).addEventListener("keydown", e => {
            if(((e.key && e.key == "Tab") || e.keyCode == 9) && !e.shiftKey) {
                var current = e.target;
                var all = document.querySelectorAll('input, button, area, object, select, textarea');//no anchors!

                var currentIndex;
                for(var i = 0; i < all.length; i++){
                    if(current.isEqualNode(all[i])){
                        currentIndex = i;
                        break;
                    }
                }

                setTimeout(() => {
                    all[currentIndex + 1].focus();
                }, 50);
            }
        }, true);
    }

    render () {
        return (
            <Typeahead {...this.props}/>
        );
    }
}

What I'm doing here is hackily wrapping the Typeahead in another component which I can access it's ReactDOM.findDOMNode (which is hacky and shouldn't really be used), so I can forcefully register my keyDown event (which typeahead doesn't let me to do) and simulate a tab click (again, hacky).

Please just merge the PR that fixes this!

@stavlocker stavlocker changed the title Cannot tab through typeahead input Tab acts unexpectedly Oct 11, 2018
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

1 participant