Skip to content

Commit

Permalink
feat(a11y): support adding a title attribute to the iframe
Browse files Browse the repository at this point in the history
COMUI-752
  • Loading branch information
katie-bobbe-genesys committed Dec 3, 2021
1 parent ef8597d commit fb267ec
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion client-app-example/ifc-cli.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = function(frameRouter) {
)}`,
assignedRoute: '/app2',
allow: 'camera http://localhost:8080;', // optional
sandbox: 'allow-presentation allow-modals' // optional
sandbox: 'allow-presentation allow-modals', // optional
title: 'iframe Application 2 Example' // optional, but needed for accessibility
}
},
{
Expand Down
15 changes: 15 additions & 0 deletions src/FrameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ class FrameManager {
this._iframe.setAttribute('sandbox', newSandbox);
}

/**
* String for the `title` attribute to be added to the <iframe> element
* Ex: "Manage Preferences"
*
* See [<iframe> Accessibility Concerns](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#accessibility_concerns)
*
* @param title String for the `title` attribute added to the `<iframe>` element.
*/
public setFrameTitle(title?: string): void {
if (typeof title !== 'string') {
title = '';
}
this._iframe.setAttribute('title', title);
}

/**
* Navigates the wrapped iframe to the provided location in a
* way that does not affect the host application's history.
Expand Down
13 changes: 11 additions & 2 deletions src/HostRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export class HostRouter {
url: applyRoute(client.url, clientRoute),
assignedRoute: client.assignedRoute,
allow: client.allow,
sandbox: client.sandbox
sandbox: client.sandbox,
title: client.title
};
}
});
Expand All @@ -60,6 +61,8 @@ export interface ClientTarget {
allow?: string;
/** iframe's sandbox directive to be merged with defaults */
sandbox?: string;
/** iframe's title attribute */
title?: string;
}

/**
Expand Down Expand Up @@ -100,6 +103,11 @@ export interface ClientRegistration {
* for this client. Values wll be merged with built-in defaults.
*/
sandbox?: string;
/**
* Sets the iframe's [title](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#accessibility_concerns) attribute.
* This is required for accessibility.
*/
title?: string;
}

/**
Expand Down Expand Up @@ -151,7 +159,8 @@ function parseRegistration(key: string, value: ClientRegistration): ClientInfo {
url: value.url,
assignedRoute: normalizeRoute(value.assignedRoute),
allow: value.allow,
sandbox: value.sandbox
sandbox: value.sandbox,
title: value.title
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/elements/frame-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ export default class FrameRouterElement extends HTMLElement {
this._frameManager.setFrameAllow(
(clientInfo && clientInfo.allow) || undefined
);
this._frameManager.setFrameTitle(
(clientInfo && clientInfo.title) || undefined
);

this.dispatchEvent(
new CustomEvent('frameTransition', { detail: newLocation })
Expand Down

0 comments on commit fb267ec

Please sign in to comment.