Fix input switch accessibility

This commit is contained in:
Chocobozzz 2023-11-27 08:37:20 +01:00
parent 11f40299c5
commit 05d6520b22
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
7 changed files with 23 additions and 5 deletions

View File

@ -12,6 +12,7 @@
<div>
<my-input-switch
[label]="getWebLabel(notificationType)"
[inputName]="'web-notification-' + notificationType"
[(ngModel)]="webNotifications[notificationType]"
(ngModelChange)="updateWebSetting(notificationType, webNotifications[notificationType])"
@ -20,6 +21,7 @@
<div *ngIf="emailEnabled">
<my-input-switch
[label]="getEmailLabel(notificationType)"
[inputName]="'email-notification-' + notificationType"
[(ngModel)]="emailNotifications[notificationType]"
(ngModelChange)="updateEmailSetting(notificationType, emailNotifications[notificationType])"

View File

@ -116,6 +116,14 @@ export class MyAccountNotificationPreferencesComponent implements OnInit {
return this.user.hasRight(rightToHave)
}
getWebLabel (notificationType: keyof UserNotificationSetting) {
return `Toggle web notification for "${this.labelNotifications[notificationType]}"`
}
getEmailLabel (notificationType: keyof UserNotificationSetting) {
return `Toggle email notification for "${this.labelNotifications[notificationType]}"`
}
updateEmailSetting (field: keyof UserNotificationSetting, value: boolean) {
if (value === true) this.user.notificationSettings[field] |= UserNotificationSettingValue.EMAIL
else this.user.notificationSettings[field] &= ~UserNotificationSettingValue.EMAIL

View File

@ -32,7 +32,7 @@ export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
ngAfterViewChecked () {
if (window.location.hash && window.location.hash !== this.lastScrollHash) {
this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
// this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
this.lastScrollHash = window.location.hash
}

View File

@ -7,7 +7,11 @@
[ngbTooltip]="autoPlayNextVideoTooltip" placement="bottom-right auto"
>
<span i18n>AUTOPLAY</span>
<my-input-switch class="small" inputName="autoplay-next-video" [(ngModel)]="autoPlayNextVideo" (ngModelChange)="switchAutoPlayNextVideo()"></my-input-switch>
<my-input-switch
i18n-label label="Toggle autoplay next video"
class="small" inputName="autoplay-next-video"
[(ngModel)]="autoPlayNextVideo" (ngModelChange)="switchAutoPlayNextVideo()"
></my-input-switch>
</div>
</div>

View File

@ -1,2 +1,4 @@
<input type="checkbox" role="switch" [checked]="checked" [name]="inputName" [id]="inputName" (change)="update()" [disabled]="preventUpdate" />
<label [for]="inputName" class="ms-auto">Toggle</label>
<div class="root">
<input type="checkbox" role="switch" [checked]="checked" [name]="inputName" [id]="inputName" (change)="update()" [disabled]="preventUpdate" />
<label [for]="inputName" class="ms-auto">{{ label }}</label>
</div>

View File

@ -3,7 +3,8 @@
input {
position: absolute;
top: -100px;
width: 0;
height: 0;
left: -100px;
+ label {

View File

@ -17,6 +17,7 @@ export class InputSwitchComponent implements ControlValueAccessor {
@Input() checked = false
@Input() inputName: string
@Input() preventUpdate = false
@Input() label = $localize`Toggle`
propagateChange = (_: any) => { /* empty */ }