Files
wekan/client/components/main/uiFont.js
T
Lauri Ojansivu 144777ae6b Member Settings: a per-member switch to hide the focus outline.
Change Settings has Show focus outline, on by default: the blue ring round the
focused control is an accessibility feature (WCAG 2.4.7), and it also shows
after a click on a minicard. A member who turns it off - profile.hideFocusOutline,
a toggle method that takes the signed-in user only - gets a class on body that
hides the outline and its halo for them and nobody else. The label is translated
into every language file (best effort; the low-confidence ones are listed in the
changelog).

Thanks to mimZD and xet7 !

Refs #6755,
2026-11-03 16:04:44 +02:00

76 lines
4.1 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { fontFamilyValue, fontSizeValue, fontScaleValue, readableUiTextColor } from '/models/lib/uiFonts';
import { activeThemeName } from '/client/lib/activeTheme';
// #4759: apply the user's chosen UI font AND font-size preset to the whole UI by
// setting CSS variables on :root and toggling marker classes on <body> (uiFont.css
// consumes them). fontFamilyValue()/fontSizeValue() return '' for anything not on the
// curated whitelist/presets, so only known, safe values can ever reach the DOM — the
// saved values are also validated server-side. Unset => nothing applied (defaults).
Meteor.startup(() => {
// #6587: the font-size preset has to land on the ROOT element, not on <body>.
// A size on <body> is inherited only by children that ask for a relative size,
// and it leaves `rem` — which is measured against the root — untouched. So a
// board's type, which states its sizes in rem so it does not change with the
// window, ignored the setting completely: "The font size setting in the user
// menu (Settings -> Font Size) has no effect on mini cards, while it correctly
// applies to other UI elements."
//
// Only ONE element may carry it. With the size on both html and body, a 130%
// preset would compound to 169% for anything relative to body, so this marks
// the root for font-size and <body> for everything else (the font-family and
// colour rules match on body, and form controls are listed there explicitly).
const ROOT_CLASSES = new Set(['has-ui-font-size']);
function toggle(varName, className, value) {
try {
const el = ROOT_CLASSES.has(className) ? document.documentElement : document.body;
if (value) {
document.documentElement.style.setProperty(varName, value);
if (className) el.classList.add(className);
} else {
document.documentElement.style.removeProperty(varName);
if (className) el.classList.remove(className);
}
} catch (_) {
// document not ready in exotic embeddings; ignore.
}
}
// #6755: a member who hid the focus outline (Member Settings / Change Settings):
// a class on <body>, which layouts.css turns into no ring.
Tracker.autorun(() => {
const user = Meteor.user();
try {
document.body.classList.toggle('has-hide-focus-outline', !!(user && user.profile && user.profile.hideFocusOutline === true));
} catch (_) {
// document.body may not exist yet in exotic embeddings; ignore.
}
});
Tracker.autorun(() => {
const user = Meteor.user();
const profile = (user && user.profile) || {};
toggle('--wekan-ui-font', 'has-ui-font', fontFamilyValue(profile.uiFont));
toggle('--wekan-ui-font-size', 'has-ui-font-size', fontSizeValue(profile.uiFontSize));
// ...and the same preset as a number, which is what actually moves most of
// the UI: the percentage above only reaches text written in a relative unit,
// and WeKan writes most of its sizes in px. Every px font-size and
// line-height in the stylesheets is multiplied by this variable
// (uiFont.css), so one preset moves the whole interface instead of the part
// of it that happened to be written in rem. No class goes with it - a
// variable that is not set falls back to 1 in the calc itself.
toggle('--wekan-ui-font-scale', null, fontScaleValue(profile.uiFontSize));
// The chosen colour, made legible on the surface of the theme in use (4.5:1,
// WCAG 1.4.3): a colour that already reads is applied as chosen.
toggle('--wekan-ui-text-color', 'has-ui-text-color', readableUiTextColor(profile.uiTextColor, activeThemeName()));
// There was a `--wekan-ui-bg-color` here, for "text background color". It is
// removed: a colour behind the text needs elements to sit on, and there is no
// set of them that looks right - on the boxes it painted the page, on the text
// carriers it striped headings and menu rows with bands. Nothing reads
// `profile.uiTextBgColor` any more, and setUiColors unsets it, so a value
// stored before this is gone rather than dormant.
});
});