Skip to content
Snippets Groups Projects
Commit f3a7e1d0 authored by Marlène SIMONDANT's avatar Marlène SIMONDANT
Browse files

fix(accessibility): slugify checkbox id/for attributes

parent 2f25367d
No related branches found
No related tags found
2 merge requests!907V3.2.0,!872fix(accessibility): slugify checkbox id/for attributes
......@@ -4,7 +4,7 @@
<app-label-checkbox
*ngFor="let filter of filtersTypes"
[label]="filter"
[for]="filter"
[for]="filter | slugify"
[checked]="isFilterChecked(filter)"
[size]="'small'"
(action)="toggleCheckbox(filter)"
......
import { DayPipe } from './day.pipe';
import { PhonePipe } from './phone.pipe';
import { SlugifyPipe } from './slugify.pipe';
import { UrlPipe } from './url.pipe';
import { UserNamePipe } from './userName.pipe';
export { DayPipe, PhonePipe, UrlPipe, UserNamePipe };
export { DayPipe, PhonePipe, SlugifyPipe, UrlPipe, UserNamePipe };
export const SharedPipes = [DayPipe, PhonePipe, UrlPipe, UserNamePipe];
export const SharedPipes = [DayPipe, PhonePipe, SlugifyPipe, UrlPipe, UserNamePipe];
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'slugify',
})
export class SlugifyPipe implements PipeTransform {
transform(value: string): string {
if (!value) return '';
// Remove accents
const withoutAccents = value.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
// Use a regex to create the slug
return withoutAccents
.toLowerCase()
.trim()
.replace(/[^a-z0-9\s-]/g, '') // Remove special characters
.replace(/[\s-]+/g, '-') // Replace spaces and multiple hyphens with a single hyphen
.replace(/^-+/, '') // Trim hyphens from the start
.replace(/-+$/, ''); // Trim hyphens from the end
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment