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

Regard operating system color scheme for rescues #36122

Conversation

cseelus
Copy link
Contributor

@cseelus cseelus commented Apr 27, 2019

Summary

Small PR that enables Rails to regard the OS setting for dark/light appearance when displaying errors.

It uses the prefers-color-scheme CSS media query which is currently supported by Firefox and Safari and in development for Chrome.

Essentially when you crunch it deep at night and don't want to burn your retinas, thus have enabled dark mode for your OS, it changes this …

Screen Shot 2019-04-27 at 17 57 36

… into this

Screen Shot 2019-04-27 at 17 57 09

@rails-bot rails-bot bot added the actionpack label Apr 27, 2019
Copy link
Member

@gmcgibbon gmcgibbon left a comment

Choose a reason for hiding this comment

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

This is really cool! In light of the recent addition of actionable errors (#34788), can we add styling for buttons too?

@cseelus cseelus force-pushed the respect-operating-system-color-scheme-for-errors branch from a5077d5 to ccd97d1 Compare May 15, 2019 10:45
@cseelus
Copy link
Contributor Author

cseelus commented May 15, 2019

Thanks @gmcgibbon!

Added the supported-color-scheme CSS property, which adapts the styling of form inputs automatically according to the selected OS appearance:

Screen Shot 2019-05-15 at 12 23 08

Screen Shot 2019-05-15 at 12 42 32

@gmcgibbon
Copy link
Member

gmcgibbon commented May 15, 2019

supported-color-schemes: light dark; doesn't seem to work on firefox nightly. 🤔 Is it part of the prefers-color-scheme spec?

@cseelus
Copy link
Contributor Author

cseelus commented May 15, 2019

Its part of the spec, but unfortunately not implemented by Firefox yet.

I have also added the color-scheme prop, which will supplant supported-color-schemes, if thats ok with you.

Edit: Moved that property into the declaration for the body-tag, which I think is cleaner.

Edit 2: Firefox doesn't seem to fully support macOS dark mode yet, as seen in the following screenshot. Nevertheless I think its easier on the eyes than no support at all:

Screen Shot 2019-05-15 at 22 26 34

@cseelus cseelus force-pushed the respect-operating-system-color-scheme-for-errors branch 2 times, most recently from 4c1111e to fc9e601 Compare May 15, 2019 20:21
Copy link
Member

@gmcgibbon gmcgibbon left a comment

Choose a reason for hiding this comment

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

Firefox doesn't seem to fully support macOS dark mode yet

Would it not make more sense to remove color-scheme: light dark; and apply a few lines of manual styling for buttons? I can't think of a place where we use other form elements, so having legacy support for just form input buttons should be fine (we can always remove it later).

Also please squash your commits into one.

@cseelus
Copy link
Contributor Author

cseelus commented May 16, 2019

Would it not make more sense to remove color-scheme: light dark; and apply a few lines of manual styling for buttons?

Tough question. Native styling has its advantages and I wouldn't have dared to touch that buttons, but I guess you are right, it might actually make sense here.

I would suggest keeping color-scheme: light dark;, as it "lets the engine know both modes are supported by the document", which might have implications for example when using accessibility features. This CSS prop is also in development for Chrome.

Have squashed all commits into one, wasn't aware this was to be done for each iteration.

@cseelus cseelus force-pushed the respect-operating-system-color-scheme-for-errors branch from fc9e601 to a6bc443 Compare May 16, 2019 12:46
Copy link
Member

@gmcgibbon gmcgibbon left a comment

Choose a reason for hiding this comment

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

One last thing. We haven't decided on a style for the button yet and I was thinking just manually styling buttons to look like what you've shown in your screenshots on Safari. If you could revert the other button stylings, I will merge this.

Thank you for your patience! ❤️

@cseelus
Copy link
Contributor Author

cseelus commented May 17, 2019

No problem at all, thanks for the input!

So just to make sure I got that: You want the buttons to be styled with CSS to look like (native) macOS buttons?

@gmcgibbon
Copy link
Member

So just to make sure I got that: You want the buttons to be styled with CSS to look like (native) macOS buttons?

Yes, the way they currently look on master:

Screen Shot 2019-05-15 at 12 23 08

And then in dark mode (on firefox nightly and safari) we can add manual styles for form input buttons to look like this:

Screen Shot 2019-05-15 at 12 42 32

@cseelus cseelus force-pushed the respect-operating-system-color-scheme-for-errors branch from a6bc443 to a26ac25 Compare May 18, 2019 00:17
@cseelus
Copy link
Contributor Author

cseelus commented May 18, 2019

Done.

Untitled

Edit: Only fo the dark versions style is "hardcoded", the normal version is unstyled/native.

@cseelus cseelus force-pushed the respect-operating-system-color-scheme-for-errors branch from a26ac25 to fe9c249 Compare May 18, 2019 00:46
Copy link
Member

@gmcgibbon gmcgibbon left a comment

Choose a reason for hiding this comment

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

Looks great! Please remove the hover and focus styles on the dark buttons and then we can :shipit:

padding: 2px 7px;
}
input[type="submit"]:focus,
input[type="submit"]:hover {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this focus or hover rule is necessary as there are no hover or focus styles applied to light mode buttons.

@matthewd
Copy link
Member

I can't be sure without looking at a proper mock-up, but I think I'd ultimately aim for those buttons to look more like the one on https://rubyonrails.org/ or something -- I'd always seen the current plain OS styling as being temporary, and far too subtle on a busy and colorful screen, given it's almost certainly what you want to do.

(But that's all an aside for this PR: here, a dark style that matches the existing light style is fine.)

Talking of dark style, though, the current-line highlight in dark mode looks pretty average to me... maybe a quite-dark red would work better?

@cseelus cseelus force-pushed the respect-operating-system-color-scheme-for-errors branch from fe9c249 to d8f4cfa Compare May 18, 2019 10:33
@cseelus
Copy link
Contributor Author

cseelus commented May 18, 2019

Removed hover and focus styles for the button.

@matthewd Using a button style similar to the one on rubyonrails.org would look something like this:

Screen Shot 2019-05-18 at 12 51 15

… and a line highlight that is more of a dark red would look like this:

Screen Shot 2019-05-18 at 12 55 56

@matthewd
Copy link
Member

Thanks @cseelus! I like both of those, though I think it's still safer to stick with the plain button style in this PR (so this PR can get merged without a side-track into extra opinions). I'd love to see a separate PR for that button change if you're interested!

@gmcgibbon gmcgibbon merged commit 88b12b2 into rails:master May 18, 2019
@cseelus cseelus deleted the respect-operating-system-color-scheme-for-errors branch May 19, 2019 03:37
@cseelus
Copy link
Contributor Author

cseelus commented May 19, 2019

Yeah, redesigning that button sure is a separate and probably somewhat controversial matter.

@matthewd
Copy link
Member

Did this get the line-highlight change?

@cseelus
Copy link
Contributor Author

cseelus commented May 19, 2019

Last push where just the changes requested by Gannon.

Wanted to wait for feedback if the darker red I chose in the mock-up was actually an improvement, but the PR got merged before I saw your last comment and could react.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants