Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♿ [#2372] Fix dyslexia data-attributes for toggling accessible label #1464

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/open_inwoner/js/components/accessibility/change_font.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export class ChangeFont {
static selector = '.accessibility--change-font'

constructor(node) {
this.node = node
this.text = node.querySelector('.link__text')
Expand All @@ -9,6 +10,8 @@ export class ChangeFont {
change(event) {
event.preventDefault()
let root = document.documentElement

// Variable names for font families
const bodyFontFamily = '--oip-typography-sans-serif-font-family'
const headingFontFamily = '--utrecht-heading-font-family'
// Start of legacy styles
Expand All @@ -20,25 +23,34 @@ export class ChangeFont {
const defaultHeadingFont = 'Heading'

if (root.style.getPropertyValue(bodyFontFamily) === openDyslexicFont) {
// Switch back to default font
root.style.setProperty(bodyFontFamily, defaultBodyFont)
root.style.setProperty(headingFontFamily, defaultHeadingFont)
root.style.setProperty(oipBodyFontFamily, defaultBodyFont)
root.style.setProperty(oipHeadingFontFamily, defaultHeadingFont)

// Update text content, aria-label, and title
this.text.innerText = this.node.dataset.text
this.node.setAttribute('aria-label', this.node.dataset.text)
this.node.setAttribute('title', this.node.dataset.text)
} else {
// Switch to Dyslexic font
root.style.setProperty(bodyFontFamily, openDyslexicFont)
root.style.setProperty(headingFontFamily, openDyslexicFont)
root.style.setProperty(oipBodyFontFamily, openDyslexicFont)
root.style.setProperty(oipHeadingFontFamily, openDyslexicFont)

// Update text content, aria-label, and title
this.text.innerText = this.node.dataset.altText
this.node.setAttribute('aria-label', this.node.dataset.altText)
this.node.setAttribute('title', this.node.dataset.altText)
}
}
}

/**
* Controls the toggling of Dyslexia font when button is clicked
*/

document
.querySelectorAll(ChangeFont.selector)
.forEach((readmoreToggle) => new ChangeFont(readmoreToggle))
.forEach((changeFontButton) => new ChangeFont(changeFontButton))
Loading