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

Fix Autocomplete selection display with custom Component #4367

Merged
merged 9 commits into from
Jan 31, 2020

Conversation

JulienMattiussi
Copy link
Contributor

@JulienMattiussi JulienMattiussi commented Jan 29, 2020

Closes #4281

Issue

When an autocomplete use a custom Component as optionText, The selected value can't be display in the filter TextField.

Solution

When you want to pass a custom component as optionText to an Autocomplete,
you also have to pass a text rendering function returning the filter text to be displayed for your custom component
This inputText function must return a string which can be similary to the displayed component, or totally different

const OptionRenderer = ({ record }) => (
    <span>
        {record.title}-{record.id}
    </span>
);

const inputText = record => `${record.title}-${record.id}`;

<AutocompleteInput
   matchSuggestion={(filterValue, suggestion) => true}
   optionText={<OptionRenderer />}
   inputText={inputText}
   options={{ fullWidth: true }}
/>

Preview

image

Documentation

image

image

@JulienMattiussi JulienMattiussi added the WIP Work In Progress label Jan 29, 2020
@JulienMattiussi JulienMattiussi changed the title Autocomplete custom component Fix Autocomplete selection display with custom Component Jan 31, 2020
@JulienMattiussi JulienMattiussi added RFR Ready For Review and removed WIP Work In Progress labels Jan 31, 2020
docs/Inputs.md Outdated Show resolved Hide resolved
@fzaninotto
Copy link
Member

Please target next rather than master for this one

@fzaninotto fzaninotto added this to the 3.2.0 milestone Jan 31, 2020
@fzaninotto fzaninotto changed the base branch from master to next January 31, 2020 09:57
Co-Authored-By: Gildas Garcia <1122076+djhi@users.noreply.github.com>
Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a check for the existence of an inputText prop if the optionText is a component, and throw an explicit error if it's not the case?

docs/Inputs.md Outdated Show resolved Hide resolved
docs/Inputs.md Outdated Show resolved Hide resolved
JulienMattiussi and others added 4 commits January 31, 2020 11:29
Co-Authored-By: Francois Zaninotto <francois@marmelab.com>
Co-Authored-By: Francois Zaninotto <francois@marmelab.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants