Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

269
Visualizações
Tailwind transition delay arbitrary value only working for specific values

I am getting really inconsistent behavior with tailwinds arbitrary value functionality, specifically in relation to the transition delay property. When I use any random value directly within the arbitrary value it has worked for every value I have tested so far (random positive integers). Ex...

<li className="delay-[2455]">{some text}</li>

But if I were to use a variable, the class will only occasionally have any effect depending on the value, seemingly randomly. Ex...

const delay = "250ms";
return <li className={`delay-[${delay}]}`></li>

This segment above will produce a valid class but the segment below will have no effect and will not produce a valid class

const delay = "500ms";
return <li className={`delay-[${delay}]}`></li>

I am not sure if this is something that I am doing wrong or is some weird quirk in tailwind. I am open to any and all suggestions. If it makes a difference I am using typescript in conjunction with react. I am using tailwindcss version 3.0.11 and postcss version 8.4.5 These are my tailwind.config.js and my postcss.config.js files

module.exports = {
  content: ["./src/**/*.{js,jsx,ts,tsx}",],
  theme: {
    extend: {
      screens: {
        '3xl': '1920px',
        'xsm': '428px',
        '2xsm': '360'
      },
      fontFamily: {
        title: ['Patrick Hand'],
        body: ['Balsamiq Sans']
      },
      transitionProperty: {
        'opacity': 'opacity',
      },
    },
  },
  plugins: [],
}

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Right from the docs:

The most important implication of how Tailwind extracts class names is that it will only find classes that exist as complete unbroken strings in your source files.

If you use string interpolation or concatenate partial class names together, Tailwind will not find them and therefore will not generate the corresponding CSS

It means that you need to use full class name, not dynamic concatenation of its parts.

For example you can make a function like that:

function getClassByDelay(delay) {
  return {
    250: 'delay-250',
    500: 'delay-500',
    750: 'delay-750',
  }[delay]
}

And use it like so: <li className={getClassByDelay(delay)}></li>

If you really need to use dynamic classes then you can also use another approach: just add them to the safelist array in the config:

// tailwind.config.js
module.exports = {
  content: [
    // ...
  ],
  safelist: [
    'delay-250',
    'delay-500',
    'delay-750',
    // etc.
  ]
  // ...
}

That way Tailwind will know that it needs to generate this safelist classes anyway, regardless if it finds them in your source code or not.

Obviously it has downside that you need to manage this list and not forget to delete unused classes from the config if you stop using them in the code, otherwise they will be a dead weight in your bundle.

More info: https://tailwindcss.com/docs/content-configuration#class-detection-in-depth

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda