mui / mui/material-ui

[autocomplete][JoyUI] Autocomplete bug with searching title but displaying value

Open
#44,257 1 comment 0 reactions 1 assignee View on GitHub

@siriwatknp is already working on this.

Since Oct 30, 2024.

on hold package: joy-ui scope: autocomplete
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Possible related issue

https://github.com/mui/material-ui/issues/38360

Search keywords

autocomplete

Latest version
  • I have tested the latest version
Steps to reproduce

Link to live example: (required)
https://codesandbox.io/p/sandbox/c8v7xf

Steps:

  1. Create list of options using format
    countryCode = [
    { name: 'Afghanistan', code: 'AF', phoneCode: '+93' },
    { name: 'Albania', code: 'AL', phoneCode: '+355' },
    { name: 'Algeria', code: 'DZ', phoneCode: '+213' },
    ....
    ....
  2. Create autocomplete and set attribute getOptionLabel={(option) => option.phoneCode}
  3. Type in a country name e.g "France" , the options given show a bunch of countries + the filtered search country (e.g France) at the end of the list

I have noted there might be a related issue where there might be wrong search results when there are lots of data - according to issue https://github.com/mui/material-ui/issues/38360

Current behavior

Autocomplete currently cannot accurately search from list of items when I want to show value selected , but search by label/title/name.

Im using autocomplete for searching for country code , user should be able to search by typing country name , but when selected , the country phone code will be displayed.

If i change the getOptionLabel
from
getOptionLabel={(option) => option.phoneCode}
to
getOptionLabel={(option) => option.name}//name is country name / label/title , autocomplete will work ,but I cannot achieve what I want to achieve with autocomplete

Expected behavior

Autocomplete can correctly search from list of items and when selected , the value ( which is different from the label/title/name) will be shown in the option label instead

Context
Your environment
npx @mui/envinfo

Tested on Chrome Version 129.0.6668.101 (Official Build) (64-bit)

  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.
    System:
    OS: Windows 11 10.0.22631
  Binaries:
    Node: 20.11.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
    pnpm: Not Found
  Browsers:
    Chrome: Not Found
    Edge: Chromium (128.0.2739.79)
  npmPackages:
    @emotion/react: ^11.11.4 => 11.11.4
    @emotion/styled: ^11.11.5 => 11.11.5
    @mui/base:  5.0.0-beta.42
    @mui/core-downloads-tracker:  6.0.0-dev.240424162023-9968b4889d
    @mui/icons-material: ^5.15.20 => 5.15.20
    @mui/joy: ^5.0.0-beta.36 => 5.0.0-beta.36
    @mui/material: ^5.15.20 => 5.15.20
    @mui/private-theming:  6.0.0-dev.20240529-082515-213b5e33ab
    @mui/styled-engine:  6.0.0-dev.20240529-082515-213b5e33ab
    @mui/system:  6.0.0-dev.240424162023-9968b4889d
    @mui/types:  7.2.14
    @mui/utils:  6.0.0-dev.20240529-082515-213b5e33ab
    @mui/x-date-pickers: ^7.9.0 => 7.9.0
    @types/react: ^18.3.3 => 18.3.3
    react: ^18.3.1 => 18.3.1
    react-dom: ^18.3.1 => 18.3.1
    typescript: ^5.4.3 => 5.4.5

Search keywords: autocomplete

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.