Conceal the input field in a Vue.js datepicker

In my Vue project, I am utilizing the vuejs-datepicker component. My goal is to hide the default input field and display the Calendar only when the user clicks a button. To achieve this, I have placed the <datepicker/> within a div and applied CSS to the div in order to hide it.

<div class="datePickerDiv">
   <datepicker class="date" ref="datepick"></datepicker>
</div>

<style scoped>
.datePickerDiv {
  position: relative;
  float: left;
  margin-top: -40px;
}
.datePickerDiv input {
  border: none;
  background: transparent;
}
</style>

However, the current setup is not functioning as expected. You can view a sample at this link.

Answer №1

To effectively target the input tag within a nested element, you must utilize the `>>>` combinator:

.datePickerDiv >>> input {
  border: none;
  background: transparent;
}

This approach is necessary when applying styles to nested elements while using the scoped attribute in your style tag. The scoped attribute restricts styling to only direct child components of your current Vue component. In the case of the datepicker component creating its own child input, the deep selector demonstrated above is required for proper styling.

Answer №2

To add styling to your date picker tag, utilize the attribute input-class instead of just using the class attribute. The styles will not be applied to default scoped style tags, so make sure to include another style tag below your scoped style tag like this:

<style scoped>
---your scoped Styles ----
</style>

<style >
-- Add your unscoped style for vue date picker here ---
</style>

For instance,

<datepicker input-class="date" ref="datepick"></datepicker>
<style>
.date {
  display: none !important;
}
</style>

Answer №3

To hide the input element, add the prop input-class with the class hide-input. This will apply the hide-input class to the input element. For more details on props, click here.

<datepicker input-class="hide-input"></datepicker>
.hide-input{
  display: none !important;
}

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

A guide to verifying a user's age using JavaScript by collecting information from 3 separate input fields

On page load, only the year input is required for users to fill in. The user can enter their birth year first without providing the month and day. Currently, I have a function that checks if a person is over 16 years old by comparing their birth year with ...

A different way to center elements using CSS

Many criticize the center tag, but I find that it consistently aligns things perfectly for me. Despite its deprecation, I still rely on it. I've come across suggestions to use the mysterious CSS margin: 0 auto;, but I struggle to make it work (refer ...

Tips for positioning text at the bottom of a div without specifying a set height

I plan to extract the style later. My goal is to understand how to achieve this using pure HTML. I would like the Select and Description labels to be aligned with the bottom of the green box. Unfortunately, neither vertical-align: bottom; nor position: ab ...

Customizing Axios actions in Vue JS using a variable

I have a form in my Vue component that sends a reservation object to my API for storage. I am exploring the possibility of setting the axios action dynamically based on a variable's value, without duplicating the entire axios function (as both the pos ...

I need to condense my layout from three columns to just two columns in HTML

The html code for "Date Accessed" is meant to be in one column as a header, while the actual dates should be in another column, but somehow they are all appearing in a single column. I am having trouble figuring out why. <!DOCTYPE html> {% load stati ...

Modify the property of an element during execution

I am tasked with developing a button that can change the type of a chart component (e.g., from columns to pie) upon clicking. However, I am unsure how to implement this functionality within the component structure. The goal is to modify the :series-default ...

How to horizontally align Yii's CHtml radioButtonList using CSS

I am currently using yii framework for my development and I have encountered an issue. While writing CSS, I was able to align my <input tags in HTML properly. However, when I applied the same CSS to yii, the alignment got messed up. Can anyone offer som ...

sticky navigation causing issues with tab functionality

Currently in the process of developing a website with a rather intricate sticky navigation bar. The JavaScript code being utilized to achieve this functionality is as follows: // Code for creating a sticky navigation bar document.addEventListener("s ...

Implementing event handling with .On() in Jquery following .Off()

I need assistance with my responsive navigation bar. I am having trouble with the jQuery code to disable hover events if the width is less than or equal to 768px and enable it for desktop screens. $(window).on('load resize', function (e) { v ...

Tips for submitting a form remotely using Radix Alert Dialog and the form attribute

Currently, I have integrated a Radix UI's Alert Dialog in my Next.js 13 app to confirm the deletion of a contact from the user's contact list: Take a look at the Alert Dialog modal here However, there seems to be an issue with the delete button ...

What is the best way to handle images overflowing a div

I am currently working on creating a carousel using React, where the content images are aligned horizontally. If I have 3 image tags within a div with a width of 1200px, how can I effectively control these images to ensure they fit within the container div ...

Nuxtjs is experiencing issues with the functionality of Vuex-module-decorator

After exploring various solutions for nearly 3 days, I decided to implement my Vuex modules as classes to enhance the cleanliness and readability of my code. One helpful resource I found was the section on accessing modules with NuxtJS in this document: ht ...

Customizing the jQuery Datepicker to only allow a predefined set of dates

I am looking for assistance regarding the jQuery datepicker. I have an array of dates and I need to disable all dates except for the ones in this specific array. Currently, the code I have does the opposite of what I need. I generate the array of dates in ...

JavaScript's jQuery selector retrieves a child element from one location and adds it to a different

Why does the Jquery children selector select the img element, extract it, remove it, and then append it to another div element? Shouldn't it create a copy of the element being appended? var $anchors = $("#imageGallery a"); var $overlay = $('&l ...

Tips for adjusting Default ASP page size in Visual Studio for big screens?

My ASP page is not fitting the entire screen on large screens. How do I make it responsive? The CSS file contains the following styling: /* DEFAULTS ----------------------------------------------------------*/ body { background: #b6b7bc; ...

Reposition the checked box to the top of the list

My goal is to click on each item, and the selected item should move to the top of the list and be rendered at the top. However, I encountered an issue where when clicking on an item, it moves to the top but the item that replaces it also gets checked. Bel ...

The CSS overflow property is a great tool to demonstrate how a box can be neatly cut off at its

According to the specifications outlined in this resource, In situations where overflow occurs, the 'overflow' property determines if a box is clipped to its padding edge. Additionally, it specifies whether or not a scrolling mechanism will b ...

Tips for swapping out text with a hyperlink using JavaScript

I need to create hyperlinks for certain words in my posts. I found a code snippet that does this: document.body.innerHTML = document.body.innerHTML.replace('Ronaldo', '<a href="www.ronaldo.com">Ronaldo</a>'); Whil ...

How can I animate scrolling up or down using jQuery and CSS?

I have a a element that triggers an action when clicked: <a href="#" class="hel" onclick="YPCP1_();">Scroll down</a> Also, function YPCP_(){ var scroll = $(window).scrollTop(); window.scrollTo(0, 600); } The function successfully sc ...

Working with Vue 3 Composition API: manipulating an array of objects

I am working with an array stored in an external JSON file named "West.json" { "west" : [ { "id" : 1, "state": "CA" }, { "id" : 2, ...