-
Notifications
You must be signed in to change notification settings - Fork 38
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 more autofocus options (#1324)
* fix(modal): prevent close button auto focus * feat(modal): extend autofocus option * feat(modal): add autofocus example * feat(modal): add autofocus example * feat(modal): add autofocus test * fix(modal): make initial focused element visible * fix(modal): make initial focused element visible * fix(modal): make initial focus work on voiceover * fix(modal): make initital focus work on voiceover * fix(modal): fallback focus to dialog * fix(modal): add note for aria-label on voiceover
- Loading branch information
1 parent
5866d47
commit a2eb516
Showing
10 changed files
with
249 additions
and
29 deletions.
There are no files selected for viewing
Empty file.
59 changes: 59 additions & 0 deletions
59
projects/ng-aquila/documentation/examples/modal/modal-autofocus/modal-autofocus-example.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,59 @@ | ||
<button | ||
nxButton="small" | ||
class="nx-margin-right-xs" | ||
(click)="openFromTemplate('dialog')" | ||
> | ||
dialog (false) | ||
</button> | ||
<button | ||
nxButton="small" | ||
class="nx-margin-right-xs" | ||
(click)="openFromTemplate('first-tabbable')" | ||
> | ||
first-tabbable (true) - default | ||
</button> | ||
<button | ||
nxButton="small" | ||
class="nx-margin-right-xs" | ||
(click)="openFromTemplate('first-heading')" | ||
> | ||
first-heading | ||
</button> | ||
<button | ||
nxButton="small" | ||
class="nx-margin-right-xs" | ||
(click)="openFromTemplate('.custom-content')" | ||
> | ||
custom selector | ||
</button> | ||
|
||
<ng-template #template> | ||
<div nxModalContent> | ||
<h3 nxHeadline="subsection-medium" class="nx-modal-margin-bottom"> | ||
Autofocus when the modal is opened | ||
</h3> | ||
<p nxCopytext="small" class="nx-modal-margin-bottom"> | ||
Elements inside this modal will receive focus based on the value of | ||
the autofocus property. | ||
</p> | ||
<p class="custom-content">Custom selector</p> | ||
</div> | ||
<div nxModalActions> | ||
<button | ||
nxModalClose | ||
class="nx-margin-bottom-0 nx-margin-right-xs" | ||
nxButton="small secondary" | ||
type="button" | ||
> | ||
Cancel | ||
</button> | ||
<button | ||
nxModalClose | ||
class="nx-margin-bottom-0" | ||
nxButton="small" | ||
type="button" | ||
> | ||
Proceed | ||
</button> | ||
</div> | ||
</ng-template> |
47 changes: 47 additions & 0 deletions
47
projects/ng-aquila/documentation/examples/modal/modal-autofocus/modal-autofocus-example.ts
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,47 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
TemplateRef, | ||
ViewChild, | ||
} from '@angular/core'; | ||
import { NxButtonComponent } from '@aposin/ng-aquila/button'; | ||
import { NxCopytextComponent } from '@aposin/ng-aquila/copytext'; | ||
import { NxHeadlineComponent } from '@aposin/ng-aquila/headline'; | ||
import { | ||
AutoFocusTarget, | ||
NxDialogService, | ||
NxModalActionsDirective, | ||
NxModalCloseDirective, | ||
NxModalContentDirective, | ||
} from '@aposin/ng-aquila/modal'; | ||
|
||
/** | ||
* @title Modal autofocus Example | ||
*/ | ||
@Component({ | ||
selector: 'modal-autofocus-example', | ||
standalone: true, | ||
imports: [ | ||
NxButtonComponent, | ||
NxModalContentDirective, | ||
NxHeadlineComponent, | ||
NxCopytextComponent, | ||
NxModalActionsDirective, | ||
NxModalCloseDirective, | ||
], | ||
templateUrl: './modal-autofocus-example.html', | ||
styleUrl: './modal-autofocus-example.css', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ModalAutofocusExampleComponent { | ||
@ViewChild('template') templateRef!: TemplateRef<any>; | ||
|
||
constructor(private readonly dialogService: NxDialogService) {} | ||
|
||
openFromTemplate(focus: AutoFocusTarget | string): void { | ||
this.dialogService.open(this.templateRef, { | ||
autoFocus: focus, | ||
showCloseIcon: true, | ||
}); | ||
} | ||
} |
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
3 changes: 1 addition & 2 deletions
3
projects/ng-aquila/src/modal/dialog/modal-container.component.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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
<ng-template cdkPortalOutlet></ng-template> | ||
@if (_config.showCloseIcon) { | ||
<button #closeButton [attr.aria-label]="_config.closeIconButtonLabel" (click)="_closeButtonClick()" class="nx-modal__close" type="button"> | ||
<nx-icon name="close" aria-hidden="true"></nx-icon> | ||
</button> | ||
} | ||
|
||
<ng-template cdkPortalOutlet></ng-template> |
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
Oops, something went wrong.