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

[docs][base-ui] Improve Select's country select demo #38983

Merged
merged 2 commits into from
Oct 4, 2023

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Sep 14, 2023

A quick iteration on #38796 to polish the demo. This feels much clearer for me when reading.

Before: https://master--material-ui.netlify.app/base-ui/react-select/#selected-value-appearance
Preview: https://deploy-preview-38983--material-ui.netlify.app/base-ui/react-select/#selected-value-appearance


A side note, I have tried to make this

diff --git a/docs/data/base/components/select/UnstyledSelectRichOptions.tsx b/docs/data/base/components/select/UnstyledSelectRichOptions.tsx
index 1144795569..b5d901cbc0 100644
--- a/docs/data/base/components/select/UnstyledSelectRichOptions.tsx
+++ b/docs/data/base/components/select/UnstyledSelectRichOptions.tsx
@@ -7,6 +7,7 @@ import { Popper } from '@mui/base/Popper';
 export default function UnstyledSelectRichOptions() {
   return (
     <CustomSelect placeholder="Select country…">
+      <StyledOption value={undefined} label="">None</StyledOption>
       {countries.map((country) => (
         <StyledOption key={country.code} value={country.code} label={country.label}>
           <img

work to reproduce https://mui.com/material-ui/react-select/#filled-and-standard-variants but it didn't show the placeholder. Should we expect it to?

Screen.Recording.2023-09-14.at.20.33.19.mov

@oliviertassinari oliviertassinari added component: select This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base labels Sep 14, 2023
@oliviertassinari oliviertassinari changed the title [docs] Fix Base UI elevation conflict [docs] Improve Base UI country select demo Sep 14, 2023
@mui-bot
Copy link

mui-bot commented Sep 14, 2023

Netlify deploy preview

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 0352e38

@oliviertassinari oliviertassinari force-pushed the base-menu-country branch 2 times, most recently from 728e2f0 to a255ca0 Compare September 14, 2023 20:00
@danilo-leal danilo-leal changed the title [docs] Improve Base UI country select demo [docs][base-ui] Improve Select's country select demo Sep 14, 2023
@danilo-leal danilo-leal added the docs Improvements or additions to the documentation label Sep 14, 2023
@mj12albert
Copy link
Member

mj12albert commented Sep 19, 2023

A side note, I have tried to make this work to reproduce https://mui.com/material-ui/react-select/#filled-and-standard-variants but it didn't show the placeholder. Should we expect it to?

@oliviertassinari It's because label is "" and not null/undefined, so it didn't fall back to the placeholder.
When using renderValue it works, though TS complains about option.value being undefined (not sure if it can be worked around):

diff --git a/docs/data/base/components/select/UnstyledSelectRichOptions.tsx b/docs/data/base/components/select/UnstyledSelectRichOptions.tsx
index cd73f9736d..945d2c73cc 100644
--- a/docs/data/base/components/select/UnstyledSelectRichOptions.tsx
+++ b/docs/data/base/components/select/UnstyledSelectRichOptions.tsx
@@ -6,7 +6,17 @@ import { Popper } from '@mui/base';
 
 export default function UnstyledSelectRichOptions() {
   return (
-    <CustomSelect placeholder="Select country…">
+    <CustomSelect
+      renderValue={(option) => {
+        if (option == null || option.value === null || option.value === undefined) {
+          return 'Select country…';
+        }
+        return `${option.label} (${option.value})`;
+      }}
+    >
+      <StyledOption key="none" value={undefined} label="">
+        None
+      </StyledOption>
       {countries.map((c) => (
         <StyledOption key={c.code} value={c.code} label={c.label}>
           <img

Something else I noticed is that custom props (e.g. phone) passed to the Option component aren't passed to the option arg in renderValue.

A fix could be:

  1. If the options param is provided, we can spread everything into the Map here
  2. If there is no options param, we could forward external props from useOption to useCompoundItem here

Copy link
Member

@mj12albert mj12albert left a comment

Choose a reason for hiding this comment

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

Looks good 🙆‍♂️

@michaldudak michaldudak merged commit 039ec70 into mui:master Oct 4, 2023
20 checks passed
mnajdova pushed a commit to mnajdova/material-ui that referenced this pull request Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: select This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation package: base-ui Specific to @mui/base
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants