skip to Main Content

I am trying to remove the appearance border inside my input. But I am unable to remove it. Someone please guide me how can I remove it? I am using TailwindCSS and React JS.

You can see an inner border in the picture attached

This is the link to codesandbox: (Codesandbox)

My code:

import * as React from "react";
import { useState, ChangeEvent } from "react";


export default function App() {
  const [selectedColor, setSelectedColor] = useState("#1C4B40");

  const handleColorChange = (event: ChangeEvent<HTMLInputElement>) => {
    let inputValue = event.target.value;
    if (!inputValue.startsWith("#")) {
      inputValue = `#${inputValue}`;
    }
    setSelectedColor(inputValue);
  };

  return (
    <div className="bg-gray-500">
      <input
        id="colorPicker"
        type="color"
        style={{
          WebkitAppearance: "none",
          appearance: "none",
          backgroundColor: selectedColor,
          borderColor: selectedColor,
          outline: "none"
        }}
        className="h-8 w-8 cursor-pointer rounded-[4px] border-none"
        value={selectedColor}
        onChange={handleColorChange}
      />
    </div>
  );
}


Image

I am trying to remove the inner grey border from the input. I want to achieve it using tailwind

enter image description here

2

Answers


  1. You have issue with tailwind config. Thats why it does not work.
    See here Tailwind styling not working in react project

    Login or Signup to reply.
  2. Add this into your index.css file

    .swatch-wrapper {
      &::-webkit-color-swatch-wrapper {
        padding: 0;
      }
    
      &::-webkit-color-swatch {
        @apply border-2 border-transparent rounded-[4px];
      }
    }

    After use the class in your code

    <input
        id="colorPicker"
        type="color"
        className="swatch-wrapper h-8 w-8 cursor-pointer appearance-none rounded-[4px] border-none bg-none"
         value={selectedColor}
        onChange={handleColorChange}
    />
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search