mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.51k stars 32.19k forks source link

[Select][material-next] Add Select component #38972

Open mj12albert opened 1 year ago

mj12albert commented 1 year ago

Part of https://github.com/mui/material-ui/issues/29345

Material You specs: https://m3.material.io/components/menus/specs

Migration Guide checklist

Other features & related tasks

mj12albert commented 1 year ago

Some open questions I have on my mind:

1. New Option component

v5 uses the same MenuItem component for Select options and items in Menu, Base has a new useOption that is distinct from useMenu so we could introduce a new Option component for material-next (this would be it's own separate issue)

2. Do not rely on Menu, introduce Listbox component?

v5 uses the Menu component for the listbox, if v6 were to use useSelect it wouldn't make sense as Base's useMenu has it's own prop getters with a different context. This new component can be completely internal, the important part is detaching from the v5 Menu/MenuList/List structure

Maybe we just need to share the styles between Menu and the select Listbox since they should be identical in terms of the MD3 specs

mj12albert commented 1 year ago

I think the v6 Select will still depend on InputBase (and therefore also depends on FormControl) for the select trigger, since internally it uses OutlinedInput (or filled) to share styles with text fields:

// heavily simplified version of what https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Select/Select.js
// would look like in v6
function Select() {
  return (
    <OutlinedInput // it's essentially `InputBase` with a layer of styles
      slots={{
        input: SelectInput, // most of the refactoring with useSelect would happen here
      }}
      slotProps={{
        input: {
          children,
          multiple,
          // more props
        },
      }}
    />
  );
}
DiegoAndai commented 1 year ago

@mj12albert I agree with both your points 🙌🏼 This would mean trying to get as close as possible to Joy's implementation (which uses Option and ListBox components) without breaking changes 🚀