I have 4 buttons in a row in HTML of my Angular 8 Component.I am using ant design (antd) library.
What I Want ?
I want to change the background-color of button when it is
clicked.
Previously pressed button should return to original styling when
other button is pressed. And newly pressed should be highlighted
by changing background-color
Contraint
I want to achieve this without click-event method.I want to do this purely CSS(styling) based like giving buttons id and class and then implementing it ?
I checked few stack-overflow posts relevant to this problem but those did't helped. Few using hover and active classes
HTML
<div class="row">
<div class="col-md-1 col-sm-1">
<button (click)="redirectToHub1()" type="button" class="ant-btn ant-btn-primary ant-btn-lg"
ant-click-animating-without-extra-node="false" ><span>Hub 1</span></button>
</div>
<div class="col-md-1 col-sm-1">
<button (click)="redirectToHub2()" type="button" class="ant-btn ant-btn-primary ant-btn-lg"
ant-click-animating-without-extra-node="false" >Hub2</button>
</div>
<div class="col-md-1 col-sm-1">
<button (click)="redirectToHub3()" type="button" class="ant-btn ant-btn-primary ant-btn-lg"
ant-click-animating-without-extra-node="false" >Hub 3</button>
</div>
<div class="col-md-1 col-sm-1">
<button (click)="redirectToHub4()" type="button" class="ant-btn ant-btn-primary ant-btn-lg"
ant-click-animating-without-extra-node="false" >Hub 4</button>
</div>
</div>
Typescript
redirectToHub1() {
this.router.navigate(["/hubs/hub1"], {
queryParams: { id: `${this.hubCode}` },
});
}
redirectToHub2() {
this.router.navigate(["/hubs/hub2"], {
queryParams: { id: `${this.hubCode}` },
});
}
redirectToHub3() {
this.router.navigate(["/hubs/hub3"], {
queryParams: { id: `${this.hubCode}` },
});
}
redirectToHub2() {
this.router.navigate(["/hubs/hub4"], {
queryParams: { id: `${this.hubCode}` },
});
}
Current Display
Required Display
It works fine with below styling but when I add (click)="redirectToHub()" methods it does't work
.ant-btn:active, .redirect_btn:focus{
background: blue;
}
Please fins the sample, this will be helpful.
.btn {
border: 1px solid blue;
background: #e7e7e7;
outline: none;
}
.btn:active, .btn:focus{
background: blue;
}
<button class="btn">Test 1</button>
<button class="btn">Test 2</button>
<button class="btn">Test 3</button>
<button class="btn">Test 4</button>
<button class="btn">Test 5</button>
Related
Html code:
<div class="col-md-4" *ngFor="let card of allCards">
<p class="card-text">Card Color: {{card.color}}</p>
<button type="button" class="btn btn-sm btn-primary product-btn" (click)="addCard()">Add Card</button>"
Here I also want to bind the value "card.color" into another variable (maybe using ngModel) so that I can use it inside my typescript file in angular 8.
I tried the below but not working:
<p class="card-text" [(ngModel)]="cardColor">Card Color: {{card.color}}</p>
You could send the contents to the button click event's handler.
Template (*.html)
<div class="col-md-4" *ngFor="let card of allCards">
<p class="card-text">Card Color: {{card.color}}</p>
<button
type="button"
class="btn btn-sm btn-primary product-btn"
(click)="addCard(card.color)"
>
Add Card
</button>
Controller (*.ts)
addCard(color: any) {
// use `color` here
}
I am working on signature pad dialogue box and for the dialogue box i am using bootstrap modal. In this activity when i click on complete activity a dialogbox should open asking yes or no on clicking yes a dialog box with signaturepad in modal body and clear button in modal footer.
the problem is when clicking on clear button from modal footer the clear method of signaturepad module is not working Any suggestions would be of great help
import { Component, OnInit, ViewChild, Directive } from '#angular/core';
import { NgbModalConfig, NgbModal } from '#ng-bootstrap/ng-bootstrap';
import {SignaturePad} from 'angular2-signaturepad/signature-pad';
import { ClickOutsideModule } from 'ng-click-outside';
#Component({
selector: 'app-modal',
templateUrl: './modal.component.html',
styleUrls: ['./modal.component.css']
})
export class ModalComponent {
#ViewChild('SignaturePad1', { static: true })signaturepad: SignaturePad;
public signaturepadoption = {
minWidth: 2,
penColor: 'rgb(255,0,0)',
backgroundColor: 'rgb(0,0,0)',
canvasWidth: 250,
canvasHeight: 300,
};
closeResult: string;
constructor(private modalService: NgbModal) {}
openSm(content) {
this.modalService.open(content, { centered: true });
}
SignaturepadPopUp(longContent) {
this.modalService.open(longContent, { scrollable: true, centered: true });
}
onClear() {
this.signaturepad.clear();
}
saveSignature() {
const base64 = this.signaturepad.toDataURL('image\png', 0.1);
console.log(base64);
const blob = this.base64toblob(base64);
console.log(blob);
}
base64toblob(base64) {
const bytestring = atob(base64.split(',')[1]);
const stringtype = base64.split(',')[0].split(':')[1].split(':')[0];
const size = bytestring.length;
const saveString: any[] = new Array(size);
for (let i = 0; i < bytestring.length; i++) {
saveString[i] = bytestring.charAt(i);
}
const ia = new Uint8Array(saveString);
return new Blob([ia], {type: stringtype});
}
}
<ng-template #content let-modal>
<div class="modal-header">
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Are you sure You want to complete Activity?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)="modal.close('Close click')">No</button>
<button type="button" class="btn btn-primary" (click)="SignaturepadPopUp(longContent)">Yes</button>
</div>
</ng-template>
<ng-template #longContent let-modal>
<div class="modal-header">
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="col-md-12">
<div class="m-signature-pad">
<div class="m-signature-pad-body">
<signature-pad #SignaturePad1 [options]="signaturepadoption"></signature-pad>
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-primary" (click)="onClear()">clear</button>
</ng-template>
<button class="btn btn-secondary" (click)="openSm(content)">Complete Activity</button>
The reason this happens is because ng-template is not rendered yet and thus the signature pad will be undefined. A way I found to work around this is to create my signature pad in a separate component and then add that component to the ngbModal.
So in your example:
<ng-template #longContent let-modal>
<div class="modal-header">
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="col-md-12">
<div class="m-signature-pad">
<div class="m-signature-pad-body">
<!-- <signature-pad #SignaturePad1 [options]="signaturepadoption"></signature-pad> -->
<app-my-signature-pad-component></app-my-signature-pad-component> <!-- In this component you add the above commented out line and then do your functionality for the signature pad there. -->
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-primary" (click)="onClear()">clear</button>
</ng-template>
I found that with this approach, you are able to use the ViewChild and don't get the undefined issue.
Hope this makes sense!
My modal window is blocking my time picker on Angular
Component.ts
open() {
const amazingTimePicker = this.atp.open();
amazingTimePicker.afterClose().subscribe(time => {
console.log(time);
});
}
// Triggering the modal window
createApplication(content) {
this.modalService.open(content, {centered: true, size: 'lg'});
}
Modal html
<ng-template #create let-modal>
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">Job Application</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form #createApplicationForm="ngForm" (ngSubmit)="createApplicationForm.form.valid && createForm(createApplicationForm)" >
<div class="form-group">
<div class="input-group">
<input class="form-control" id="preferredContactDate" name="preferredContactDate"
[(ngModel)]="newApplicationFormDateModel" ngbDatepicker #preferredContactDate="ngbDatepicker">
<div class="input-group-append">
//Open time picker here
<button class="btn btn-secondary" (click)="open()"
type="button"></button>
</div>
</div>
</div>
<div class="modal-footer">
<!-- Submit button -->
<input class="btn btn-dark" type="submit" value="Create" />
<button type="button" class="btn btn-dark" (click)="modal.dismiss('Cross click')">Cancel</button>
</div>
</form>
</div>
</ng-template>
However, when i do this, the time picker gets blocked by the modal.
Any ideas?
Stackbliz for timepicker - https://stackblitz.com/edit/amazing-timepicker-example
Referenced to: https://www.npmjs.com/package/amazing-time-picker
Modal: https://ng-bootstrap.github.io/#/components/modal/examples
Update based on answer:
<div class="time-picker">
<input atp-time-picker value="19:00"/>
</div>
CSS
.time-picker {
position:absolute;
z-index : 99999999;
}
.my-custom-class{
z-index: 900;
}
I also tried inline style as well
<input style= "z-index: 99999999;" atp-time-picker value="19:00"/>
We need to get the bootstrap's z-index dynamically and increment it with some arbitrary number and set to the time-picket something like below:
$(document).on('show.bs.modal', '.modal', function (event) {
const zIndex = 1045 + (10 * $('.modal:visible').length);
// this zIndex can be assigned to the time-picker
$(this).css('z-index', zIndex);
setTimeout(function () {
$('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack');
}, 0);
});
you can specify a custom class for the modal to overwrite the z-index.
example:
in your js/ts:
this.modalService.open(content, {backdropClass: 'my-custom-class'});
css:
.my-custom-class{
z-index: 900;
}
Your issue is similar to the one mentioned here : https://github.com/owsolutions/amazing-time-picker/issues/129
The proposed solution, as think win win explained, was to increase the timepicker's z-index :
time-picker {
position:absolute;
z-index : 99999999;
}
How to Implement Drag and Drop for a bootstrap modal dialog.. So user can drag a file from the windows explorer.
At Present there is an EDIT button and if Click on that Edit button a modal dialog will open and in that I ahve to implement DRag and DRop.So that user can drag a file from the windows explorer.
#Input() isUploadImage: boolean;
#Output() openImageUploadModal = new EventEmitter();
onUploadBtnClick(){
this.openImageUploadModal.emit('Open');
}
openImageUploadModal(content) {
this.modalService.open(content, { centered: true });
}
// fileChangeEvent(event: any): void {
// this.imageChangedEvent = event;
// }
imageCropped(event: ImageCroppedEvent) {
if (event.base64.indexOf('data:image/jpeg;base64,') > -1) {
this.croppedImage = event.base64.split('data:image/jpeg;base64,')[1];
} else {
this.croppedImage = event.base64.split('data:image/png;base64,')[1];
}
}
imageLoaded() {
this.cropperReady = true;
}
loadImageFailed() {
}
saveCroppedImage() {
this.imagePath = this.croppedImage;
this.myprofile.Photo = this.editPhoto === this.croppedImage ? this.editPhoto : this.croppedImage;
console.log('this.createNewProfile: ', this.createNewProfile);
this.advisorbranding.saveUpdateBrand(this.myprofile, this.createNewProfile).
subscribe(() => {
console.log('Profile Image updated..');
}, (err) => {
console.log('save Api failed, err: ', err);
});
}
deletPhoto() {
this.editPhoto = ProfileImageData.defaultImage;
// this.croppedImage = this.editPhoto;
// this.saveCroppedImage();
}
<div class="outer-div-for-the-imgae-icon">
<app-image [imagesrc]="imagePath" [isUploadImage]="true" (openImageUploadModal)="openImageUploadModal(content)" style="width : 38%; margin-top: 30px;"
class="d-none d-sm-block" alt="..." ></app-image>
</div>
<div class="upload-icon" *ngIf="isUploadImage" (click)="onUploadBtnClick()" >
<i class="fa fa-pencil fa-lg img-upload-icon" aria-hidden="true"> EDIT</i>
</div>
<input #inputFile id="filereader" type="file" (change)="onFileChange($event)" style="visibility: hidden;" />
<ng-template #content let-modal >
<div class="modal-header">
<h4 class="modal-title">Edit Photo</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="image-upload-modal">
<image-cropper
[imageBase64]="'data:image/png;base64,' + editPhoto"
[maintainAspectRatio]="true"
[aspectRatio]="4 / 3"
[resizeToWidth]="128"
[roundCropper]="false"
format="png"
outputType="both"
(imageCropped)="imageCropped($event)"
(imageLoaded)="imageLoaded()"
(loadImageFailed)="loadImageFailed()"
style="max-height: 33vh"
[style.display]="cropperReady ? null : 'none'"
></image-cropper>
<h6 style="color: white;font-size: 10px;text-align: center; position: relative;
top: 10px;">Drag a reposition photo</h6>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light button" (click)="deletPhoto();">DELETE PHOTO</button>
<button type="button" class="btn btn-light buttonbg" (click)="inputFile.click();">UPLOAD NEW</button>
<button type="button" class="btn btn-light" (click)="modal.close('Close click'); saveCroppedImage();">SAVE PHOTO</button>
</div>
</ng-template>
I would hide a buttons except the last one . But when I put mouse over prevous elements, they get displayed.
Here's my html
<p-growl [(value)]="msgs"></p-growl>
<div class="center" appMcard>
<h2> Select Group (s) name(s) </h2>
<form [formGroup]="GroupRMPM_FG" class="form">
<div formArrayName="GroupId_Name" *ngFor="let control of GroupRMPM_FG.controls.GroupId_Name.controls; let i= index" >
<input type="text" pInputText [formControl]="control.controls.Group_Id_Name"/>
<button pButton type="button" class="delete-btn " *ngIf="GroupRMPM_FG.controls.GroupId_Name.controls.length > 1" (click)="deleteGroup(i)" icon="fa-minus" >
</button>
<button *ngIf="GroupRMPM_FG.controls.GroupId_Name.controls.length == i+1" pButton type="button" (click)="addNewGroup()" icon="fa-plus" class="add-btn formcontainer"></button>
<button *ngIf="GroupRMPM_FG.controls.GroupId_Name.controls.length != i+1" pButton type="button" class="dummyElement" icon="fa-plus" ></button>
<button *ngIf="GroupRMPM_FG.controls.GroupId_Name.controls.length == 1" pButton type="button" class="dummyElement" icon="fa-plus" ></button>
</div>
</form>
<div>
I have created a "dummy element" so that the content is centred in the right way when I get only a "plus" icon .
Here's the CSS:
.dummyElement, .dummyElement:hover{
background-color:transparent;
border-color: transparent;
cursor:none;
color: transparent;
}
Here's what I get
Also the cursor is disappearing when I'm over the button.
In my Browser dev tool show me this :
For information I use primeNg Button.
Please use pointer-events: none; instead of cursor:none as below;
.dummyElement, .dummyElement:hover{
background-color:transparent;
border-color: transparent;
pointer-events: none;
color: transparent !important;
}
It seems like your CSS is overwritten by another CSS rule. Try to add !important to your CSS:
.dummyElement, .dummyElement:hover{
background-color:transparent;
border-color: transparent;
cursor:none;
color: transparent !important;
}