All files / packages/theme-selector/src accessibility.ts

100% Statements 7/7
100% Branches 6/6
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18                      6x 5x 5x 5x      
// SPDX-License-Identifier: MIT
/**
 * Accessibility enhancements
 */
 
import { DOM_SELECTORS } from './constants.js';
 
/**
 * Enhances accessibility for code blocks
 */
export function enhanceAccessibility(documentObj: Document): void {
  documentObj.querySelectorAll(DOM_SELECTORS.HIGHLIGHT_PRE).forEach((pre) => {
    if (!pre.hasAttribute('tabindex')) pre.setAttribute('tabindex', '0');
    if (!pre.hasAttribute('role')) pre.setAttribute('role', 'region');
    if (!pre.hasAttribute('aria-label')) pre.setAttribute('aria-label', 'Code block');
  });
}