react-search-input icon indicating copy to clipboard operation
react-search-input copied to clipboard

Custom Input

Open FDiskas opened this issue 7 years ago • 2 comments

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

FDiskas avatar Aug 31 '17 15:08 FDiskas

:saxophone: 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;

FDiskas avatar Aug 31 '17 15:08 FDiskas

Hi. A possible solution here: #144

arojunior avatar Jun 23 '20 12:06 arojunior