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

prose-invert not working as expected #228

Closed
rjgux opened this issue Dec 17, 2021 · 14 comments · Fixed by #315
Closed

prose-invert not working as expected #228

rjgux opened this issue Dec 17, 2021 · 14 comments · Fixed by #315
Assignees

Comments

@rjgux
Copy link

rjgux commented Dec 17, 2021

What version of @tailwindcss/typography are you using?

v0.5.0

What version of Node.js are you using?

v12.0.0

What browser are you using?

Chrome

What operating system are you using?

macOS

Reproduction repository

https://play.tailwindcss.com/vkmcuQsUPz

Describe your issue

I may be misunderstanding how prose-invert works, but in the Tailwind Play example where it's used in combination with a custom color theme (in this case prose-white) the inversed colours are not being applied.

prose-white prose-invert I would expect --tw-prose-body to be set to theme.colors.black.

Screenshot 2021-12-17 at 20 22 23

@Karmalakas
Copy link

I think invert works only with default - prose prose-invert. If you use any prose-COLOR, invert won't work

@liltechnomancer
Copy link

I think invert works only with default - prose prose-invert. If you use any prose-COLOR, invert won't work

This is not true, that is why they include all the --tw-prose-invert variables.

@Karmalakas
Copy link

I'd need to revisit my code now (been a while), but I also couldn't make it work

@liltechnomancer
Copy link

I could probably get a repository with a minimal reproduction this weekend. I am currently running into this.

@mttmzr
Copy link

mttmzr commented Feb 11, 2022

This can be resolved by moving the invert modifier (https://github.com/tailwindlabs/tailwindcss-typography/blob/master/src/styles.js#L923-L943) below all the gray and color modifiers to the end of defaultModifiers in src/styles.js.

@adamwathan
Copy link
Member

Just spent a little time looking into this, don't have a solution yet but wanted to leave some notes for myself so I don't forget:

The root problem here is that when we added prose-invert we sort of always expected it to actually be used as dark:prose-invert, which has a higher specificity than prose-zinc or similar, and therefore triggers the inverted color, even though prose-invert is actually defined earlier in the CSS.

This means that prose-invert doesn't work when used as the default, for example on a dark block in an otherwise light mode site, like bg-black prose-zinc prose-invert.

One possible solution is trying to make sure prose-invert is always last in the CSS output. Another is reworking the variable names so that the color modifiers are setting different variables than the prose-invert class (maybe --tw-prose-normal-body and invert sets --tw-prose-body, and the regular prose class also loads up the defaults to make sure they are applied). I think the second option is maybe "better" but could be a breaking change.

@joshleblanc
Copy link

joshleblanc commented Jun 14, 2022

Just in case someone else runs across this, you can temporarily work around this with prose !prose-invert

@bb
Copy link

bb commented Aug 25, 2022

Thanks for pointing to !, @joshleblanc!

I am using prose dark:prose-invert but it sill does not invert (without exclamation mark) because there's another rule :root .prose overriding both .proseand dark:prose-invert (without !). I have no idea where :root comes from, I'm only specifying prose max-w-full dark:prose-invert.

Maybe specifically adding :root to the invert-rule could solve this issue?

CleanShot 2022-08-25 at 15 14 31@2x

@leslie555
Copy link

leslie555 commented Feb 17, 2023

v0.5.9 + tailwindcss v3.2.2 still has this issue. Could someone update the DOC? I spent a couple of hours on it and then find this address.

oeyoews added a commit to oeyoews/tiddlywiki-starter-kit that referenced this issue Mar 22, 2023
@sedubois
Copy link

sedubois commented May 24, 2023

I tried the suggested !prose-invert workaround but dark mode still doesn't work for me. In the example below, the heading text is invisible in dark mode (same color as background). Am I missing something?

<body class="text-gray-900 dark:text-gray-100 bg-gray-100 dark:bg-gray-900">
  <article class="prose dark:!prose-invert"> <!-- also tried <article class="prose !prose-invert"> -->
    <h1>My Heading</h1>
  </article>
</body>

This CSS rule gets applied:

.prose :where(h1):not(:where([class~=not-prose] *)) {
  color:var(--tw-prose-headings);
}

.prose {
  --tw-prose-headings: #111827;
}

I can't find any code like @media(prefers-color-scheme:dark) { .dark:prose-invert { ... } } in the generated CSS. Isn't there supposed to be something like that?

Using tailwindcss-rails 2.0.29 (corresponding to Tailwind CSS v3.3.2 according to the release note) and the Rails-generated config:

const defaultTheme = require('tailwindcss/defaultTheme')

module.exports = {
  content: [
    './public/*.html',
    './app/helpers/**/*.rb',
    './app/javascript/**/*.js',
    './app/views/**/*.{erb,haml,html,slim}'
  ],
  theme: {
    extend: {
      fontFamily: {
        sans: ['Inter var', ...defaultTheme.fontFamily.sans],
      },
    },
  },
  plugins: [
    require('@tailwindcss/forms'),
    require('@tailwindcss/aspect-ratio'),
    require('@tailwindcss/typography'),
    require('@tailwindcss/container-queries'),
  ]
}

@samjowen
Copy link

Just in case someone else runs across this, you can temporarily work around this with prose !prose-invert

Thank you.

@reinink
Copy link
Member

reinink commented Aug 30, 2023

Hey folks! Thanks for reporting this issue. I implemented what @adamwathan suggested above in #315, and from my testing this seems to fix this issue without any negative side effects. Hoping to get a new release of the plugin out tomorrow if all goes well 👍

@iansedano
Copy link

Thank you for this fix! Unfortunately I think I've run into an edge case.

This seems to work for the built-in themes, but not if you work with a custom theme.

Here is a reproduction: https://play.tailwindcss.com/TRN5em5a8E

As a summary of the reproduction linked above:

HTML

<div class="prose prose-invert prose-custom bg-slate-200">
  <p>Curabitur blandit tempus ardua ridiculus sed magna. Sed haec quis possit intrepidus aestimare tellus. Quisque ut dolor gravida, placerat libero vel, euismod. Plura mihi bona sunt, inclinet, amari petere vellent.</p>
</div>

Trying to use prose-invert prose-custom classes, where prose-custom is my own color theme.

Config

/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    extend: {
      typography: (theme) => ({
        custom: {
          css: {
            '--tw-prose-body': theme('colors.black'),
            '--tw-prose-invert-body': theme('colors.white'),
          },
        },
      }),
    },
  },
  plugins: [require('@tailwindcss/typography')],
}

With this config, I'd expect the above HTML to render as white text, but it renders as black text. This seems like the same behavior that the plugin had for all the themes prior to the fix. Perhaps the same thing is happening to the potential custom themes?

@ravi-ojha
Copy link

@iansedano Put prose-custom before prose prose-invert in your class attr.

For eg: <div class="prose-custom prose prose-invert">

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 a pull request may close this issue.