File

projects/isy-angular-widgets/src/lib/skip-links/skip-links.component.ts

Description

Component that provides a set of skip links for accessibility purposes. Allows users to quickly navigate to specific sections of the page.

Example :
<isy-skip-links
ariaLabel="{{ 'isyAngularWidgetsDemo.skipLinks.ariaLabel' | translate }}"
[links]="skipLinks"
></isy-skip-links>

Metadata

Index

Properties
Methods
Inputs

Inputs

ariaLabel
Type : string
links
Type : SkipTarget[]
Default value : []

Methods

focusTarget
focusTarget(event: Event, target: string)
Parameters :
Name Type Optional
event Event No
target string No
Returns : void

Properties

configService
Type : unknown
Default value : inject(WidgetsConfigService)

A service used to translate labels within the widgets library.

import {Component, inject, Input} from '@angular/core';
import {SkipTarget} from './model/model';
import {WidgetsConfigService} from '../i18n/widgets-config.service';

/**
 * Component that provides a set of skip links for accessibility purposes.
 * Allows users to quickly navigate to specific sections of the page.
 * @example
 * ```html
 * <isy-skip-links
  ariaLabel="{{ 'isyAngularWidgetsDemo.skipLinks.ariaLabel' | translate }}"
  [links]="skipLinks"
></isy-skip-links>
 * ```
 */
@Component({
  selector: 'isy-skip-links',
  templateUrl: './skip-links.component.html',
  styleUrls: ['./skip-links.component.scss']
})
export class SkipLinksComponent {
  @Input() links: SkipTarget[] = [];
  @Input() ariaLabel?: string;

  /**
   * A service used to translate labels within the widgets library.
   */
  configService = inject(WidgetsConfigService);

  focusTarget(event: Event, target: string): void {
    event.preventDefault();
    const el = document.querySelector(target) as HTMLElement;

    if (el) {
      el.scrollIntoView({behavior: 'smooth', block: 'start'});

      if (!el.hasAttribute('tabindex')) {
        el.setAttribute('tabindex', '-1');
      }

      el.focus();
    } else {
      console.warn(
        `[SkipLinksComponent]: Target '${target}' not found. Please check if the element with '${target}' exists in the DOM.`
      );
    }
  }
}
<nav class="skip-links" [attr.aria-label]="configService.getTranslation('hauptfenster.aria.skipLinksAriaLabel')">
  @for (link of links; track link.target) {
    <a [href]="link.target" (click)="focusTarget($event, link.target)" class="skip-link">
      {{ link.label }}
    </a>
  }
</nav>

./skip-links.component.scss

.skip-links {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1000;
}

.skip-link {
  position: absolute;
  min-width: 250px;
  text-align: center;
  left: 0;
  top: -40px;
  background-color: var(--p-primary-color);
  color: #fff;
  padding: var(--isyfact-space-sm) var(--isyfact-space-md);
  text-decoration: none;
  font-size: 1rem;
  z-index: 1001;
  transition:
    top 0.3s ease,
    opacity 0.3s ease;
  opacity: 0;
}

.skip-link:focus {
  top: 0;
  opacity: 1;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""