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

Autocomplete renderGroup #33965

Closed
2 tasks done
el-j opened this issue Aug 17, 2022 · 1 comment · Fixed by #34066
Closed
2 tasks done

Autocomplete renderGroup #33965

el-j opened this issue Aug 17, 2022 · 1 comment · Fixed by #34066
Labels
component: autocomplete This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation

Comments

@el-j
Copy link

el-j commented Aug 17, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

if renderGroup is added for rendering a specific styled groupLabel
the list just returns the GroupLabels and no options anymore:

<Autocomplete
      id="requirement"
      options={allLogicProperties[alertType]}
      fullWidth
      renderInput={(params) => <TextField {...params} label={'label'} />}
      groupBy={(option) => option.type}
      renderOption={(props, option:IHostProps, { selected }) => {
          let temp:IHostProps = option
        return   <ListItem {...props} key={option.value} value={option.value}>
              {option.label}
            </ListItem>
      }}
      renderGroup={(params)=> <li>{params.group}</li>}
    />

image

Expected behavior 🤔

<Autocomplete
      id="requirement"
      options={allLogicProperties[alertType]}
      fullWidth
      renderInput={(params) => <TextField {...params} label={'label'} />}
      groupBy={(option) => option.type}
      renderOption={(props, option:IHostProps, { selected }) => {
          let temp:IHostProps = option
        return   <ListItem {...props} key={option.value} value={option.value}>
              {option.label}
            </ListItem>
      }}
      renderGroup={(params)=> <li>{params.group}</li>}
    />

image

Steps to reproduce 🕹

Steps:

  1. add autocomplete component
  2. add groupedBy
  3. add renderGroup
  4. options will be missing in the dropdown

use codesandbox from example:
https://codesandbox.io/s/fseoi6?file=/demo.tsx
add:

renderGroup={(p)=><li>{p.group}</li>}

image

Context 🔦

Finally the group.label component should be rendered with an Icon infront:
image

with something like:

renderGroup={(group)=><ListSubheader
         key={group.key}
         component={() => (
           <ListSubheader sx={{ display: "flex" }}>
            <Stack
              direction={"row"}
              spacing={2}
              alignItems={"center"}
              height={48}
            >
              <Icon iconName={group.iconName} fontSize={"small"} />
              <Body2Typo>{t(`${group.label}`)}</Body2Typo>
            </Stack>
           </ListSubheader>
)} />
}

Your environment 🌎

@mui/material 5.10.1

@el-j el-j added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Aug 17, 2022
@oliviertassinari oliviertassinari added the component: autocomplete This is the name of the generic UI component, not the React module! label Aug 17, 2022
@michaldudak michaldudak self-assigned this Aug 22, 2022
@michaldudak
Copy link
Member

When providing a custom renderGroup, you are responsible for rendering the group's children.
For example:

renderGroup={(params) => 
  (<li>{params.group}<ul>{params.children}</ul></li>)
}

The docs don't state this clearly. I'll make sure they are updated.

@michaldudak michaldudak added docs Improvements or additions to the documentation and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Aug 25, 2022
@michaldudak michaldudak removed their assignment Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants