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

CSS: Creative ways to switch up background hues within a grid layout

Im working on a project with a similar layout to this https://i.sstatic.net/okRL1.png I am trying to achieve a chessboard effect in my grid layout, where the last element of one row has the same background color as the first element of the next row. I h ...

What is the reason behind the issue of an infinite loop being resolved by including additional arrow function parentheses?

I'm currently using React for my project, and I've encountered an issue with the setState hook. Below is a snippet of my code: //state and handle function const [activeStep, setActiveStep] = React.useState(0); const handleStep = (index) => ...

Send a parameter to a React hook

I am facing an issue with a Component that is using a separate hook. I am unable to pass any value to that hook, which is necessary for my use case. const onEdit = (index: number) => useMediaLinkImage(img => { setNodeImages(imgData => { ...

Dynamic use of a mixin in LESS allows for greater flexibility in

Is it possible to dynamically call a mixin in Less CSS? An interesting use case could be creating a style guide: // Define the mixin that needs to be called .typography-xs(){ font-family: Arial; font-size: 16px; line-height: 22px; } // A mixin att ...

How do I make a div's height equal to 100% of the height of its parent

I am trying to make a button stick to the bottom of a card no matter how much content is on it. I used the Bootstrap class mt-auto, which worked well. However, when I set the height of all divs to 100%, the row in the card body overflows from the lg breakp ...

Typewriter Effect: The caret is advancing too quickly

I am trying to achieve a typewriter effect on my text, but the blinking cursor is extending further than the actual text. See Image for Problem Here is the code I am using: HTML: <div class="title"> <h1>Hi, I'm ConnerDE< ...

Can a full-fledged React application be opened in a popup window?

I'm currently working on an application that features a list of devices. When a user clicks on any device item, I want a popup to open with a React application specific to that device, complete with its own routing configuration. I've searched on ...

React Native: Issue with React Navigation Tab Screen not updating when using child components that are not inline functions

While working on my tab screen code, I encountered a strange behavior. I wanted to pass an extra prop into the screen component, so I created an arrow function that returns the desired component (upcomingOrderView). When I called this function inside the T ...

What is the best way to adjust the row and column layout in bootstrap?

As I was creating a layout to showcase all of the bootstrap cards in a neat and organized manner, I noticed a peculiar issue that's been bothering me. Everything looks great when the columns are filled or when there's only one card present. Howev ...

Database-driven Dynamic Dropdown

I'm currently working on a project where I need to retrieve a list of names from my database for the Select component. However, I'm facing difficulties in writing the appropriate functions required for this task. The dropdown renders successfully ...

MUI: The value you have chosen for the select component is outside the acceptable range - `[object Object]`

I'm currently in the process of developing a custom Select component that offers both single and multi-selection features. Below is how I initialize the components: const vendorList = [ { label: "John", value: "668", } ...

Changing the color of a selected React Material-UI ToggleButton: A Step-by-Step Guide

I am trying to customize the color of the selected <ToggleButton ... /> to my theme's primary color, but I am facing difficulties in achieving this. Despite my efforts, the code below does not change the color to primary: ... import { ToggleBut ...

What is the preferred method of compiling Sass: utilizing the Live Sass Compiler extension in VS Code, or setting up and running Sass through npm? (Including guidance on transitioning from node-sass to dart-sass)

As I delve into an online course focused on Advanced CSS and Sass, I have noticed that the techniques being taught seem a bit outdated. The course heavily relies on node-sass in its dependencies, which is now considered deprecated. An alternative solution ...

Exploring elements using dynamic xpaths in selenium

When working with Selenium WebDriver, I am facing difficulties selecting the <input class="cs-autocomplete-input" tabindex=""> element due to its fluid ID. This is because there are multiple items with the same class name on the web page, making it c ...

Validation of files in the material-ui dropzone is causing rejection errors

I am currently using the material-ui dropzone for file uploads. I have been attempting to validate files upon drop or add, and need a way to reject them if they are deemed invalid. Unfortunately, I have not been able to figure out how to reject the files. ...

Got a value of `false` for an attribute `closable` that is not meant to be a

Here's the code snippet I have: import { Modal } from "antd"; import styled from "styled-components"; export const StANTModal = styled(Modal)` & .ant-modal-content { border-radius: 20px; overflow: hidden; } `; And ...

Typescript causing undefined React Router match issue

Currently, I am working on a basic eCommerce Proof of Concept using react and TypeScript. Unfortunately, I am facing an issue where I am unable to pass props to a product detail page or access the match containing the params. This is how my Routes pages a ...

When the mouse is moved to the UL LI list, the border color of the Top Hover is reverted back to default

Can you assist me with this issue? I need to modify the code below so that the border color remains blue while a user selects an item from the UL LI list. Here is an image showing the current problem: And here is a picture of the expected outcome: For ...

Troubleshooting CSS rendering issues on Chrome browser

Currently in the process of developing a new website based on an old template. The site appears as intended in IE, Safari, and Firefox, but for some reason Chrome is not rendering any of the css. Just to clarify, none of the links are functioning at this ...

How can I extract a value from an object that is readonly, using a formatted string as the key?

I encountered a situation where I have code resembling the following snippet. It involves an object called errorMessages and multiple fields. Each field corresponds to various error messages in the errorMessages object, but using a formatted string to retr ...