Adjust the default color for the icon in the v-text-field type=date using Vuetify

I need to filter records between two dates, displaying data retrieved from the backend. Instead of following the traditional method outlined in Vuetify's date pickers documentation or using the CodePen example:

Vuetify v-text-field Date Picker on CodePen

I have simplified it by only utilizing a

v-text-field type="date"
as shown in the code below:

HTML:

<template>
    <v-layout align-start>
        <v-flex>
            <v-toolbar flat color="grey darken-4">
                <v-toolbar-title>History</v-toolbar-title>
                <v-divider class="mx-4" inset vertical></v-divider>
                <v-spacer></v-spacer>
                From: 
                <v-text-field type="date" class="text-xs-center ml-2 mr-4" v-model="startDate"></v-text-field>
                To: 
                <v-text-field type="date" class="text-xs-center ml-2 mr-4" v-model="endDate"></v-text-field>
                <v-btn @click="list()" color="primary" class="ml-2 mb-2">Search</v-btn>
            </v-toolbar>
          </v-flex>
    </v-layout>
</template>

JS:

<script>
    import axios from 'axios'
    export default {
        data(){
            return{
                startDate:'',
                endDate:''
            }
        },

        created () {
            this.list();
        },

        methods:{
            list(){
                let me=this;
                let header={"Authorization" : "Bearer " + this.$store.state.token};
                let configuration= {headers : header};
                let url='';
                if(!me.startDate || !me.endDate){
                    url='api/Sales/List';
                }
                else{
                    url='api/Sales/SalesHistory/'+me.startDate+'/'+me.endDate;
                }
                axios.get(url,configuration).then(function(response){
                    me.sales=response.data;
                }).catch(function(error){
                    console.log(error);
                }); 
            }
        }
    }
</script>

This setup allows me to filter records based on the selected date range.

https://i.sstatic.net/thQMf.png

The only problem I have encountered is that when switching to the Dark theme, the default black calendar icon, serving as an append-icon button, does not change to white like in Vuetify's documentation example:

https://i.sstatic.net/3mBye.png

Upon checking GitHub, I noticed that a user suggested adding color props for append prepend icons in v-text-field, but it was marked as wontfix with an unsatisfactory response. Adding an

append-icon="date_range"
only introduced another colored icon next to the default one and disrupted the date picker functionality. Also, applying the readonly property to prevent users from manually entering dates caused issues with the date picker functionality as well.

How can I change the color of the calendar icon?

Answer №1

Here is the link to the codepen example: codepen link

Implementing a Global Dark Mode Theme

Based on your screenshot, it seems like your date modal is still in light mode even after toggling to "dark" mode. To avoid manually marking individual components as "dark", consider setting the dark mode theme globally with <v-app>.

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  created () {
    this.$vuetify.theme.dark = true
    // Alternatively, set theme based on the user's browser settings
    // this.$vuetify.theme.dark = window.matchMedia('(prefers-color-scheme)').media !== 'not all'
  },
})


Vuetify is known for its opinionated styling and complex scss variables. Changing variable colors, especially in dark mode, often requires going through predefined methods.

Customizing Icon Colors in v-textfield with Slots

To customize the color of a specific icon within a textfield, utilize the slots feature of v-textfield (detailed here) and pass in a v-icon with the desired color prop.

For a more personalized user experience, use this.$vuetify.theme.dark within your component to dynamically switch between light and dark themes.

Answer №2

The icon you're referring to is actually not generated by the VTextField component. Instead, it is a part of the default <input> element.

If you want to keep using the VTextField's default <input> for the datepicker, there is currently no direct way to modify the color of the icon. However, you can adjust the icon's background color using CSS. You can target it with the

::-webkit-calendar-picker-indicator
selector and explore a couple of solutions.

Option 1: Lighten the background color of the icon

You can lighten the background color of the icon to grey, which enhances its visibility in dark mode:

.theme--dark input[type="date"]::-webkit-calendar-picker-indicator {
  background-color: #ccc;
}

See demo 1

Option 2: Replace the icon image

Another approach is to change the icon image to a brighter PNG icon for dark mode:

.theme--dark input[type="date"]::-webkit-calendar-picker-indicator {
  background: url(https://img.icons8.com/cotton/64/000000/calendar.png) no-repeat;
  background-size: 24px 24px;
}

See demo 2

Answer №3

To achieve a darker appearance for your text field, simply include the dark property:

  <v-text-field dark type="date" class="text-xs-center ml-2 mr-4" v-model="startDate">
  </v-text-field>

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

The VueJS front-end is left waiting for a response from the NodeJS backend that never

Having some trouble setting up a login feature in my web application. The backend is using a MongoDB database and NodeJS (express), while the front-end uses VueJS. However, I'm facing an issue where the response from the backend isn't reaching th ...

Passing events from a VueJs 3 grandchild component to its grandparent component

I'm still getting the hang of Vue and diving into my initial project. I'm currently focusing on constructing a form that involves multiple child and grandchild components. The issue arose when I realized I needed to generate multiple copies of th ...

Extract keys from the string

Is there a better way to extract keys from a string? const {Builder, By, Key, until} = require('selenium-webdriver'); ... const obj = {val: 'Key.SPACE'} if(obj.val.startsWith('Key.'))obj.val = eval(obj.val); (...).sendKeys(obj ...

Implementing relationships in microservices with Prisma and NestJS

Schema for User Management service: model User { id String @id @default(uuid()) username String @unique email String @unique password String } Schema for File Management service: model File ...

What's the deal with dynamic prop values in React?

In my React application, I am trying to set a dynamic prop value. My goal is to use the first item in an array called Fruits and concatenate it with 'prop' to create the prop value. For example: ApplesProp index.js const ApplesProp = { Name: "G ...

Issues with the Node Package Manager's watch command functionality

Having installed the frontend dependency in my Vue.js project, I attempted to run the command npm run watch. I updated the scripts section in package.json as shown below- "scripts": { "dev": "npm run development", &qu ...

Utilize moment.js to format a datetime and display the corresponding timezone

I'm having trouble displaying timezones correctly using moment.js. I attempted to use the following code: var result = moment(someDate).format("MM/DD/YYYY HH:mm A Z"); This returns something like: 08/05/2015 06:18 PM +02:00, which is okay, but I w ...

What are some strategies for pinpointing the cause of a regular expression validation failure?

Can the specific type of error (e.g. text too short, invalid characters) that caused a regular expression match failure, like the ones listed below, be identified? regexes = { name: /^[a-zA-Z0-9_ -]{3,32}$/, title: /^[a-zA-Z0-9_ -]{3,128}$/, ...

Elements with v-for directive failing to display

I am attempting to incorporate a component using v-for. The data source infoTexts is structured as an Object where the locale code serves as the key and the corresponding message is the value. For example: { nl: 'Text in Dutch', fr: &apo ...

Issue encountered during app creation using the command line interface

After successfully installing nodejs and checking the versions of nodejs, npm, and npx, I proceeded to run the command npm install -g create-react-app which executed without any issues. However, when I attempted to create a new React app using create-react ...

Error: webpack-cli encountered an unrecognized argument along with a syntax error

Hello, I am currently delving into the realm of prestashop theme development. After setting up my local environment successfully, everything seems to be working fine. My next step is to create a new theme based on the classic default theme. Upon navigat ...

Issue with Vue and Firebase: New users are being created successfully, but are being logged into existing user accounts

I've encountered a strange issue in Firebase. When I create a new user with the same password as an existing user, the new user is logged in under the previous user's account and displays all their information. However, upon logging out and signi ...

Tips for aligning meshes to the left and ensuring responsiveness in three.js

Currently working on a website using three.js, I'm facing an issue where I can't seem to align and make the mesh responsive simultaneously. My current approach to alignment is: cube.position.x = -20 However, when I try resizing the window, the m ...

What methods are available for transferring information between nodejs and puppeteer?

Recently, I developed a nodejs application that kicks off from index.js. Within index.js, puppeteer is launched and bot.js is injected into a headless-api page using the addScriptTag function. In my implementation, index.js sets a cookie to pass initial v ...

Using VueJS to apply filters to an object causes a decrease in my application's performance

Recently, I've been working on implementing a filter for a search bar. However, I've noticed that whenever I input something into the search bar, there is a noticeable delay as it loads the entries. I'm not sure if this issue is related to ...

Interference + brochure + plotly - temporary clicks

I have come across a reproducible example that I found at the following link: https://bl.ocks.org/timelyportfolio/5ab450e90ee510f4df9758b9ec5a8ad0. library(sf) library(plotly) library(leaflet) library(crosstalk) library(htmltools) boroughs_data <- st_ ...

Drag to rotate using JavaScript when the mouse is pressed down

I am experimenting with making a spinning wheel rotate as the user drags the mouse over it. The wheel consists of 3 pieces, so I have individually mapped each image to target the specific section of the wheel that I want to rotate. Currently, it is funct ...

``tips for concealing the sidebar on a Vue.js application`

Welcome everyone, I am a newcomer to Vue and have decided to use a CoreUI admin panel to work on some cool Vue projects. However, I have hit a roadblock while working on the nav.js file. export default { items: [ { ...

Verify record removal without a PHP click

My website features a navigation menu that streamlines the browsing experience: <form action="../"> <select onchange="window.open(this.options[this.selectedIndex].value,'_top')"> <option value="" selected="selected">Navigate< ...

Ways to showcase additional content

When I receive a JSON Object containing posts from a WordPress account, it only includes about 15 posts. What steps can I take to retrieve more than that amount? The structure of the JSON data is as follows: { ID: 4164, title: "24 Hour Non-Stop with Ma ...