How to customize the color of the clock symbol in a MUI TextField set to type 'time'

<TextField
  id="endTime"
  label="End Time"
  onChange={onEndTimeChange}
  type="time"
  defaultValue="16:00"
  className={classes.textField}
/>

By using the attribute 'type="time"', an icon resembling a clock is displayed. I am interested in customizing the color of this clock icon. Is there a way to achieve this?

Answer №1

With CSS, you have the ability to conceal the default clock icon and substitute it with your preferred icon:

Although not extensively tested on all browsers, this method should function properly on browsers that support -webkit

input[type="time"]::-webkit-calendar-picker-indicator {
  background: none;
 
}

input[type="time"]{
  z-index: 0;
  position: relative;
}

input[type="time"]:after{
  content: "";
  background-image: url(https://i.ibb.co/6g2dgm0/1535322171.png);
  height: 20px;
  width: 20px;
  background-size: contain;
  z-index: -1;
  position: absolute;
  right: 0;
}
<input type="time" />

Answer №2

If you're looking to easily customize a component, consider checking out the TimePicker in the lab package. Styling the native time input can be challenging due to the lack of support. To change the icon color to green, you can use the following code snippet:

<TextField
  sx={{
    '& input[type="time"]::-webkit-calendar-picker-indicator': {
      filter:
        'invert(78%) sepia(66%) saturate(6558%) hue-rotate(84deg) brightness(127%) contrast(116%)',
    },
  }}
  type="time"
  {...}
/>

The filter value is based on this codepen example. Alternatively, if you opt for using the TimePicker, the code would resemble this:

<TimePicker
  label="Basic example"
  components={{
    OpenPickerIcon: (props) => (
      <AccessTimeIcon {...props} sx={{ color: 'red' }} />
    ),
  }}
  renderInput={(params) => <TextField {...params} />}
/>

For a demo, you can visit this link.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When using jQuery to enable contenthover on divs, they will now start a new line instead of

I've been working on achieving a layout similar to this, with the contenthover script in action: Mockup Draft Of Desired Look However, the result I'm getting is different from what I expected, it can be seen here. The images are not aligning co ...

What causes the Return URL page to load before the DocuSign form is signed in my iframe at times?

One challenge I encountered with my Next.js application was embedding a DocuSign form using an iframe. Occasionally, upon visiting the page where the embedded form is located, I would see the Return URL page instead of the actual form. This issue seemed to ...

Creating a persistent hover effect

Utilizing primarily CSS, along with background images and adjacent selectors, I am creating a page that displays unique human-readable text information when the user hovers over horizontally stacked images. The textual information is presented in a div on ...

Internet Explorer 10 offers 3D transformation capabilities

My 3D rotating image carousel works well in Chrome and Firefox but not in IE. I am aware that IE10+ does not fully support the preserve-3d tag, and although there are workarounds by applying transforms to the children instead, I have been unsuccessful in ...

Strategies for extracting data from multiple Textareas in React

I am facing an issue with a form that contains multiple textarea elements (specifically 3). The problem is that when I type in one textarea, the content is automatically filled and updated in the other textareas as well. This behavior is not desired. I h ...

Choose a color from the material-ui-color picker and set it when the mouse is released

Has anyone experienced difficulties with setting the value onChange in the material-ui-color ColorPicker plugin? The issue I'm facing is that every time I start dragging the mouse within the ColorPicker, it triggers the onChange function continuously ...

How to Implement Transition Effect for Height Changes on v-if in Vuejs

I have a code snippet that effectively animates a v-if element by reducing its height to 0px. The animation is working well, but the issue arises when I need to specify the initial height of the element in CSS. While this is fine for a single element, I ...

Launch a Next.JS web application utilizing Yarn on Google App Engine

I'm in the process of deploying a web application that was constructed using templates provided by a friend. I don't have much experience with React/NextJS frameworks, so I'm uncertain about the distinctions between yarn and npx. When runni ...

CSS code causing issues with table cellpadding functionality

I am currently working on a webpage that is utilizing a pre-existing stylesheet. This particular stylesheet includes the following style rules: table { border-collapse: collapse; } th, td { padding: 0; } My challenge arises when I attempt to cre ...

Extracting props data from a component in React.js - a step-by-step guide

I am currently developing a react.js application with react-select. I have created a dropdown menu and when an item is clicked, I need to pass that item to a function that is connected to the redux store. How can I retrieve data from a component used in re ...

Modify the path name in Next.js according to the local environment

In my upcoming next.js project, I aim to dynamically alter the URL according to the language selection of the user. By default, the URL for the English language is set to: http://localhost:3000/en/privacy-policy If the language is switched from English ...

Using MUI autocomplete with an array of objects will result in a flattened one-dimensional array

I am currently using the Autocomplete component with the following setup: <Autocomplete options={channels} autoHighlight multiple disableCloseOnSelect value={form.channel_ids} getOpti ...

An effective solution to address the Eslint warning regarding the prohibition of spreading specific props

Just getting started with React and I have a question. How can I address the Prop spreading is forbidden Eslint warning that keeps popping up? After reading through the Eslint documentation, it seems like I have to destructure all props like this: con ...

Assign properties to a component from an object

I'm working on connecting React Components to Objects by passing imported Components as Props. const [showComponent, setShowComponent] = useState([ { cId: 1, componentName: <ContactDialogAddresses />, title: 'Address', render: true ...

Customizing the colors of an Ant Design header

I am currently attempting to modify the background color of the entire header in antdesign. I believe the file containing the default settings can be found here: https://github.com/ant-design/ant-design/blob/master/components/style/themes/default.less Upo ...

ShadowBox replacement for IE8

After much experimentation, I am on the verge of achieving an inset box shadow for IE8 without relying on JavaScript. Take a look at the screenshot below: Since Internet Explorer versions 5.5 through 8 only support Microsoft's "dropshadows" and "sha ...

Firebase Function deployment encountered an issue during the build phase, despite the predeploy process

My react.js project includes Firebase functions that are configured in a sub-folder called root/functions. These functions are written in typescript and have paths option set in tsconfig.json. In my functions/index.ts file, I import files from various loca ...

How can one change the data type specified in an interface in TypeScript?

I am currently diving into TypeScript and looking to integrate it into my React Native application. Imagine having a component structured like this: interface Props { name: string; onChangeText: (args: { name: string; value: string }) => void; s ...

What is the best way to ensure this react component is reusable and able to accept a dynamic initial state?

I've managed to create a dynamic input table, but I'm looking for ways to enhance its reusability and dynamism. As it stands, the name and age are hardcoded in the code. If I want to pass additional props like country, region, etc., this current ...

Show method created by function, substituting the former element on the display

showButtons(1) will show radio buttons for frame number 1, showButtons(400) will display radio buttons for frame number 400. The current code shows all radio buttons for every frame up to 400 HOWEVER, I am aiming for a single set of radio buttons to start ...