All files / roosterjs-content-model-dom/lib/formatHandlers/common ariaFormatHandler.ts

100% Statements 11/11
100% Branches 8/8
100% Functions 2/2
100% Lines 11/11

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 19 20 21 22 23 24 25 26 27            1x   78x 78x 78x 2x   78x 2x       101x 2x   101x 2x        
import type { AriaFormat } from 'roosterjs-content-model-types';
import type { FormatHandler } from '../FormatHandler';
 
/**
 * @internal
 */
export const ariaFormatHandler: FormatHandler<AriaFormat> = {
    parse: (format, element) => {
        const ariaDescribedBy = element.getAttribute('aria-describedby');
        const title = element.getAttribute('title');
        if (ariaDescribedBy) {
            format.ariaDescribedBy = ariaDescribedBy;
        }
        if (title) {
            format.title = title;
        }
    },
    apply: (format, element) => {
        if (format.ariaDescribedBy) {
            element.setAttribute('aria-describedby', format.ariaDescribedBy);
        }
        if (format.title) {
            element.setAttribute('title', format.title);
        }
    },
};