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

Custom Input #131

Open
FDiskas opened this issue Aug 31, 2017 · 2 comments
Open

Custom Input #131

FDiskas opened this issue Aug 31, 2017 · 2 comments

Comments

@FDiskas
Copy link

FDiskas commented Aug 31, 2017

Hi, thanks for the plugin.
How I can add material-ui element against simple input?

@FDiskas
Copy link
Author

FDiskas commented Aug 31, 2017

🎷 I managed like so

import React, { Component, PropTypes } from 'react';
import SearchInput, { createFilter } from 'react-search-input';
import { TextField } from 'material-ui';

const KEYS_TO_FILTERS = ['name', 'label'];

class FacetList extends Component {
    constructor(props) {
        super(props);

        this.state = {
            searchTerm: props.searchTerm,
        };


        this.searchUpdated = this.searchUpdated.bind(this);
    }

    searchUpdated(event) {
        this.setState({ searchTerm: event.target.value });
    }

    render() {
        const filteredItems = this.props.items.filter(createFilter(this.state.searchTerm, KEYS_TO_FILTERS));

        return (
            <div>
                <TextField hintText="Search..." {...SearchInput.getDefaultProps()} onChange={this.searchUpdated} />
                {
                    filteredItems
                        .map((item) => {
                            return (
                                <p key={item.id}>
                                    {item.label}
                                </p>
                            );
                        })
                }
            </div>
        );
    }
}

FacetList.propTypes = {
    items: PropTypes.array.isRequired,
    searchTerm: PropTypes.string,
};
FacetList.defaultProps = {
    searchTerm: '',
};

export default FacetList;

danbovey added a commit to onlicar/react-search-input that referenced this issue Oct 5, 2017
@arojunior
Copy link
Contributor

Hi. A possible solution here: #144

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