-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client(fix): the skip-links target should not be generally accessible…
… via the TAB key (#688)
- Loading branch information
Showing
15 changed files
with
97 additions
and
74 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './skip-links-target.directive'; | ||
export * from './skip-links.component'; |
37 changes: 37 additions & 0 deletions
37
client/src/app/layout/skip-links/skip-links-target.directive.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,37 @@ | ||
import { Directive, ElementRef, inject, OnDestroy } from '@angular/core'; | ||
|
||
@Directive({ | ||
selector: '[appSkipLinksTarget]', | ||
exportAs: 'appSkipLinksTarget', | ||
host: { | ||
'[style.outline]': '"none"', | ||
}, | ||
standalone: true, | ||
}) | ||
export class SkipLinksTargetDirective implements OnDestroy { | ||
private elementRef = inject<ElementRef<HTMLElement>>(ElementRef); | ||
|
||
private tabIndexObserver = new MutationObserver(() => { | ||
if (this.elementRef.nativeElement.tabIndex === 0) { | ||
// Let's call the `focus` method once the `elementRef` is focusable | ||
this.elementRef.nativeElement.focus({ preventScroll: true }); | ||
} | ||
}); | ||
|
||
constructor() { | ||
this.tabIndexObserver.observe(this.elementRef.nativeElement, { attributeFilter: ['tabindex'] }); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.tabIndexObserver.disconnect(); | ||
} | ||
|
||
focus() { | ||
// The `focus` method of the directive, simply makes the `elementRef` temporarily focusable, by setting its `tabindex` attribute. | ||
// While the `focus` method of the `elementRef.nativeElement` is actually performed in the `MutationObserver` callback. | ||
this.elementRef.nativeElement.tabIndex = 0; | ||
|
||
// The `elementRef` should not be generally accessible via the TAB key. | ||
setTimeout(() => this.elementRef.nativeElement.removeAttribute('tabindex'), 500); | ||
} | ||
} |
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,4 @@ | ||
<a (click)="focusTarget()" (keydown.enter)="focusTarget()" tabindex="0" class="app-skip-links__link"> | ||
<ng-container i18n="@@Component.SkipLinks.Link">Accéder au contenu principal</ng-container> | ||
<mat-icon class="app-skip-links__icon">step_over</mat-icon> | ||
</a> |
29 changes: 29 additions & 0 deletions
29
client/src/app/layout/skip-links/skip-links.component.scss
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,29 @@ | ||
.app-skip-links { | ||
&__link { | ||
position: fixed; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
z-index: 9999; | ||
padding: 1rem; | ||
border-radius: 0.5rem; | ||
background-color: var(--sys-secondary); | ||
color: var(--sys-on-secondary); | ||
text-decoration: none; | ||
font-size: 1.125rem; | ||
cursor: pointer; | ||
|
||
top: -9999px; | ||
opacity: 0; | ||
transition: ease 300ms opacity; | ||
|
||
&:focus-visible { | ||
top: 4rem; | ||
opacity: 1; | ||
} | ||
} | ||
|
||
&__icon { | ||
margin-left: 0.5rem; | ||
vertical-align: bottom; | ||
} | ||
} |
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,19 @@ | ||
import { Component, input, ViewEncapsulation } from '@angular/core'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
import { SkipLinksTargetDirective } from './skip-links-target.directive'; | ||
|
||
@Component({ | ||
selector: 'app-skip-links', | ||
standalone: true, | ||
imports: [MatIconModule], | ||
templateUrl: './skip-links.component.html', | ||
styleUrls: ['./skip-links.component.scss'], | ||
encapsulation: ViewEncapsulation.None, | ||
}) | ||
export class SkipLinksComponent { | ||
target = input<SkipLinksTargetDirective>(); | ||
|
||
protected focusTarget() { | ||
this.target()?.focus(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
client/src/app/layout/skip-to-main-content/skip-to-main-content.component.html
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
client/src/app/layout/skip-to-main-content/skip-to-main-content.component.scss
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
client/src/app/layout/skip-to-main-content/skip-to-main-content.component.ts
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
client/src/app/layout/skip-to-main-content/skip-to-main-content.constants.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
client/src/app/layout/skip-to-main-content/skip-to-main-content.directive.ts
This file was deleted.
Oops, something went wrong.
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