0

I am working on a React Component in which I have a DatePicker (Calendar component from PrimeReact).

I want to add an arrow on top of the datepicker that pops up. Like in the image below

enter image description here

Below is a snippet in my form :

                    <div className='form-group col-md-4 calendar-group'>
                        <FontAwesomeIcon icon={faCalendarAlt} className='l-input-icon' />
                        <Calendar 
                            className='form-control'
                            dateFormat="dd/mm/yy" 
                            value={shippingDate? shippingDate.date:shippingDate} 
                            onChange={(e) => setShippingDate({date: e.value})}
                            placeholder='Shipping Date'
                            
                        />
                    </div>

Below is the span shot of the HTML dom when the component renders enter image description here

The problem is since I am using the Calender component I add HTML elements inside that Calender's DOM.

Basically, I want to place a div (0 height and width, with thick bottom border to achieve an arrow) on top of .p-datepicker

So is it possible to add a HTML element (a div) from css without having it in the HTML doc? Or is there any other approach to achieve this?

REPLY TO anon's answer:

I can't add <div className='arrow'> since I can't inject it into the calender component.

I added the below code to the scss file:

.p-calendar{
    position: relative;
    .p-datepicker{
      margin-top: 16px;
      min-width: 270px;
      position: absolute;
      &:before {
        content: "";
        display: inline-block !important;
        width: 0;
        height: 0;
        border-bottom: 8px solid red;
        border-left: 8px solid transparent;
        border-right: 8px solid transparent;
        vertical-align: middle;
      }
    }
  }

now the the the date picker looks like this.

enter image description here

I tried adding position: absolute inside the pseudo element but it doesn't not work because I think datepicker itself is positioned as absolute.

Any idea what would fix this?

Praveen Dass
  • 586
  • 1
  • 3
  • 13
  • 1
    Does this answer your question? [How to position a CSS triangle using ::after?](https://stackoverflow.com/questions/25065661/how-to-position-a-css-triangle-using-after) – disinfor Oct 15 '20 at 17:33
  • to answer you specific question. No, you cannot manipulate the DOM ( eg: add an element ) from CSS. CSS is for styling the DOM. to manipulate it you need javascript. As for options. You have the option to use `pseudo-elements`. Something like in the answer below. – Mihai T Oct 15 '20 at 17:42

1 Answers1

1

See example below using pseudo-elements.

.arrow:after {
  content: "";
  display: inline-block !important;
  width: 0;
  height: 0;
  border-bottom: 8px solid red;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  vertical-align: middle;
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
}

.arrow{
  background: green;
  width:100%;
  position relative;
}
<div class="arrow">
   Some content
</div>
anon
  • 816
  • 5
  • 17
  • I have updated my question with the result of what I got from trying out your answer. can you please have a look at it? – Praveen Dass Oct 15 '20 at 18:30
  • @PraveenDass Yes, you will need to position it using transforms / absolute positioning. – anon Oct 15 '20 at 18:36