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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Select] Style is broken when adding a className in the SelectDisplayProps #23201

Closed
2 tasks done
Newpoki opened this issue Oct 21, 2020 · 3 comments 路 Fixed by #23211
Closed
2 tasks done

[Select] Style is broken when adding a className in the SelectDisplayProps #23201

Newpoki opened this issue Oct 21, 2020 · 3 comments 路 Fixed by #23211
Assignees
Labels
bug 馃悰 Something doesn't work component: select This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process.

Comments

@Newpoki
Copy link

Newpoki commented Oct 21, 2020

Adding a className in the SelectDisplayProps actually overides its existing classNames

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

I have a component. When I want to give a className to the div that display the selected value of the Select, instead of adding the className to the others like every material ui component, it overrides them. I have a <Select /> component, when I add a className in SelectDisplayProps, it overirdes the existing classNames of the component that display the selected value in the .

Expected Behavior 馃

It should not overrides the existing classNames but be added to them.

Steps to Reproduce 馃暪

Here you can find a sandbox to see the bug: https://codesandbox.io/s/material-ui-issue-forked-oi0vd

Steps:

  1. You're on the sandbox. There is actually an object in the SelectDisplayProps:
SelectDisplayProps={{
    className: classes.selectDisplay
  }}
  1. When clicking on the Button under the input, it will change the SelectDisplayProps to undefined, as if you didn't specified one.
  2. You can see by inspecting the DOM that when there is no SelectDisplayProps, there is the material UI default class. But when the SelectDisplayProps is specified, the className disappear

Context 馃敠

I want to overrides the style of the element that display the select value. The problem exist even if i totally change the style i'm trying to give, so I don't think it's related.

Your Environment 馃寧

Tech Version
Material-UI v4.11.0
React 16.13.1
Browser Chrome - Version 86.0.4240.75 (Official Build) (64-bit)
TypeScript 3.9.5
@Newpoki Newpoki added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 21, 2020
@oliviertassinari oliviertassinari added bug 馃悰 Something doesn't work component: select This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 22, 2020
@oliviertassinari oliviertassinari changed the title Select style is broken when adding a className in the SelectDisplayProps [Select] Style is broken when adding a className in the SelectDisplayProps Oct 22, 2020
@oliviertassinari
Copy link
Member

@Newpoki Thanks for the report, I can confirm the issue. What do you think about this fix?

diff --git a/packages/material-ui/src/Select/SelectInput.js b/packages/material-ui/src/Select/SelectInput.js
index eb58ecd1b3..2098d0f3b8 100644
--- a/packages/material-ui/src/Select/SelectInput.js
+++ b/packages/material-ui/src/Select/SelectInput.js
@@ -353,16 +353,6 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
   return (
     <React.Fragment>
       <div
-        className={clsx(
-          classes.root, // TODO v5: merge root and select
-          classes.select,
-          classes.selectMenu,
-          classes[variant],
-          {
-            [classes.disabled]: disabled,
-          },
-          className,
-        )}
         ref={setDisplayNode}
         tabIndex={tabIndex}
         role="button"
@@ -376,6 +366,17 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
         onBlur={handleBlur}
         onFocus={onFocus}
         {...SelectDisplayProps}
+        className={clsx(
+          classes.root, // TODO v5: merge root and select
+          classes.select,
+          classes.selectMenu,
+          classes[variant],
+          {
+            [classes.disabled]: disabled,
+          },
+          className,
+          SelectDisplayProps.className
+        )}
         // The id is required for proper a11y
         id={buttonId}
       >

Do you want to work on a pull-request? :)

@reedanders
Copy link
Contributor

I'd like to give it a try. Can you assign it to me?

@Newpoki
Copy link
Author

Newpoki commented Oct 22, 2020

Hello,
Sorry for the late reply, I was at my job 馃槄

Glad It was a real issue and not from my mind, and that it's gonna be fixed :D

Thanks @reedanders for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 馃悰 Something doesn't work component: select This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants