I need to show a tooltip which is a Html list on hover.
I can show the date highlighted and a simple message but the list wont show at all. It has to do with the bootstrap. If I remove bootstrap then it shows but I need bootstrap in the app. Is there any way to show a list in a tooltip on hover with bootstrap?
Here is the code
export class DatepickerDateClassExample {
list: string =
"Date - (3)<br/>" +
"Names - (4)<br/>" +
"Addresses - (25)<br>" +
"Values - (30)";
constructor(private renderer: Renderer2) {}
dates = [
{ date: "2020-04-20", text: this.list }
];
dateClass = (d: Date) => {
const dateSearch = this.dateToString(d);
return this.dates.find(f => f.date == dateSearch)
? "example-custom-date-class"
: undefined;
};
displayMonth() {
let elements = document.querySelectorAll(".endDate");
let x = elements[0].querySelectorAll(".mat-calendar-body-cell");
x.forEach(y => {
const dateSearch = this.dateToString(
new Date(y.getAttribute("aria-label"))
);
const data = this.dates.find(f => f.date == dateSearch);
if (data) y.setAttribute("aria-label", data.text);
});
}
streamOpened(event) {
setTimeout(() => {
let buttons = document.querySelectorAll("mat-calendar .mat-icon-button");
buttons.forEach(btn =>
this.renderer.listen(btn, "click", () => {
setTimeout(() => {
//debugger
this.displayMonth();
});
})
);
this.displayMonth();
});
}
dateToString(date: any) {
return (
date.getFullYear() +
"-" +
("0" + (date.getMonth() + 1)).slice(-2) +
"-" +
("0" + date.getDate()).slice(-2)
);
}
Css:
::ng-deep .example-custom-date-class {
background: orange;
border-radius: 100%;
}
.tooltip
{
display: none;
position: absolute;
text-align: center;
margin-top: 30px;
width: 155px;
padding: 10px;
z-index: 2000;
box-shadow: 0px 0px 4px #222;
border-radius: 10px;
background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #eeeeee),color-stop(1, #cccccc));
background-image: -webkit-linear-gradient(top, #eeeeee, #cccccc);
color: gray;
}
.tooltip:before {
content: '';
display: block;
position: absolute;
left: 10px;
top: -20px;
width: 0;
height: 0;
border: 9px solid transparent;
border-bottom-color: #cccccc;
}
Html:
<mat-form-field class="example-full-width" >
<input matInput [matDatepicker]="picker" placeholder="Choose a date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker (opened)="streamOpened($event)" [dateClass]="dateClass" #picker panelClass="endDate" ></mat-datepicker>
</mat-form-field>
<div #toolTip class="tooltip" (mouseover)="onTool=true"
(mouseout)="onTool=false"
[style.display]="show || onTool?'inline-block':'none'" [innerHTML]="toolTipMessage">
</div>
Here is the stackblitz