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

How to use props.customListComponent? #155

Open
chrispeterson3 opened this issue Jan 4, 2016 · 3 comments
Open

How to use props.customListComponent? #155

chrispeterson3 opened this issue Jan 4, 2016 · 3 comments
Labels

Comments

@chrispeterson3
Copy link

It seems that the default functionality breaks when you use props.customListComponent. Is there any custom configuration that has to be done in order to get this to work?

For instance, when you type a value in the input and press the TAB key, there is an error, arrow keys don't work, and you can't click on a selection.

screen shot 2016-01-04 at 2 22 33 pm

@chrispeterson3 chrispeterson3 changed the title How to use props.customListComponent How to use props.customListComponent? Jan 4, 2016
@fmoo fmoo added the question label Mar 25, 2016
@eddts
Copy link

eddts commented Apr 8, 2016

I'm still sort of struggling through this as there's not a lot of documentation about it. Specifically getting the arrow keys to work and suppress the tab key event which currently submits the form!

In the most basic implementation, though, you just have to ensure that the items that list out your options have an onClick binding which calls the onOptionSelected function which is passed through, and passes it the option that has been clicked on.

i.e: onClick={this.props.onOptionSelected.bind(null, option)}

Chuck that on each <li> or whatever you're using to list them and you should be good to go.

@burmester
Copy link

This is how i use it:

< Typeahead options={schooltype.list} maxVisible={5} customListComponent={TypeaheadItem} filterOption={filterOption} displayOption={this.handleItemClick} placeholder={placeholder} / >

var TypeaheadItem = React.createClass({
    handleOnClick: function (e) {
        this.props.displayOption(e);
    },
    render: function () {
        var list = _.map(this.props.options, function (item) {
            return (
                <button key={item.id} type="label" className="tag tag-curriculum"
                        id={item.id} title={item.title} onClick={this.handleOnClick}>
                    {item.abbr}
                </button>
            )
        }.bind(this));

        return (
            <div className="dropdown-background">
                {list}
            </div>
        );
    }
});`

@marlenebowles
Copy link

I'm also having trouble getting accessibility to work when using CustomListComponent as well. It looks like the onKeyDown doesn't read any arrow up or down events. Has anyone been able to replicate the accessibility?

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

No branches or pull requests

5 participants