1

I'm very new to Tailwind, and I have weird problem. When I apply tailwind classes to react component, some of them (eg. bg-default-800, rounded-lg) work normal, but some don't.

export function Tile(props: PropsWithChildren<propsInterface>) {
    return (
        <div
            className={'bg-default-800 m-2 rounded-lg flex flex-col justify-center ' +
                'w-' + props.width + '/4 h-' + props.height + ' '}>
            {props.children}
        </div>
    )
}

Here's usage of this component:

function App() {
  return (
    <div className={'flex flex-row flex-wrap'}>
        <Tile width={1} height={36}>
            tile 1
        </Tile>
        <Tile width={3} height={36}>
            tile 2
        </Tile>
    </div>
  )
}

Here's tailwind.config.cjs:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}",
  ],
  theme: {
    extend: {
      colors: {
        'default': {
          '800': '#166534',
        },
      },
    },
  },
  plugins: [],
}

In this case, 'w-1/4' works, but 'w-3/4' don't. It worked only after I had changed className to hardcoded values (without props). Then, I redo changes and it still works, which is weird. When it comes to height, 'h-32' works, but 'h-36' doesn't, like many other values from tailwind documentation. Shift + F5 doesn't help.

1

2 Answers 2

2

You are using mode: 'jit' option in tailwind config.

Tailwind is trying to remove all non used classes from the final bundle.

From the docs:

Dynamic values Note that you still need to write purgeable HTML when using arbitrary values, and your classes need to exist as complete strings for Tailwind to detect them correctly.

Don't use string concatenation to create class names

<div className={`mt-[${size === 'lg' ? '22px' : '17px' }]`}></div>

Do dynamically select a complete class name

<div className={ size === 'lg' ? 'mt-[22px]' : 'mt-[17px]' }></div>

In your example you are using the first version, which won't work

Sign up to request clarification or add additional context in comments.

Comments

0

Try to use default config of tailwinds

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.