fix(a11y): add title attribute to iframes (#45014)

* fix:add title attribute to iframes
This commit is contained in:
Bruce B
2022-02-08 02:22:54 -08:00
committed by GitHub
parent 5a25d0b847
commit 7d817cb237
2 changed files with 37 additions and 7 deletions

View File

@@ -208,7 +208,13 @@ export function updateProjectPreview(buildData, document) {
buildData.challengeType === challengeTypes.html ||
buildData.challengeType === challengeTypes.multiFileCertProject
) {
createProjectPreviewFramer(document)(buildData);
// Give iframe a title attribute for accessibility using the preview
// document's <title>.
const titleMatch = buildData?.sources?.index?.match(
/<title>(.*?)<\/title>/
);
const frameTitle = titleMatch ? titleMatch[1] + ' preview' : 'preview';
createProjectPreviewFramer(document, frameTitle)(buildData);
} else {
throw new Error(
`Cannot show preview for challenge type ${buildData.challengeType}`