# Opinions we hold

Each of these is a choice between valid options, not a standard.

- **Our choice:** [logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values)
  (`margin-block`, `inline-size`), so right-to-left and vertical writing modes work unchanged.
- **Our choice:** keep link underlines, because color alone is not enough to spot a link (WCAG 1.4.1).
- **Our choice:** system font stacks from [Modern Font Stacks](https://modernfontstacks.com/),
  because they cost no network requests and match the platform. `css/domestic.css` makes no font request.
  For a consistent face across platforms (and pinned screenshots), the optional `css/fonts/inter.css` declares a
  self-hosted [Inter](https://rsms.me/inter/) 4 variable font (Latin and Latin Extended subsets split by
  [`unicode-range`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@font-face/unicode-range),
  [`font-display: swap`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@font-face/font-display),
  an optical size axis that [`font-optical-sizing`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-optical-sizing)
  uses automatically, [SIL OFL 1.1](https://openfontlicense.org/)). Opt in by linking it and setting
  `--dui-font-body: Inter, system-ui, sans-serif`. The docs site does.
- **Our choice:** a productive and an expressive type scale (as [Carbon](https://carbondesignsystem.com/elements/typography/overview/)
  splits them, for comparison): steps up to `--dui-step-2` are fixed, and `--dui-step-3` to `-5` are fluid with
  [`clamp()`](https://developer.mozilla.org/en-US/docs/Web/CSS/clamp) in `rem`, so display text grows with the viewport
  and everything respects the user's font size ([1.4.4 Resize Text](https://www.w3.org/WAI/WCAG22/Understanding/resize-text.html)).
- **Our choice:** interface text (buttons, fields, nav, menus, tabs, badges, tooltips, table cells) is 14px
  (`--dui-font-size-ui`), as in Primer, Fluent 2, Radix Themes and shadcn/ui, for comparison. Prose stays 16px.
  An app page title (`--dui-font-size-page-title`) is step 4, 38px at most, one step above h2. Step 5 is for docs and marketing heroes.
- **Our choice:** text fields, selects and text areas use `--dui-font-size-field`: the UI size on a fine pointer and at
  least 16px under a coarse one ([`pointer`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/pointer),
  [`max()`](https://developer.mozilla.org/en-US/docs/Web/CSS/max)), because iOS Safari zooms the page into a focused
  field with smaller text. The 44px coarse-pointer field height already fits it. The viewport meta never limits zoom
  ([1.4.4 Resize Text](https://www.w3.org/WAI/WCAG22/Understanding/resize-text.html)).
- **Our choice:** a 60ch measure for prose, near the commonly cited 45 to 75 characters per line
  ([WCAG 1.4.8 Visual Presentation](https://www.w3.org/WAI/WCAG22/Understanding/visual-presentation.html) asks for 80 or fewer).
- **Our choice:** rhythm from the "lobotomized owl" selector (`* + *`) inside flow containers
  ([Heydon Pickering](https://alistapart.com/article/axiomatic-css-and-lobotomized-owls/)), wrapped in
  `:where()` so it has zero specificity.
- **Our choice:** `type="submit"` buttons get the primary fill and other buttons stay neutral,
  so the primary action is marked by its native type, with no class.
- **Our choice:** checkboxes, radios and range keep native rendering tinted with
  [`accent-color`](https://developer.mozilla.org/en-US/docs/Web/CSS/accent-color), because
  native controls keep their platform accessibility.
- **Our choice:** each atom has one `data-<atom>` attribute whose value is a space-separated
  list (`data-button="primary small"`), matched with `~=`, instead of modifier classes. The
  other atom choices (button variants, focus rings, switch, field errors, badge tints) are
  listed with their reasons in the [atoms index](https://github.com/odonckers/domestic-ui/blob/main/css/components/atoms/README.md#our-choices).
- **Our choice:** molecules follow the same rule (`data-card="link"`, `data-dialog="drawer end"`),
  or use the native element or ARIA role when that already says everything (`<search>`,
  `role="toolbar"`). The molecule choices are listed with their reasons in the
  [molecules index](https://github.com/odonckers/domestic-ui/blob/main/css/components/molecules/README.md#our-choices). The main ones:
  - **Our choice:** tabs select on focus (automatic activation), as the
    [APG recommends](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/#deciding-when-to-make-selection-automatically-follow-focus)
    when panels show at once. `activation="manual"` is available.
  - **Our choice:** the drawer is a `<dialog>` variant, so the browser handles modality, focus and
    <kbd>Esc</kbd> ([explainer](https://domestic-ui.odonckers.dev/explainers/drawer.md)).
  - **Our choice:** a clickable card links its heading and stretches that link over the card, so the
    accessible name stays the heading ([explainer](https://domestic-ui.odonckers.dev/explainers/card.md)).
  - **Our choice:** toasts never dismiss themselves and never take focus ([explainer](https://domestic-ui.odonckers.dev/explainers/toast.md)).
  - **Our choice:** the typeahead (`<dui-combobox>`) upgrades a native `<input list>` + `<datalist>`, not a
    `<select>`, because the value is free text and the upgrade reuses the same input and options. It
    follows the [APG Combobox](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/) list autocomplete
    variant, filters by "contains" like the native
    [`<datalist>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/datalist) popups
    in Chromium and Firefox, and positions its listbox under the input rather than in the top layer, so
    it is never wider than the field ([explainer](https://domestic-ui.odonckers.dev/explainers/combobox.md)).
- **Our choice:** organisms (page header, filter bar, form sections, data table) follow the same one-attribute rule
  (`data-page-header`, `data-filter-bar`, `data-form-sections`, `data-table`) and take the rest of their layout from their
  children's native elements. Their choices are listed in the
  [organisms index](https://github.com/odonckers/domestic-ui/blob/main/css/components/organisms/README.md#our-choices). The main ones:
  - **Our choice:** the filter bar is a `<form method="get">` in `<search>` with an Apply button and a
    `role="status"` result count present from page load, so filters live in the URL, work without
    JavaScript and are announced ([4.1.3 Status Messages](https://www.w3.org/WAI/WCAG22/Understanding/status-messages.html)).
  - **Our choice:** form sections are headed `<section>` elements with a `<header>` and one body of fields,
    not fieldsets, because a `<legend>` cannot be placed in a grid column. Related controls still go in a
    `<fieldset>` inside the body.
  - **Our choice:** the data table (`data-table` on a native `<table>`) has sortable headers that are plain
    text in the markup. `<dui-table>` turns them into buttons and follows the
    [APG Sortable Table](https://www.w3.org/WAI/ARIA/apg/patterns/table/examples/sortable-table/) example
    (`aria-sort` on the sorted header only, a visually hidden caption hint, nothing else announced), so with
    JavaScript off there are no buttons that do nothing. A selected row shows a checked checkbox, a bar on its
    leading edge and a tint, never color alone. The count is a `role="status"` element present from load.
  - **Our choice:** a sticky table header sticks to the nearest scroll container, so a sticky table goes in
    `data-scroll="block inline"` (at most `--dui-size-pane` tall) or in none. Numeric columns are marked per
    cell with the same attribute (`data-table-cell="number"`), because words on the table cannot target a column.
- **Our choice:** layout primitives come from [Every Layout](https://every-layout.dev/)'s
  Stack, Cluster and Grid. Their custom properties are registered with
  [`@property`](https://developer.mozilla.org/en-US/docs/Web/CSS/@property) as non-inheriting,
  so a nested primitive keeps its own default.

## Links: visited state

[`:visited`](https://developer.mozilla.org/en-US/docs/Web/CSS/:visited) tells a reader which
destinations they have already seen. WCAG does not require it.
[Understanding 1.4.1](https://www.w3.org/WAI/WCAG22/Understanding/use-of-color.html) says conveying a
link's visited status "is not an author responsibility". The visited color still meets 4.5:1.

- **Our choice:** only content links take `--dui-color-link-visited`. Navigational links keep their
  unvisited color, because a reader picks a destination again on every page and "seen before" is noise
  there. Navigational means: inside a [`<nav>`](https://html.spec.whatwg.org/multipage/sections.html#the-nav-element)
  or `role="navigation"`, `menu`, `menubar`, `tablist` or `toolbar`; a `role="tab"` or `menuitem*` link;
  a link with `data-button`; or a same-page `#fragment` link (skip links, tables of contents).
- The base rule does this with `a:visited:not(:where(…))`, so it stays at the specificity of `a:visited`
  and needs no per-component resets. In forced colors, navigational links show `LinkText` and content
  links show `VisitedText`.
- **Either way:** mark a navigational link outside a `<nav>` with `data-link="nav"` (combines with
  `quiet`) to drop the visited color. For the rare content link inside a `<nav>`, set
  `color: var(--dui-color-link-visited)` on its `:visited` state in your own CSS, which beats the layers.

## Icons

- **Our choice:** [Lucide](https://lucide.dev) is the icon set, because its SVGs already use our 24px grid and a round
  `currentColor` stroke and need no build. We draw the stroke at `--dui-icon-stroke-width` (1.75 units), not Lucide's 2. Credit: Lucide is under the [ISC license](https://lucide.dev/license). The
  icons it took from [Feather](https://github.com/feathericons/feather) are under the
  [MIT license](https://github.com/feathericons/feather/blob/main/LICENSE). [Tabler](https://tabler.io/icons) and
  [Heroicons](https://heroicons.com) were the alternatives considered.
- **Our choice:** icons are inline SVG, copied from the official set into the markup. The repository ships no icon
  files, sprite, font or package. The recipe: copy the icon from lucide.dev, replace its `class` with
  [`data-icon`](https://domestic-ui.odonckers.dev/components/atoms/icon.md), add `aria-hidden="true" focusable="false"`, keep everything else
  (`viewBox`, `fill="none"`, `stroke="currentColor"`, `width` and `height`) as Lucide ships it, and note the icon's name
  in a comment. `data-icon` sizes it to `--dui-size-icon` and keeps it from shrinking. The stroke follows the text color
  through [`currentColor`](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentcolor), so it follows
  themes and [forced colors](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors) with no extra CSS.

  [`examples/atoms/icon.html`](https://domestic-ui.odonckers.dev/components/atoms/icon.md) shows the recipe in every context.

- **Decorative or meaningful.** An icon beside a visible label is decoration: `aria-hidden="true"`, so the label is the
  name and is not announced twice ([1.1.1 Non-text Content](https://www.w3.org/WAI/WCAG22/Understanding/non-text-content.html)).
  A standalone icon that carries meaning, outside a control, is `role="img"` with a `<title>` (and `aria-labelledby`
  pointing at it). In a control, the name goes on the control, never on the SVG
  ([4.1.2 Name, Role, Value](https://www.w3.org/WAI/WCAG22/Understanding/name-role-value.html),
  [APG: names and descriptions](https://www.w3.org/WAI/ARIA/apg/practices/names-and-descriptions/)).
- **Contrast.** An icon that is the only sign of a control or a state meets 3:1
  ([1.4.11 Non-text Contrast](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html)). A selected state
  changes the drawing (filled or outlined), not only its color.
- **Our choice:** icon plus a visible label is the default. Label only is always fine, and better when no icon comes to
  mind at once. If the label is visible, the accessible name contains it
  ([2.5.3 Label in Name](https://www.w3.org/WAI/WCAG22/Understanding/label-in-name.html)).
- **Our choice:** icon only (`data-button="icon"`) is allowed only for these widely recognized actions: search, close,
  open or close navigation (menu), show or hide a sidebar or panel, play, pause, stop, skip, expand and collapse, back, forward, edit, more (overflow),
  settings in an app bar, and add item in a dense toolbar. A product-specific metaphor is never icon only. The button
  - is named for the action ("Search", "Close"), never the picture ("Magnifying glass", "X"), with visually hidden text
    inside it;
  - shows a visible tooltip with the same words on hover **and** keyboard focus, which <kbd>Esc</kbd> hides and the
    pointer can move onto ([1.4.13 Content on Hover or Focus](https://www.w3.org/WAI/WCAG22/Understanding/content-on-hover-or-focus.html)).
    The tooltip is `<dui-tooltip>` with a `popover="hint"`. No browser can show a popover on hover and focus without
    script except Chromium, through [`interestfor`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button#interestfor),
    which Firefox and Safari do not support yet;
  - is a square of `--dui-size-control` (36px comfortable, 32px compact, 44px under a coarse pointer), never smaller than 24 by 24 pixels
    ([2.5.8 Target Size (Minimum)](https://www.w3.org/WAI/WCAG22/Understanding/target-size-minimum.html)).
- **Our choice:** no icon-only destructive actions. Delete, remove, empty and reset always show their word. A trash icon
  may sit beside it. For that reason delete is not on the list above, even in a toolbar.
- **Our choice:** navigation keeps visible text. Icons in nav links and app bar buttons are decoration.
- **Our choice:** in right-to-left text, flip only icons whose meaning has a direction, with `data-icon="mirror"`
  (flipped under [`:dir(rtl)`](https://developer.mozilla.org/en-US/docs/Web/CSS/:dir), which follows the nearest `dir`
  attribute): arrows, chevrons, back and forward, undo and redo, indent and outdent, text alignment to the start or end.
  Never flip search, close, play, check, clocks or logos.
- **Icon fonts are rejected.** A ligature or private-use glyph is text. User text spacing
  ([1.4.12 Text Spacing](https://www.w3.org/WAI/WCAG22/Understanding/text-spacing.html)) can break the ligature into
  words, a font that fails to load shows letters or empty boxes, and screen readers may read the ligature name.
