question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RFC] Should we handle dark mode scrollbar?

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

The default style of the scrollbar doesn’t play well with a dark mode. The surface is too white, it draws more attention than it needs to:

Windows Capture d’écran 2020-09-14 à 13 53 47

macOS dark

On the other hand, there are ways to work around the issue. For instance, we can use StackOverflow’s sources as a starting point. It’s the CSS they use for displaying all the code in the pages (even in light mode).

Capture d’écran 2020-09-14 à 14 06 58

A quick diff:

diff --git a/packages/material-ui/src/CssBaseline/CssBaseline.js b/packages/material-ui/src/CssBaseline/CssBaseline.js
index 72187760ba..f73b994ba1 100644
--- a/packages/material-ui/src/CssBaseline/CssBaseline.js
+++ b/packages/material-ui/src/CssBaseline/CssBaseline.js
@@ -23,6 +23,11 @@ export const body = (theme) => ({
   },
 });

+// Values coming from mac OS.
+const track = '#202022';
+const thumb = '#585859';
+const active = '#838384';
+
 export const styles = (theme) => ({
   '@global': {
     html,
@@ -32,6 +37,27 @@ export const styles = (theme) => ({
     'strong, b': {
       fontWeight: theme.typography.fontWeightBold,
     },
+    ...(theme.palette.type === 'dark' ? {
+      scrollbarColor: `${thumb} ${track}`,
+      '*::-webkit-scrollbar': {
+        backgroundColor: track,
+      },
+      '*::-webkit-scrollbar-thumb': {
+        borderRadius: 8,
+        backgroundColor: thumb,
+        minHeight: 24,
+        border: `3px solid ${track}`,
+      },
+      '*::-webkit-scrollbar-thumb:focus': {
+        backgroundColor: active,
+      },
+      '*::-webkit-scrollbar-thumb:active': {
+        backgroundColor: active,
+      },
+      '*::-webkit-scrollbar-corner': {
+        backgroundColor: track,
+      },
+    } : {}),
     body: {
       margin: 0, // Remove the margin in all browsers.
       ...body(theme),

Which turns into:

Capture d’écran 2020-09-14 à 14 02 05

We first explored this direction in https://github.com/mui-org/material-ui-x/pull/282.

Should we bundle the style in the CssBasline component? Any potential downsides?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
eps1loncommented, Sep 14, 2020

I thought this was a custom scrollbar implementation.

@eps1lon I think you can follow #21641 for this one.

I vastly prefer native scrollbars. Scrolling is one of those things that need the absolute best performance. And a general purpose React component can’t fit into that.

I would support this feature only if it uses native scrollbars. Though we should be a bit more diligent and explore standardized properties.

2reactions
mmmolscommented, Nov 5, 2020

Since @Avi98 haven’t responded, I will make a PR if that’s cool

Read more comments on GitHub >

github_iconTop Results From Across the Web

[RFC] Should we handle dark mode scrollbar? #22594
The default style of the scrollbar doesn't play well with a dark mode. The surface is too white, it draws more attention than...
Read more >
How do I switch to Chromes dark scrollbar like GitHub does?
Save this question. Show activity on this post. I just came across, that GitHub uses a dark scrollbar in Chrome, when you're using...
Read more >
CSS Scrollbars Styling Module Level 1
This CSS module defines properties to influence the visual styling of scrollbars, introducing controls for their color and width.
Read more >
Mui dark scrollbar
Firstly, we set the .scrollbar (class) width, height, background-color, ... 1 Security Insights New issue [RFC] Should we handle dark mode scrollbar?
Read more >
WebView
WebView objects allow you to display web content as part of your activity ... android:isScrollContainer, Set this if the view will serve as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found