sickdyd / react-search-autocomplete

A search box that filters the provided array of objects
https://sickdyd.github.io/react-search-autocomplete
MIT License
218 stars 82 forks source link

Custom formatResult, is it possible? #60

Open Radwisatso opened 2 years ago

Radwisatso commented 2 years ago

Hi dev, I'm still trying to figure out how to make a custom formatResult with your library. I've attached the example below. Please let me know if it's possible to do

Thanks!

image

This is the only thing that I can do right now (pardon me for the bad quality) 3Fm12mQcoE

Radwisatso commented 2 years ago

@sickdyd

gofri commented 2 years ago

It doesn't seem to be ready for a header. The class names are auto-generated, so it makes it a bit tricky to hack it with CSS too. Relevant code:

        <div className="wrapper">
          <SearchInput
            searchString={searchString}
            setSearchString={handleSetSearchString}
            autoFocus={autoFocus}
            onBlur={() => setResults([])}
            onFocus={onFocus}
            onClear={onClear}
            placeholder={placeholder}
            showIcon={showIcon}
            showClear={showClear}
            setHighlightedItem={handleSetHighligthedItem}
          />
          <Results
            results={results}
            onClick={handleOnClick}
            setSearchString={setSearchString}
            showIcon={showIcon}
            maxResults={maxResul
            resultStringKeyName={resultStringKeyName}
            formatResult={formatResult}
            highlightedItem={highlightedItem}
            setHighlightedItem={handleSetHighligthedItem}
          /> 
        </div>
      </StyledReactSearchAutocomplete>

One hack that I think might work after all - place the search component inside a div with a special class name, e.g. myclassname, then use CSS to edit the elements with the 'line' class that are descendants of myclassname