Style reference fields

Task type
Project
Changed

Context

Entity reference field items are hard to tell apart.

Same problem, different markup: Increase space between book navigation links (theme site). In both cases the space between two items is about the same as the space between the wrapped lines of one item, so you can't tell where one item ends.

Current list variations

Computed styles in mantra_starter, measured at a 16px font size:

Source Markup Line height Gap between items Indent List margin
Prose: lists in .text-formatted ul/ol 1.75 8px 26px + 6px 20px
Item list (core item_list, Views lists) div.item-list > ul.item-list__list 1 8px 16 / 20px 0 (wrapper has my-4)
Item list inside prose same 1.75 (picks up prose values) 8px 26 + 6px 0
list_items SDC ul.list_items 1 / 1.25 / 1.5, set by a prop 0 16 / 20px 16px (browser default)
Plain list: book nav ul.menu-tree, any list with no class ul 1 0 16px 16px
Multi-value fields, including reference fields div.field__items > div.field__item 1.5 4px none, no markers 0
Inline: ul.links.inline, comma lists ul 1.25 separators — —
  • Book navigation: libraries/global/base/elements.css sets the "compact" list values (line height 1) on :root. variables.css loads first (weight -1), so compact quietly became the site default. With line height 1 and no gap, a wrapped title is as close to its own second line as to the next item.
  • Reference fields: line height 1.5 leaves about 8px between the lines of a wrapped title, and items are only 4px further apart than that (component/field.css, .25rem). No markers either.
  • Variables are tangled:
    • --list-line-height is set to 1.5 in variables.css, then overridden to 1.
    • --list-default-* exists only so .text-formatted can undo that override.
    • --list-ol-style: disc is never used, and would be wrong for an ol.
    • list_items defines its own --item-list-line-height.
    • field.css and views.css use hard-coded rem values.

Ideas

Rule for every variant: the gap between items must clearly exceed the spacing between the wrapped lines of one item.

  1. Five variants:

    • prose: unchanged; the UnoCSS typography preset already reads --list-*.
    • default: markers, line height about 1.3, gap of at least 0.5em.
    • compact: denser, for sidebars and tables.
    • plain: same spacing as default, no markers or indent (reference fields).
    • inline: comma lists and inline links.

    Columns and nested markers (circle, square / lower-alpha, lower-roman) are separate options that apply to any variant.

  2. One set of variables per variant: --list-line-height, --list-item-gap, --list-indent, --list-margin-block, --list-marker. One shared stylesheet reads them; a variant class only sets them. Delete the :root override in elements.css and the --list-default-* / --list-compact-* layers.
  3. Unclassed lists get the default variant. This fixes the book navigation with no template change, along with every other stray list.
  4. Render all lists through list_items. Replace its line_height: 1|2|3 prop with a variant prop. Route the other sources through it:

    • item-list.html.twig (comma list_style → inline);
    • views-view-list.html.twig;
    • a book-tree.html.twig override (list_items already supports nested below items);
    • multi-value reference fields, through a field template suggestion (variant plain) rather than per-display Fences settings.

    Nested markers move from list_items.css into the shared stylesheet so every list gets them.

TODO

  • [ ] Steps 2–3: variables and the default variant for unclassed lists. Resolves the book navigation issue.
  • [ ] Field template suggestion for multi-value reference fields. Resolves this task.
  • [ ] Add the variant prop to list_items; move item lists, Views lists and the book tree onto it.
  • [ ] Update /ui-examples/item_lists (mantra_examples/src/ItemListExamples.php): it describes --item-list-line-height and an adjacent-sibling margin rule as part of item-list.css, and that file no longer contains either.
  • [ ] ddev theme build, commit dist/, check contrib (task pages) and theme (/ui-examples/item_lists, list_items stories).

Related tasks