Bug in PrimeNG calendar occurs when trying to apply a CSS class from Bootstrap

Encountering a peculiar issue with displaying a DatePicker using PrimeNG in my application. Whenever I attempt to utilize bootstrap's form-control, a visual glitch occurs.

Below is the template being used:

<div class="form-group row">
    <div class="form-group col-md-2">
        <label for="valeur">Valeur</label>
        <input type="number" id="valeur" class="form-control" />
    </div>

    <div class="form-group col-md-5">
        <label for="dateDebut">Date de début</label>
        <p-calendar id="dateDebut" dateFormat="dd/mm/yy" styleClass="form-control" [showIcon]="true"></p-calendar>
    </div>

    <div class="form-group col-md-5">
        <label for="dateFin">Date de fin</label>
        <p-calendar id="dateFin" dateFormat="dd/mm/yy" styleClass="form-control" [showIcon]="true"></p-calendar>
    </div>
</div>

This results in:

https://i.sstatic.net/4uGAp.png

EDIT

If you need further insight, find the generated HTML below:

<div class="form-group col-md-5" _ngcontent-scp-1="">
   <label for="dateDebut" _ngcontent-scp-1="">Date de début</label>
   <p-calendar ng-reflect-show-icon="true" ng-reflect-date-format="dd/mm/yy" ng-reflect-style-class="form-control" styleclass="form-control" id="dateDebut" dateformat="dd/mm/yy" _ngcontent-scp-1="">
      <!--template bindings={
         "ng-reflect-ng-if": "true"
         }-->
      <span ng-reflect-initial-classes="form-control" class="form-control ui-calendar" ng-reflect-raw-class="ui-calendar">
         <input id="dp1467976345328" ng-reflect-value="" class="hasDatepicker ui-inputtext ui-widget ui-state-default ui-corner-left" ng-reflect-raw-class="[object Object]" type="text"><!--template bindings={
            "ng-reflect-ng-if": "true"
            }--><button ng-reflect-icon="fa-calendar" type="button" pbutton="" class="ui-datepicker-trigger ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only"><span class="ui-button-icon-left ui-c fa fa-fw fa-calendar"></span><span class="ui-button-text ui-c">ui-button</span></button>
      </span>
      <!--template bindings={
         "ng-reflect-ng-if": "false"
         }-->
   </p-calendar>
</div>

Answer №1

I have implemented a solution that has been successful in both Internet Explorer and Chrome:

<p-calendar [inputStyle]="{'width':'55%'}" ...

Give it a try!

Answer №2

PrimeNG's calendar component provides users with four styling options, including two for inline styles and two for adding CSS classes - style, styleClass, inputStyle, and inputStyleClass.

  • style and styleClass are meant to style the calendar component itself
  • inputStyle and inputStyleClass are used to style the input field of the calendar

This behavior should not be considered a bug; it is the intended functionality as you may have been using the incorrect attribute. To apply the form-control class to the input field of PrimeNG's calendar, use the inputStyleClass instead of styleClass:

<div class="form-group col-md-5">
    <label for="dateFin">End Date</label>
    <p-calendar id="dateFin" dateFormat="dd/mm/yy" inputStyleClass="form-control" [showIcon]="true"></p-calendar>
</div>

You can find the complete list of attributes for PrimeNG's calendar component here.

Answer №3

  1. Specify the css class using the "inputStyleClass" property

<p-calendar inputStyleClass="form-control"></p-calendar>

  1. If you are not utilizing an Inline form, customize the "ui-calendar" css class
.ui-calendar {
    display: block;
}

Answer №4

After some trial and error, I found a solution that worked for me. By adjusting the CSS styling and adding the form-control class to the inputStyleClass attribute, I was able to properly position the icon.

.ui-calendar button {
    right: 0;
    top: 0;
}
.ui-calendar {
    width: 100%;
}

<p-calendar dateFormat="dd/mm/yy" showTime="showTime" hourFormat="24" formControlName="start" [showIcon]="true" inputStyleClass="form-control"></p-calendar>

Answer №5

Using Primeng 11 with Bootstrap 4.

Customize CSS:

.p-calendar {
  width: 100%;
  height: 36px;
}

Avoid the need to specify styleClass for the p-calendar:

<div class="form-group col-md-5">
    <label for="dateFin">End Date</label>
    <p-calendar inputId="dateFin" dateFormat="dd/mm/yy" [showIcon]="true"></p-calendar>
</div>

Answer №6

Hey everyone, I wanted to share a helpful tip for coding. Here's how I use it in my code:

Make sure to include styleClass and inputStyleClass like so:

<p-calendar styleClass="form-control" inputStyleClass="form-control" ></p-calendar>

Additionally, try adjusting some CSS properties. In my case, I did the following:

.ui-inputtext{ 
      margin:-7px -12px; 
     }

.ui-button, button.ui-button.ui-state-default, .ui-button.ui-state-default{ 
    top:0px;
    right: -1px; 
  }

.ui-calendar button{ 
      width: 2.5em; 
   }

After making these adjustments, here is the resulting appearance.

Answer №7

Extending on @Srefan Svrkota's response. An alternative approach is to create a new CSS class that overrides the inline style of the form-control class.

    .setInlineCalendar
    {
    display: inline !important;
    }

and then assign it to the calendar input using : inputStyleClass="form-control setInlineCalendar"

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

versatile grid tiles with CSS flexibility

Trying to remove the svg elements while keeping the grid layout intact. The svgs are used to maintain a 1:1 aspect ratio for all tiles. UPDATE: Discovered a CSS Solution for this. Simply set aspect-ratio: 1 for the tiles. Is there an alternative soluti ...

Do you know the name of the jQuery tool that Mashable employs for showcasing their top 5 images and videos?

Recently, I came across an image scroller on Mashable that caught my eye and I am interested in incorporating it into a new project: I saw it in action on the website, but I am curious about what it actually is. Does anyone know if it is available as a W ...

Tips for Including a Parallax Image Within a Parallax Section

Currently, I am working on implementing a parallax effect that involves having one image nested inside another, both of which will move at different speeds. My progress has been somewhat successful, however, the effect seems to only work on screens narrowe ...

Styling Text with Shadow Effects in Mobile Web Browsers

I'm attempting to apply a text-stroke effect using text-shadow like this: .text-stroke { text-shadow: -1px -1px 0 white, 1px -1px 0 white, -1px 1px 0 white, 1px 1px 0 white; } Unfortunately, it's not rendering correctly on mobile versions of Fi ...

The database is receiving new information, however, it is not being visually represented on the frontend

After making updates to my user details, I noticed that the changes are reflected in the collection data but not on the page when I refresh. However, upon logging out and back in, the updated information is displayed correctly. For some reason, the compone ...

Main content with a floating aside menu

I am currently using the CoreUI admin template. The layout I have set up is the basic one outlined on the following page: My goal is to make the aside menu appear on the right side of the main content, floating over it rather than inline and reducing the ...

Using Angular Universal with Prerender.io fails to display HTML content inside component tags

I have recently developed an Angular Universal application with nested components. My main issue now is that when using Prerender.io, it only returns the top-level component tags and not the HTML content within them. This seems to be a common problem for ...

How to stop a div from shifting downwards with CSS

Within my Web Application, I have implemented HTML code that displays different texts above input fields based on certain conditions. However, the issue I am facing is that the input fields are being shifted down by the text. I want the input fields to al ...

Page designed for displaying small star ratings in JSP

In the realm of my star.jsp page, the style.css is its trusty companion, faithfully executing its duties. However, a desire has crept into my heart - I yearn for the stars to shrink in size. The Chronicles of My Code star.jsp <!DOCTYPE html> ...

Browsing through different backdrop visuals

I realize this question has been brought up numerous times before, but I urge you to take a moment and read through it. Currently, I am looking to add more interactivity to my HTML page. My goal is to change the background image every five seconds with a ...

Enhance your calendar with sleek jQuery styling

Currently, I am utilizing the jQuery-ui.css (smoothness) solely for the calendar CSS. Can anyone provide me with a comprehensive list of all the calendar CSS functions available in it? I'm looking to avoid using any unnecessary CSS that might be causi ...

What is the best way to achieve consistent width in a material-ui card component?

How can I ensure that all these cards have the same width? https://i.stack.imgur.com/Ns3zw.png I'm experiencing an issue with achieving uniform card widths when using flexbox in material-ui. How can I resolve this? Is it necessary to utilize Grid fo ...

What is the best method to extract a query parameter from the ActivatedRoute snapshot within the Angular app component?

Is there a way to retrieve a query parameter in my app.component synchronously without using ActivatedRoute's queryParamMap observable? I tried using the route snapshot like this: const param = this.route.snapshot.queryParamMap.get('param') ...

Issues with Organizing Bootstrap Card Layout

I'm in need of assistance with creating a responsive Bootstrap card grid. My goal is to have a grid layout with 6 cards, initially displayed as 2 rows of 3 cards. As the screen size decreases, I want the layout to adjust accordingly to maintain reada ...

Unexpected behavior observed in ng-select when pasting search values

When attempting to update an array of strings acting as the model for an ng-select, the values do not appear correctly in the search box. https://i.sstatic.net/WqdJ6.png The values that are displaying correctly are the ones selected from the dropdown men ...

A guide to adjusting the font size and placement of text in a precise manner

Is there a way to adjust the font size and position in a particular text? How can this be achieved? doc.text( 40, 30, "jspdf" ); https://i.stack.imgur.com/Io7RE.png ...

Eliminating data containers from Google Maps

How can I hide the white info boxes (1 and 2) on my Google Map? I attempted using the following CSS code below, but it doesn't seem to be effective: .place-card { display:none; } Is there a different approach I should take? ...

Make the HTML element expand to the remaining height of the viewport

Need help with creating a section that automatically fills the remaining viewport height below the navigation bar. The section includes a centered div and background image, along with a button at the bottom for scrolling down by one full viewport height. H ...

Is it possible to nest forkJoins within another forkJoin call?

I have implemented a route resolver in this manner, where I want to make two additional HTTP requests based on the initial response from forkjoin. I attempted to nest another forkjoin inside the first one, but I am open to suggestions on better approache ...

What is the process for altering the color of an ion-label using a script?

I want to be able to dynamically change the color of a label that displays {{person.name}} based on user interaction in my .Ts file. When I click a button, I add the user to an array and want their name to change color to indicate they are selected. Below ...