ui: two more labels were painting text with an inline colour, and shorthand hex

Both from review, and both correct.

* The tag edit preview and the Flasher's chip badges still wrote the
  calculated text colour to `color`.  That is the same defect the last
  commit fixed on the tag chip itself: an inline declaration no stylesheet
  rule can outrank, so night keeps the colour calculated for the fill it
  has just discarded and a bright fill leaves black text on near-black.

  The preview is the worse of the two -- it is the preview of the colour
  being chosen, so it was misrepresenting what the tag would look like at
  the moment the user picks it.  It now shows the tag shape as well.

  Fixing the first site did not fix these, and the stylesheet comment
  explaining the night and amber override already named the Flasher.  So
  there is a source guard now: no element carrying `wrolpi-label` may set
  `color` in its style object.  Verified against a planted violation,
  which it reports by file.

* `hexToRGBArray` rejected the shorthand `#fff`, which left the luminance
  at zero -- a near-white tag was read as black and handed light text.
  Reachable because tag colours are not only picked in the colour picker:
  they are stored in a config, and a config is a file a user edits by
  hand.  Three tests were red first, including one asserting the shorthand
  and the six-digit form of the same colour agree.
This commit is contained in:
Roland 2026-08-01 14:34:17 -06:00
parent d117d92a85
commit 672e7973f6
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
5 changed files with 115 additions and 7 deletions

View file

@ -599,6 +599,65 @@ describe('Label as a tag', () => {
});
});
describe('nothing paints a label\'s text with an inline colour', () => {
/*
* A source guard, because this defect appeared at three separate call sites and fixing the
* first one did not fix the others.
*
* A label's text colour has to travel through `--label-text`. An inline `color` is a
* declaration no stylesheet rule can outrank, so night -- which turns a label into an
* outline over a near-black page -- keeps whatever was calculated for the fill it just
* discarded. A bright fill leaves black text on near-black: the tag reads as an empty
* outline, and nothing fails.
*
* The three were the tag chip, the tag edit preview (the very preview of the colour being
* chosen), and the Flasher's chip badges. The stylesheet comment explaining the night and
* amber override already named the Flasher, and it was still missed.
*/
const sourceFiles = (directory) => fs.readdirSync(directory, {withFileTypes: true})
.flatMap(entry => {
const full = path.join(directory, entry.name);
if (entry.isDirectory()) {
return entry.name === 'node_modules' ? [] : sourceFiles(full);
}
if (!/\.(js|tsx)$/.test(entry.name) || /\.test\.|\.cy\./.test(entry.name)) {
return [];
}
return [[full, fs.readFileSync(full, 'utf8')]];
});
it('sets --label-text instead, everywhere', () => {
const src = path.join(__dirname, '..', '..');
const offenders = [];
for (const [file, source] of sourceFiles(src)) {
const stripped = source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '');
let from = 0;
while (true) {
const at = stripped.indexOf('wrolpi-label', from);
if (at === -1) break;
from = at + 1;
// The style object belonging to this element, if it has one nearby.
const styleAt = stripped.indexOf('style={{', at);
if (styleAt === -1 || styleAt - at > 200) continue;
const styleEnd = stripped.indexOf('}}', styleAt);
if (styleEnd === -1) continue;
const styleObject = stripped.slice(styleAt, styleEnd);
// A bare `color:` -- not `--label-color`, and not `backgroundColor` and friends,
// which are camelCase and so do not match a lowercase `color:`.
if (/(?:^|[^-\w])color\s*:/.test(styleObject)) {
offenders.push(`${path.relative(src, file)}: ${styleObject.slice(0, 90)}`);
}
}
}
expect(offenders).toEqual([]);
});
});
describe('Table', () => {
it('renders a Semantic-shaped compound table', () => {
renderUI(<Table>