mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 20:06:22 -05:00
ui: headings open their section, and keep their help icon on one line
Two things, and the second was a regression this migration caused.
A heading had `margin: 0 0 10px` -- no top margin at all -- so it sat flush
against whatever came before and read as part of it rather than as the start of
the next thing. On /more/statistics "Tags" touched the panel above it with a
0px gap. Now 22px above and 10px below, because a heading belongs to what
follows it.
`* + .wrolpi-header` rather than a blanket margin, for the same reason
StatisticGroup needed it: a heading that opens a Panel or a page is already
where it should be, and pushing it down just dents the top of its own container.
The help icon on every HelpHeader and InfoHeader had dropped to its own line --
"Root CA Certificate" in Settings is the clearest one. `.inline-header` set
`h1..h5 {display: inline-block}` so the heading and a sibling `<span>` shared a
row, which worked while these were a bare `<h2>` and stopped the moment they
gained a block wrapper: the `<label>`'s block child forced a break.
Fixed in the library rather than patched in App.css. `Header` takes an `after`
slot rendered inside the heading element, where the existing flex row already
handles alignment and spacing. Both wrappers pass their icon through it, the
`<label>` moves inside the heading so `for_` keeps associating the text with its
field (three call sites rely on it), and the `.inline-header` rules are deleted.
Fifteen call sites are fixed by fixing the two wrappers.
Tests: containment in jest, and the part jsdom cannot judge -- that the two
boxes actually share a line, and that the heading stays one row tall -- in a
browser. Planted both original shapes: the margin removed, a blanket margin
denting its container, and the control moved back outside the heading element.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2ce7601ebb
commit
c18fe84783
8 changed files with 221 additions and 43 deletions
|
|
@ -388,6 +388,94 @@ describe('a load reading ranks itself in the monochrome themes', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('a heading keeps its trailing control on its own line', () => {
|
||||
/*
|
||||
* The defect this fixes: `.wrolpi-header` is a block, so a help icon placed after it
|
||||
* wrapped to the next line -- every `HelpHeader` and `InfoHeader` in the app, most
|
||||
* visibly "Root CA Certificate" on the Settings page.
|
||||
*
|
||||
* A pure layout claim, so jsdom cannot judge it: getBoundingClientRect returns zeros
|
||||
* there, and containment alone (which the jest tests assert) does not prove two boxes
|
||||
* share a line.
|
||||
*/
|
||||
themeNames.forEach((theme) => {
|
||||
it(`sits the control beside the text in ${theme}`, () => {
|
||||
cy.mountUI(
|
||||
<Header as='h3' after={<Button role='cancel' size='xs'>Help</Button>}>
|
||||
Root CA Certificate
|
||||
</Header>,
|
||||
{theme},
|
||||
);
|
||||
|
||||
cy.get('.wrolpi-header-after').should(($after) => {
|
||||
const control = $after[0].getBoundingClientRect();
|
||||
const text = $after[0].previousElementSibling.getBoundingClientRect();
|
||||
|
||||
// Beside, not below: they overlap vertically and the control is to the right.
|
||||
expect(control.top, 'control starts above the text baseline')
|
||||
.to.be.lessThan(text.bottom);
|
||||
expect(text.top, 'text starts above the control baseline')
|
||||
.to.be.lessThan(control.bottom);
|
||||
expect(control.left, 'control is after the text').to.be.at.least(text.right);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('does not stretch the heading to make room', () => {
|
||||
// A wrapped control would make the heading two lines tall. One line is the claim.
|
||||
cy.mountUI(
|
||||
<Header as='h3' after={<Button role='cancel' size='xs'>Help</Button>}>
|
||||
Root CA Certificate
|
||||
</Header>,
|
||||
{theme: 'light'},
|
||||
);
|
||||
|
||||
cy.get('.wrolpi-header-text').should(($heading) => {
|
||||
const control = Cypress.$('.wrolpi-header-after')[0].getBoundingClientRect();
|
||||
expect($heading[0].getBoundingClientRect().height, 'heading is one row tall')
|
||||
.to.be.lessThan(control.height * 2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('a heading opens a section rather than closing the last one', () => {
|
||||
it('leaves room above a heading that follows something', () => {
|
||||
/*
|
||||
* With no top margin a heading sat flush against the panel above it and read as part
|
||||
* of it -- "Tags" on /more/statistics touched the panel above with a 0px gap.
|
||||
*/
|
||||
cy.mountUI(
|
||||
<div>
|
||||
<Panel>Files</Panel>
|
||||
<Header as='h3'>Tags</Header>
|
||||
<Panel>34 tags</Panel>
|
||||
</div>,
|
||||
{theme: 'light'},
|
||||
);
|
||||
|
||||
cy.get('.wrolpi-header').should(($header) => {
|
||||
const panel = Cypress.$('.wrolpi-panel')[0].getBoundingClientRect();
|
||||
const gap = $header[0].getBoundingClientRect().top - panel.bottom;
|
||||
expect(gap, 'gap above the heading').to.be.at.least(12);
|
||||
|
||||
// And more above than below, because the heading belongs to what follows it.
|
||||
const below = Cypress.$('.wrolpi-panel')[1].getBoundingClientRect().top
|
||||
- $header[0].getBoundingClientRect().bottom;
|
||||
expect(gap, 'more air above the heading than below it').to.be.greaterThan(below);
|
||||
});
|
||||
});
|
||||
|
||||
it('does not dent the top of its own container', () => {
|
||||
// A blanket margin would push a heading that opens a Panel away from the Panel's edge.
|
||||
cy.mountUI(<Panel><Header as='h3'>Downloads</Header><p>body</p></Panel>, {theme: 'light'});
|
||||
|
||||
cy.get('.wrolpi-header').should(($header) => {
|
||||
expect(getComputedStyle($header[0]).marginTop, 'first child has no top margin')
|
||||
.to.equal('0px');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('a table header is a surface, not just bold text', () => {
|
||||
themeNames.forEach((theme) => {
|
||||
it(`separates the header from every body row in ${theme}`, () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue