Flo*_*low 5 typescript ng-bootstrap ng-modal angular
我们刚刚将应用程序升级到了angular 7,我们注意到所有ngBootstrap模态现在都默认自动关闭按钮,如下图所示。
这是我的代码:
html模态代码:
<form [formGroup]="storeForm" novalidate>
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Modal Test</h4>
<button type="button" class="close" aria-label="Close"
(click)="activeModal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h4>Todo</h4>
</div>
<div class="modal-footer">
<button role="button" type="submit" class="btn btn-primary"
(click)="activeModal.close('Finish click')" prevent-double-
submit>{{ 'store.add.finish' | translate }}</button>
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
以及如何通过我的component.ts调用模式
const modal = this._modalService.open(ModalComponent, { backdrop:
'static', size: 'lg'});
modal.result.then(
(data) => {
// some code
},
() => {
}
);
Run Code Online (Sandbox Code Playgroud)
我的问题是如何删除这种不符合我们预期行为的默认自动对焦?
感谢您的阅读,请原谅拼写错误。
Kld*_*Kld 13
出于可访问性和键盘导航的原因,需要将焦点放在模式内。默认情况下,焦点位于模式中的第一个可聚焦元素上,在您的情况下为关闭按钮。您可以将ngbAutofocus属性添加到想要焦点所在的元素。
<button type="button" ngbAutofocus class="btn btn-danger"
(click)="modal.close('Ok click')">Ok</button>
Run Code Online (Sandbox Code Playgroud)
您可以在github上阅读更多内容
如果您不介意关闭按钮实际聚焦但想要摆脱丑陋的轮廓,您可以使用outline: none.
template.html:
<button type="button" aria-label="Close">Close</button>
Run Code Online (Sandbox Code Playgroud)
styles.css:
button[aria-label="Close"]:focus {
outline: none;
}
Run Code Online (Sandbox Code Playgroud)
小智 7
这是一个丑陋的黑客,但您可以添加一个不可见的元素作为第一个元素:
<input type="text" style="display:none" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3049 次 |
| 最近记录: |