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

Add selected variant #2385

Closed
wants to merge 1 commit into from
Closed

Conversation

EpicEric
Copy link
Contributor

This commit adds the selected variant -- unused by default --, which allows the styling of selected/highlighted parts of the document (usually, text).

This variant uses the ::selection pseudo-element; as such, it can only be applied to the following current Tailwind utilities:

  • Text color
  • Background color
  • Cursor
  • Text decoration

The main purpose for this variant is to improve accessibility of the selection feature in certain browsers, elements and styles, such as on macOS, where eg. a non-stylized selection over a bg-blue-400 element (#63b3ed) will result in a highlight background of #9fbed4 on Chrome and an even worse #65b2f6 on Firefox, both of which have terrible contrast by default.

This commit adds the `selected` variant -- unused by default --, which allows
the styling of selected/highlighted parts of the document (usually, text).

This variant uses the [`::selection`](https://developer.mozilla.org/en-US/docs/Web/CSS/::selection)
pseudo-element; as such, it can only be applied to the following current
Tailwind utilities:

- Text color
- Background color
- Cursor
- Text decoration

The main purpose for this variant is to improve accessibility of the selection
feature in certain browsers, elements and styles, such as on macOS, where eg. a
non-stylized selection over a `bg-blue-400` element (`#63b3ed`) will result in
a highlight background of `#9fbed4` on Chrome and an even worse `#65b2f6` on
Firefox, both of which have terrible contrast by default.
@EpicEric
Copy link
Contributor Author

As a side note: I've tried to add the ::-moz-selection pseudo-element as well, but I could not get it to work with both selectors.

@neupauer
Copy link
Contributor

neupauer commented Oct 9, 2020

+1 for that 👍... btw I don't think it is necessary to explicitly add ::-moz-selection, Autoprefixer should take care of that.

@adamwathan
Copy link
Member

I like this idea and would like to include it! Just need to dedicate some time to thinking it through deeply and making sure there are no alternate API ideas. Like select-text-blue-500 instead of a variant for example, or finding a way to be clever with CSS variables to reduce the number of generated classes. Will come back to this probably in a month or two when we wrap up some other stuff and I can dedicate some time to thinking about it. Thanks and sorry for the delay!

@adamwathan
Copy link
Member

Hey! Decided to call this selection:bg-blue-500 to make it easy to guess for people familiar with the CSS syntax, and I've collapsed it into #4482 along with support for all other relevant pseudo-elements/classes. I've added you as a co-author on it to make sure you get credit for it but going to close this PR in favor of that one ❤️

@adamwathan adamwathan closed this May 26, 2021
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.

3 participants