I want autofocus to button on Modal
like this:
....
<div class="modal-footer">
<button [autofocus] id="btnDelete" type="button" class="btn btn-success" (click)="active()">OK</button>
</div>
but It not show, so how I can focus on button on Modal?
I afraid I don't know
I faced the same issue, to autofocus the input element.
I found workaround
<button class="btn btn-success btn sp-action-button" (click)="inputNameFocus(); NameModal.show() ">Open modal</button>
<div class="modal-body">
<label>Name</label>
<input type="text" id="inputName" name="inputName" placeholder="Name" [(ngModel)]="name" >
</div>
inputNameFocus() {
setTimeout(() => {
document.getElementById('inputName').focus();
}, 500);
}
I got i worked by calling the focus() on the onShown event.
this.modal.onShown.pipe(
tap(() => (document.querySelector('[autofocus]') as HTMLElement).focus())
).subscribe());