When I encountered this issue it took me about 20 minutes to find the answer in an article here: https://www.kindacode.com/snippet/how-to-style-file-inputs-with-tailwind-css/
I had scrolled though many pages of overly complicated answers on existing similar questions on Stackoverflow
Posting the solution here so that people can quickly find the answer
Following the examples provided in the question here Styling an input type="file" button I tried a bunch of solutions that weren't quite satisfactory
I tried wrapping the input in a label element and setting the display to none
<label className="text-sm bg-stone-200 hover:bg-stone-300" htmlFor="fileUpload">
<input type="file" className="hidden" id="fileUpload"/>
Upload File
</label>
which works, but then you lose the file name preview - solutions for this involved putting a <span>
between the label and the hidden input and altering the span element in the onChange event.. I think thats too much code for such a simple task
I also tried setting the size with the element attribute <input type="file" size={60} />
which apparently worked for other people, but had no effect when I tried
file
prefix. This is also in the Tailwind documentation. tailwindcss.com/docs/… – Beagle