-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modal): add [ngbAutofocus] option (#2737)
- Loading branch information
1 parent
c585124
commit 10fd5e4
Showing
8 changed files
with
199 additions
and
29 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
demo/src/app/components/modal/demos/focus/modal-focus.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<p>First focusable element within the modal window will receive focus upon opening. | ||
This could be configured to focus any other element by adding an <code>ngbAutofocus</code> attribute on it.</p> | ||
|
||
<pre class="language-html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>button</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>button<span class="token punctuation">"</span></span> <span class="token attr-name">ngbAutofocus</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>btn btn-danger<span class="token punctuation">"</span></span> | ||
<span class="token attr-name">(click)</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>modal.close(<span class="token punctuation">'</span>Ok click<span class="token punctuation">'</span>)<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Ok<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>button</span><span class="token punctuation">></span></span></code></pre> | ||
|
||
<br /> | ||
<button class="btn btn-outline-primary mr-2" (click)="open('focusFirst')"> | ||
<div>Open confirm modal</div> | ||
<div class="text-dark" aria-hidden="true"><small>× button will be focused</small></div> | ||
</button> | ||
|
||
<button class="btn btn-outline-primary" (click)="open('autofocus')"> | ||
<div>Open confirm modal with `ngbAutofocus`</div> | ||
<div class="text-dark" aria-hidden="true"><small>Ok button will be focused</small></div> | ||
</button> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Component } from '@angular/core'; | ||
import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
@Component({ | ||
selector: 'ngbd-modal-confirm', | ||
template: ` | ||
<div class="modal-header"> | ||
<h4 class="modal-title" id="modal-title">Profile deletion</h4> | ||
<button type="button" class="close" aria-describedby="modal-title" (click)="modal.dismiss('Cross click')"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<p><strong>Are you sure you want to delete <span class="text-primary">"John Doe"</span> profile?</strong></p> | ||
<p>All information associated to this user profile will be permanently deleted. | ||
<span class="text-danger">This operation can not be undone.</span> | ||
</p> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-outline-secondary" (click)="modal.dismiss('cancel click')">Cancel</button> | ||
<button type="button" class="btn btn-danger" (click)="modal.close('Ok click')">Ok</button> | ||
</div> | ||
` | ||
}) | ||
export class NgbdModalConfirm { | ||
constructor(public modal: NgbActiveModal) {} | ||
} | ||
|
||
@Component({ | ||
selector: 'ngbd-modal-confirm-autofocus', | ||
template: ` | ||
<div class="modal-header"> | ||
<h4 class="modal-title" id="modal-title">Profile deletion</h4> | ||
<button type="button" class="close" aria-label="Close button" aria-describedby="modal-title" (click)="modal.dismiss('Cross click')"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<p><strong>Are you sure you want to delete <span class="text-primary">"John Doe"</span> profile?</strong></p> | ||
<p>All information associated to this user profile will be permanently deleted. | ||
<span class="text-danger">This operation can not be undone.</span> | ||
</p> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-outline-secondary" (click)="modal.dismiss('cancel click')">Cancel</button> | ||
<button type="button" ngbAutofocus class="btn btn-danger" (click)="modal.close('Ok click')">Ok</button> | ||
</div> | ||
` | ||
}) | ||
export class NgbdModalConfirmAutofocus { | ||
constructor(public modal: NgbActiveModal) {} | ||
} | ||
|
||
const MODALS = { | ||
focusFirst: NgbdModalConfirm, | ||
autofocus: NgbdModalConfirmAutofocus | ||
}; | ||
|
||
@Component({ | ||
selector: 'ngbd-modal-focus', | ||
templateUrl: './modal-focus.html' | ||
}) | ||
export class NgbdModalFocus { | ||
withAutofocus = `<button type="button" ngbAutofocus class="btn btn-danger" | ||
(click)="modal.close('Ok click')">Ok</button>`; | ||
|
||
constructor(private _modalService: NgbModal) {} | ||
|
||
open(name: string) { | ||
this._modalService.open(MODALS[name]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters