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.

Merge function does not work with custom box shadow classes

See original GitHub issue

Hello, thanks for this awesome package.

I noticed an issue with the twMerge function when using custom box shadow classes.

// Actual
twMerge('shadow-md shadow-lg shadow-light shadow-dark') // 'shadow-lg shadow-light shadow-dark'

// Expected 
twMerge('shadow-md shadow-lg shadow-light shadow-dark') // 'shadow-dark'

This works properly with the normal box shadow classes.

Perhaps I to make a custom tailwind merge function with the light and dark suffixes? Thanks.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dcastilcommented, Oct 21, 2021

Hi @charkour! Indeed, if you’re using a custom Tailwind config, you need to use createTailwindMerge and create a config for it. You don’t need createTailwindMerge in all cases, but in this one yes.

Here is how to create it in v0.7.1:

import { createTailwindMerge } from 'tailwind-merge'

export const twMerge = createTailwindMerge((getConfig) => {
    const config = getConfig()

    config.classGroups.shadow.push({ shadow: ['light', 'dark'] })

    return config
})

In v0.8.0 which will be released soon you can do it a little cleaner:

import { createTailwindMerge, getDefaultConfig, mergeConfigs } from 'tailwind-merge'

export const twMerge = createTailwindMerge(() =>
    mergeConfigs(getDefaultConfig(), {
        classGroups: {
            shadow: [{ shadow: ['light', 'dark'] }],
        },
    })
)

If you’re wondering where that class group name shadow comes from, it is specified in the default config here. So far there is no straight forward way to figure out which property to access but to look into the source code.

Let me know if that helps.

0reactions
dcastilcommented, Oct 21, 2021

Moving this to discussions as this isn’t a bug in tailwind-merge.

Read more comments on GitHub >

github_iconTop Results From Across the Web

css merge box shadows - Stack Overflow
However, because there are two shadows between each element, I get a shadow two times thicker between them. navigation bar. Is there a...
Read more >
box-shadow - CSS: Cascading Style Sheets - MDN Web Docs
The box-shadow CSS property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is...
Read more >
box-shadow - CSS-Tricks
The box-shadow property in CSS is for putting shadows on elements (sometimes referred to as “drop shadows”, ala Photoshop/Figma).
Read more >
[Feature Proposal] Coloured Box Shadow · Issue #654 - GitHub
Heya, I think it'd be neat if box shadows worked with colour ... It would generate a lot of classes that most people...
Read more >
Using box-shadow to construct a border | Codementor
box -shadow is a wonderful property. Use it to draw simple borders with CSS.
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