Topic: Modal Keyboard Issue and solution
modals
Angular2
i wanted to pass a configuration based on my requirements to the modal so i added the following to the modalDirective.ts
public setConfiguration(config) {
this._config = {
backdrop: config.backdrop || true,
keyboard: config.keyboard || true,
focus: true,
show: config.show || true,
ignoreBackdropClick: false
};
}
problem is the keyboard JUST NEVER WORKS so i had to change the OnEsc
method to the following
// todo: consider preventing default and stopping propagation
@HostListener('keydown.esc')
public onEsc(): void {
if (this.config.backdrop !== 'static') {
this.hide();
}
}
I do not like this hack, but it seems to be the only solution. Please give it a look and advice if there is a better solution.
Cheers
Magdalena Obalska
answered 8 years ago
mog5808
pro answered 8 years ago
keyboard
as i sometimes need it true
and other times false
Cheers
Magdalena Obalska
answered 8 years ago
[config]="{keyboard: false}"
added to the main div, so it's not possible to close it when the escape key is pressed. You can change 'false' to 'true', of course.
<button md-ripple type="button" class="btn btn-primary relative" (click)="basicModal.show()" ripple-radius>Basic Example</button>
<div bsModal #basicModal="bs-modal" [config]="{keyboard: false}" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myBasicModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close pull-right" aria-label="Close" (click)="basicModal.hide()">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title w-100" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer flex-column">
<button type="button" class="btn btn-secondary ml-auto" aria-label="Close" (click)="basicModal.hide()" ripple-radius>Close</button>
<button md-ripple type="button" class="btn btn-primary relative ml-auto" ripple-radius>Save changes</button>
</div>
</div>
</div>
</div>
mog5808
pro answered 8 years ago
Magdalena Obalska
answered 8 years ago
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
- User: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: No