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

ERB classes don't show tailwind css autocompletion in form helpers #515

Closed
ishanray opened this issue Apr 11, 2022 · 7 comments
Closed

ERB classes don't show tailwind css autocompletion in form helpers #515

ishanray opened this issue Apr 11, 2022 · 7 comments

Comments

@ishanray
Copy link

<%= form.select :select_field, options, {}, 
        class: 'w-full mt-1 rounded-lg border  text-zinc-700' %>

When using tailwindcss in rails, the erb templates don't show any autocompletion when they are using rails form helpers.

@bradlc
Copy link
Contributor

bradlc commented Apr 13, 2022

Hey @ishanray. By default the extension only provides completions for syntax that looks like a HTML attribute (e.g. class="", className={}, [ngClass]="" etc.), and this is unlikely to change.

You can however use the tailwindCSS.experimental.classRegex setting to enable completions in custom locations. For the example you gave you could use a configuration like this:

"tailwindCSS.experimental.classRegex": [
  "\\bclass:\\s*'([^']*)'"
]

I hope that helps!

@bradlc bradlc closed this as completed Apr 13, 2022
@swanson
Copy link

swanson commented Jun 27, 2022

This was helpful, however I needed an additional regex to work with double quotes:

"tailwindCSS.experimental.classRegex": [
    "\\bclass:\\s*'([^']*)'",
    "\\bclass:\\s*\"([^\"]*)\""
 ],

@katekostina
Copy link

katekostina commented Jun 8, 2023

I added this to my config file but it doesn't work in RubyMine.
What could be a problem? Could you please take a look? @bradlc
image

@rafaeldalago
Copy link

Or simply this to consider both single and double quotes:

"tailwindCSS.experimental.classRegex": [
    "\\bclass:\\s*['\"]([^'\"]*)['\"]"
  ]

@loomchild
Copy link

loomchild commented Nov 20, 2023

Thanks a lot for sharing, it works.

For anyone using NeoVim with nvim-lspconfig:

lspconfig.tailwindcss.setup{
  settings = {
    tailwindCSS = {
      experimental = {
        classRegex = { [[\bclass:\s*'([^']*)']], [[\bclass:\s*\"([^"]*)"]] }
      }
    }
  }
}

@Samuelodan
Copy link

Same here @katekostina . It doesn't work for me in RubyMine.

@Samuelodan
Copy link

Update! I found a fix for RubyMine @katekostina and anyone else interested.
All it took was installing Tailwind within the project via npm install -D tailwindcss according to the RubyMine Tailwindcss docs.

It also enabled the feature that lets you see the resulting CSS on hover.
I should mention, though, that VS Code didn't require this additional install. It just worked.

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

No branches or pull requests

7 participants