Skip to content

Units without leading 0s causes shadow color to not work. #7178

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

Closed
crswll opened this issue Jan 23, 2022 · 0 comments · Fixed by #7289
Closed

Units without leading 0s causes shadow color to not work. #7178

crswll opened this issue Jan 23, 2022 · 0 comments · Fixed by #7289

Comments

@crswll
Copy link

crswll commented Jan 23, 2022

What version of Tailwind CSS are you using?

3.0.14

What build tool (or framework if it abstracts the build tool) are you using?

Play

What version of Node.js are you using?

N/A

What browser are you using?

Chrome

What operating system are you using?

macOS

Reproduction URL

https://play.tailwindcss.com/sgiL9df2gw?file=config

Describe your issue

When using a value without a leading 0 for a box shadow the color won't be changed.

I took a shot at rewriting parseBoxShadowValue to get it to work because it seemed like a fun one to play around with. Ran the tests and it all passed. Didn't want to create a PR incase you had quicker, better fixes.

let KEYWORDS = ['inset', 'inherit', 'initial', 'revert', 'unset']
let COMMA = /\,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubiz-bezier(a, b, c)` these don't count.
let SPACE = /\ +(?![^(]*\))/g // Similar to the one above, but with spaces instead.

function parseBoxShadowValue (input) {
  let shadows = input.split(COMMA)

  return shadows.map(shadow => {
    let value = shadow.trim()
    let parts = value.split(SPACE)
    let output = { raw: value, valid: true }

    // A box-shadow requires at least 3 parts.
    if (parts.length < 3) {
      output.valid = false
      return output
    }

    // The color is always at the end, also a color can't start with a number or a .
    if (/^[\d.]/.test(parts[parts.length - 1])) {
      output.valid = false
      return output
    }

    if (KEYWORDS.includes(parts[0])) {
      output.keyword = parts.shift()
    }

    output.color = parts.pop()
    output.x = parts.shift()
    output.y = parts.shift()
    output.blur = parts.shift()
    output.spread = parts.shift()
    output.unknown = parts

    return output
  })
}
@crswll crswll changed the title Units without leading 0s cause shadow color to not work. Units without leading 0s causes shadow color to not work. Jan 23, 2022
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.

1 participant