MapComplete/src/Utils/ariaLabel.ts

28 lines
696 B
TypeScript
Raw Normal View History

import { Translation } from "../UI/i18n/Translation"
2023-12-21 17:36:43 +01:00
import { Store } from "../Logic/UIEventSource"
export function ariaLabel(htmlElement: Element, t: Translation) {
2023-12-21 17:36:43 +01:00
ariaLabelStore(htmlElement, t?.current)
}
export function ariaLabelStore(htmlElement: Element, t: Store<string>) {
if (!t) {
return
}
let destroy: () => void = undefined
2023-12-21 17:36:43 +01:00
t?.mapD(
(label) => {
htmlElement.setAttribute("aria-label", label)
2023-12-21 17:36:43 +01:00
// Set the tooltip, which is the 'title' attribute of an html-element
htmlElement.setAttribute("title", label)
},
[],
(f) => {
destroy = f
}
)
return { destroy }
}