-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2070 from GSA/1904-polite-a11y-page-titles
1904 polite a11y page titles
- Loading branch information
Showing
9 changed files
with
56 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const politeTitles = (location, locale) => { | ||
// create a hidden liveRegion to announce titles to screen-readers | ||
const liveRegion = document.getElementById('live-region') | ||
|
||
// get the last part of the location Path | ||
// remove the hyphen | ||
const pathValue = location.split('/').pop() | ||
const title = pathValue.replace('-', ' ') | ||
|
||
// create language specific titles | ||
const enTitle = `Entering Benefit Finder: ${title.toLowerCase()} | USAGov` | ||
const esTitle = `Buscador de beneficios: ${title.toLowerCase()} | USAGov` | ||
const defaultTitle = `${title} | USAGov` | ||
|
||
// assign title based on locale | ||
const politeTitle = !locale | ||
? defaultTitle | ||
: locale === 'es' | ||
? esTitle | ||
: enTitle | ||
|
||
// update the live region | ||
if (liveRegion) { | ||
liveRegion.textContent = politeTitle | ||
} | ||
// update the page title | ||
document.title = politeTitle | ||
|
||
return | ||
} | ||
|
||
export default politeTitles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters