Skip to content

Refactor native select caret styles, fixes #571 and #572 #594

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

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

lindsaym-fa
Copy link
Contributor

@lindsaym-fa lindsaym-fa commented Jan 24, 2025

For styling a native <select>, the story goes:

  • We can't use ::after on a <select>.
  • We can't use ::after on a <label> containing the select because it won't appear for selects outside of a label.
  • We can't use the technique of background-color + mask on a <select> to get the right shape and color of the caret since...well, the select itself will be masked.

So, in a live discussion of #571, we chose to use the browser's default caret rather than trying to replace it with our own. As it turns out...

We can't do that because each browser's default select styling creates inconsistencies, but most of all...Safari.


❌ Fail: Using the browser's default caret

Removing appearance: none to use the browser's default caret yielded these results:
Firefox (close!)
Screenshot 2025-01-23 at 4 06 30 PM

Chrome and Edge (they add space around the selected value that we can't seem to target)
Screenshot 2025-01-23 at 4 07 20 PM

Safari (straight-up doesn't care)
Screenshot 2025-01-23 at 4 06 10 PM


✅ Pass: Using background-image with background-blend-mode

So, I ended up taking the approach of keeping appearance: none and using a background-image with background-blend-mode.

The results are not exact, but they are passable. Here are some examples:
Default theme:
Screenshot 2025-01-23 at 7 04 12 PM
Screenshot 2025-01-23 at 7 04 19 PM
Screenshot 2025-01-23 at 7 04 33 PM
Screenshot 2025-01-23 at 7 04 27 PM

Awesome theme:
Screenshot 2025-01-23 at 7 04 52 PM
Screenshot 2025-01-23 at 7 04 58 PM
Screenshot 2025-01-23 at 7 04 44 PM
Screenshot 2025-01-23 at 7 05 03 PM

The worst offenders are selects in the Premium theme, where background-blend-mode is less effective because the theme sets --wa-form-control-background-color: transparent.

A filled select in dark mode is not especially great:
Screenshot 2025-01-23 at 6 43 30 PM

An outlined select in light mode is meh:
Screenshot 2025-01-23 at 6 43 53 PM

There may be a closer match, but I've exceeded the allotment of time I'd like to spend mixing and matching blend modes for now.

@lindsaym-fa lindsaym-fa linked an issue Jan 24, 2025 that may be closed by this pull request
Copy link

vercel bot commented Jan 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
webawesome ✅ Ready (Inspect) Visit Preview Jan 24, 2025 0:08am

@lindsaym-fa lindsaym-fa requested a review from LeaVerou January 24, 2025 00:08
@lindsaym-fa lindsaym-fa linked an issue Jan 24, 2025 that may be closed by this pull request
Copy link
Contributor

@LeaVerou LeaVerou left a comment

Choose a reason for hiding this comment

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

Wow, this is great! I'm so glad the blending mode idea actually panned out!! I hadn't considered including the icon twice, that's clever.

@lindsaym-fa lindsaym-fa merged commit 71c054d into next Jan 24, 2025
2 checks passed
@lindsaym-fa lindsaym-fa deleted the 571-native-select-not-inside-a-label-has-no-caret branch January 25, 2025 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Native <select> caret is blocking interactions Native <select> not inside a <label> has no caret
2 participants