Skip to main content

Components and accessibility contracts (part 6 of 6)

Part of Design system, which is built from DESIGN.md in the repository, where it is edited.

ComponentContract
BasemapPickerA radio group named "Basemap", one tab stop, with native radios inside labelled tiles. When every tile of a basemap fails and none loads, from its style loading until the map settles, the map marks it unavailable, goes back to the previous basemap (or the default, never one already marked) and says " is not available right now." with "Use previous basemap"; with nothing else left, it stays and the message has only Dismiss. Once any tile of a basemap has loaded, later failures are not reported this way, and the general tile error covers them. A marked basemap has its radio natively disabled, so the arrow keys skip it, and the words "Not available right now" sit inside the label, so they are part of the radio's name and not told by a faded tile alone. The chosen basemap is never disabled, so the group always has a checked radio the keyboard can reach. A "Try again" button sits under the grid, outside the radio group, while any basemap is marked; it clears every mark, so the map judges a basemap again when it is chosen, and moves focus to the chosen radio, because the button goes. A mark lapses after 5 minutes, so a provider that recovers comes back without a reload. Nothing is requested to find out: a basemap is judged only by the tiles the map asks for. A basemap the person chose in this session that turns out to be down is not kept as the saved choice: the one saved before it comes back. A saved or linked basemap the person did not just choose is left alone by the outage; going back or dismissing the message saves the basemap the map went back to, except for a visitor who is following the theme and is already on it, who goes on following it. Pressing the tile that is already shown chooses it without an announcement, so a visitor following the theme can keep the default.
TourCardA region named by its h2 heading, not a dialog: the welcome card ("Take the tour", "Skip"), a step ("Step N of M", its text, Next or Finish, "Skip tour") or the ending (Close). The welcome card never takes focus and is announced once; Take the tour, Next and Help's "Take the tour" focus the heading; a step finished by doing it keeps focus where it is and announces the next step. Escape inside the card skips and prevents the default; Escape elsewhere keeps its meaning. Closing with focus inside returns it to the map. The current step's control carries data-tour-highlight, drawn with the focus ring, with no scrim. Answering stores the host's tour version in Settings.tourSeen; it is not offered on a link with a view, layers or shapes, or when storage will not remember.
LiveRegionThe one announcer: a polite and an assertive region mounted once, throttled and de-duplicated. Nothing else creates live regions. Each region speaks at most one message per THROTTLE_MS. The first message after an idle window is spoken at once. Messages that arrive inside the window wait for it to end, and a waiting message is replaced by a later one, so a stream of updates is spoken as its latest. A message that reports a running count, such as the selection's ("Added Gauge 4. 5 selected."), carries the whole count, so the one that is read is still true. A message sent with keep is never replaced: it reports the outcome of something the person did ("2 layers turned back on") or a state they would otherwise miss (a tile layer they turned on that is still waiting for imagery), so it waits its turn, in order, one per window, and a kept message that repeats a waiting one makes that one kept. Set keep only for such messages, because each one lengthens the queue. The two regions are throttled apart. A message is text or a Message from core (a key and its parameters), which the provider formats with the active catalogue just before it is queued, so the throttle, the de-duplication and keep all act on the words that will be spoken. The reference site calls the selection hook but builds no selection store, so these messages are not heard there.
SkipLinkFirst focusable element. Moves focus to the map region.
VisuallyHiddenThe one way to provide screen-reader-only text.

Map region: a focusable region named "Map", described by hidden keyboard instructions. It is aria-busy while the style or the basemap's own tiles load, with a loading bar over the map. A data layer's tiles do not set it, so a layer whose server is slow or never answers cannot leave the region busy for good; a feed layer's loading and failure are in its status line in the Layers section, and a tile layer says there when it is still waiting for its first tile or none of its tiles loaded. The region being ready therefore says nothing about a layer's tiles having arrived. Arrow keys pan, plus and minus zoom, Shift with left and right arrows rotates, Home or 0 resets north, P drops a pin, I shows what is at the centre of the map, as a tap there would (a card for one feature, a list for several), Escape closes the active surface. While the draw tool is open its keys come first: Space, Enter, the arrows with a point selected, the bracket keys, Delete, Backspace, Control or Command with Z, and a staged Escape (leave a point, cancel the shape, drop the selection, then close the tool).

Gesture equivalents: tapping a data point, polygon or line has the layer's list and its "Show on map" rows, and a tap that finds several features has the I key, which also asks the raster layers that answer a tap. Escape, on the map or from elsewhere on the page, ends such a lookup while it waits and does not also close the open surface; a second press closes it. Saving an image is a button, and importing shapes is a button that opens the browser's own file picker, with no drag and drop to need an equivalent. Drawing has Add point at map centre and the Space key. Selecting a point has Previous point, Next point and the bracket keys. Dragging a point has the arrow keys (Shift for more) and Move point to map centre. Tapping a midpoint handle to add a vertex has Add point after this one at map centre, and dragging a circle's radius handle has the radius buttons. Finish has Enter, Cancel has Escape and Remove point has Delete or Backspace. Long-press pin has "Drop pin at map centre" and the P key. Pinch and double-tap have the zoom buttons and +/-. Rotation has Shift with left and right arrows and the compass. Sheet drag has the handle button. Measure taps have "Add point at map centre". Directions stop taps have "Add stop at map centre", "Add dropped pin" and a place search, and any drag of a stop has the Move and Remove buttons.

Overriding a primitive​

The primitives that take a className (Surface, Button, IconButton, Chip and the ListRow body) define their styles with primitiveRecipe (packages/map/src/ui/primitiveRecipe.ts), which puts every rule of the recipe, with its selectors and media queries, in one cascade layer (primitives, declared in primitives.css.ts). A style outside any layer beats a layered one whatever its specificity or the order the stylesheets load in, so a component restyles a primitive with a plain class passed as className: a background, a radius, a shadow, a border colour. Never double a selector (&&) to win, and never rely on the stylesheet order. A new primitive that takes a className uses primitiveRecipe; a recipe that is a component's own style (such as StatusMessage's) stays a plain recipe.

What the layer changes:

  • A component's plain rule also beats the recipe's state rules (hover, active, focus, pressed). A component that sets its own background therefore sets its own hover and focus styles, as the credits button does.
  • Unlayered rules beat the primitives, in this repository and in an adopter's app. The host's default focus outline (:where(:focus-visible), in packages/web/src/global.css.ts) outranks the recipes' own outline, so the two keep the same outline and outlineOffset (both come from focusRing; a test pins them). Do not add an unlayered rule for button or another element a primitive renders unless it is meant to win.
  • Known trade-off for adopters: an unlayered element rule in an app (button { background: transparent; border: 0; padding: 0 }, say, or :focus-visible { outline: none }) now beats every primitive whatever its specificity or the stylesheet order. Before the layer, the primitive's class beat an element selector. An app's base styles and resets therefore go in an @layer that is declared before @mapcairn/map/styles.css is imported, because a layer declared earlier ranks lower, so the primitives outrank it. The layer name stays generated and private, so an app cannot order it by name. An adopter who hits a problem with this can open an issue.
  • The built styles.css uses one layer with a generated name. Each file that holds primitive rules repeats the one-line statement @layer <name>; before its blocks, so the name is declared several times, in the middle of the file and not first; with one layer the repeats change nothing, and the first sits ahead of every block that uses it. npm run consumer:check builds a throwaway app with a layered reset imported before styles.css and checks a primitive keeps its background, padding and border.
  • Forced colours and prefers-contrast: more still apply: they come from the tokens, which are not layered, and from the same layered rules.

e2e/primitive-override.spec.ts moves the recipe's rules to a stylesheet added last and checks the credits button keeps its surface, radius and shadow (its hover case passes without the layer and only guards the hover rule); packages/core/src/lint/sdkDist.test.ts checks the built styles.css and that every primitive recipe uses primitiveRecipe.