Skip to content Skip to sidebar Skip to footer

How To Show Calendar Popup When Input[type="date"] Is On Focus

Is there a way to activate the native HTML5 date picker dropdown on focus of an input element? Large Input Element: Currently I can only utilize the calendar on click of an arrow

Solution 1:

For anyone who stumbles across this, I solved it (webkit only firefox also seems to respect this) by making the calendar-picker-indicator the full height and width of the input, as outlined here.

.input-containerinput {
    border: none;
    box-sizing: border-box;
    outline: 0;
    padding: .75rem;
    position: relative;
    width: 100%;
}

input[type="date"]::-webkit-calendar-picker-indicator {
    background: transparent;
    bottom: 0;
    color: transparent;
    cursor: pointer;
    height: auto;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    width: auto;
}
<inputtype="date">

Full-Width Clickable Calendar Dropdown

Solution 2:

input[type="date"] {
        position: relative;
    }

    /* create a new arrow, because we are going to mess up the native one
    see "List of symbols" below if you want another, you could also try to add a font-awesome icon.. */input[type="date"]:after {
        content: "\25BC"; 
        color: #555;
        padding: 05px;
    }

    /* change color of symbol on hover */input[type="date"]:hover:after {
        color: #bf1400;
    }

    /* make the native arrow invisible and stretch it over the whole field so you can click anywhere in the input field to trigger the native datepicker*/input[type="date"]::-webkit-calendar-picker-indicator {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        height: auto;
        color: transparent;
        background: transparent;
    }

    /* adjust increase/decrease button */input[type="date"]::-webkit-inner-spin-button {
        z-index: 1;
    }

    /* adjust clear button */input[type="date"]::-webkit-clear-button {
        z-index: 1;
    }

Post a Comment for "How To Show Calendar Popup When Input[type="date"] Is On Focus"