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

[input] Fix border color resolution on mobile #43879

Merged
merged 4 commits into from
Oct 5, 2024

Conversation

wojtek35
Copy link
Contributor

@wojtek35 wojtek35 commented Sep 25, 2024

Summary

This pull request addresses the issue with the border color of the OutlinedInput component on mobile devices. Previously, the focus state did not display the correct color due to a lack of specificity in styles for touch devices.

Changes Made

  • Updated the focus styles to ensure that the border color appears correctly on mobile devices.
  • Added media queries to handle hover and pointer events appropriately for different device capabilities.

Related Issues

Fix #43797

@zannager zannager added the component: input This is the name of the generic UI component, not the React module! label Sep 25, 2024
Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

The proposed changes while they work, they are changing the specificity and adding additional complexity. We can fix the issue simply by moving the '@media (hover: none)` style in the same position where it was in v5, see the code

This diff should be sufficient:

index e96b4ec567..af2715d017 100644
--- a/packages/mui-material/src/OutlinedInput/OutlinedInput.js
+++ b/packages/mui-material/src/OutlinedInput/OutlinedInput.js
@@ -51,6 +51,14 @@ const OutlinedInputRoot = styled(InputBaseRoot, {
       [`&:hover .${outlinedInputClasses.notchedOutline}`]: {
         borderColor: (theme.vars || theme).palette.text.primary,
       },
+      // Reset on touch devices, it doesn't add specificity
+      '@media (hover: none)': {
+        [`&:hover .${outlinedInputClasses.notchedOutline}`]: {
+          borderColor: theme.vars
+            ? `rgba(${theme.vars.palette.common.onBackgroundChannel} / 0.23)`
+            : borderColor,
+        },
+      },
       [`&.${outlinedInputClasses.focused} .${outlinedInputClasses.notchedOutline}`]: {
         borderWidth: 2,
       },
@@ -68,14 +76,6 @@ const OutlinedInputRoot = styled(InputBaseRoot, {
         {
           props: {}, // to overide the above style
           style: {
-            // Reset on touch devices, it doesn't add specificity
-            '@media (hover: none)': {
-              [`&:hover .${outlinedInputClasses.notchedOutline}`]: {
-                borderColor: theme.vars
-                  ? `rgba(${theme.vars.palette.common.onBackgroundChannel} / 0.23)`
-                  : borderColor,
-              },
-            },
             [`&.${outlinedInputClasses.error} .${outlinedInputClasses.notchedOutline}`]: {
               borderColor: (theme.vars || theme).palette.error.main,
             },

We never wanted the hover styles to override the focus styles, that code segment was only intended for the error and disabled states.

@mui-bot
Copy link

mui-bot commented Oct 5, 2024

Netlify deploy preview

https://deploy-preview-43879--material-ui.netlify.app/

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against a35b670

@mnajdova
Copy link
Member

mnajdova commented Oct 5, 2024

I simplified a bit the fix, thanks for the effort! :)

@mnajdova mnajdova merged commit e73c8a9 into mui:master Oct 5, 2024
19 checks passed
@oliviertassinari oliviertassinari changed the title [materual-ui][OutlinedInput] Resolve border color issue on mobile (#43797) [materual-ui][OutlinedInput] Resolve border color issue on mobile Oct 5, 2024
@oliviertassinari oliviertassinari changed the title [materual-ui][OutlinedInput] Resolve border color issue on mobile [OutlinedInput] Resolve border color issue on mobile Oct 5, 2024
@oliviertassinari oliviertassinari changed the title [OutlinedInput] Resolve border color issue on mobile [input] Fix border color resolution on mobile Oct 5, 2024
@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work regression A bug, but worse labels Oct 5, 2024
@oliviertassinari
Copy link
Member

Nice 👍

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: input This is the name of the generic UI component, not the React module! regression A bug, but worse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[OutlinedInput] No highlighted border on input on mobile
5 participants