When to use it#
- Use it when the question is where a place is: the nearest preschool, the recycling stations in a district, the polling station for an address. The same places are always in a list, so nobody has to use the map to reach one.
- Not for a single address: write it as text, with a link to a map service. Not for a long list with no question about where: use a list or a Table.
- Tiles (the map pictures) are your choice. The library names no tile server, and it has no default. A visitor’s browser asks your tile host for each picture, so the host sees the visitor’s IP address: name it in your privacy notice. A provider is the code that draws the map, such as MapLibre. Nothing is requested until a
Map.Rootwith a provider is on the page. - The map has no address search of its own. A visitor finds a place by the markers, the list and the layers. To let a visitor search for an address, put an AddressSearch beside the map.
- It is its own package,
@kvirn-ui/map. Its styles are an opt-in import,@kvirn-ui/theme/map.css, aftertheme.css, so a site without maps does not pay for them. MapLibre is an optional peer. The install lines are in the API reference.
Example#
import { Map } from '@kvirn-ui/map'
import { useMapTexts } from './texts.ts'
import { DocsMap } from './use-docs-provider.tsx'
const initialView = { center: { longitude: 18.07, latitude: 59.33 }, zoom: 13 }
export function RecyclingMap() {
const { texts } = useMapTexts()
return (
<DocsMap>
{(provider) => (
<Map.Root
provider={provider}
label={texts.stationsLabel}
places={texts.stations}
initialView={initialView}
>
<Map.Skip />
<Map.Viewport>
<Map.BaseMapSwitch />
<Map.Markers />
<Map.Controls />
<Map.Attribution />
</Map.Viewport>
<Map.List headingLevel="h3" />
<Map.Details />
</Map.Root>
)}
</DocsMap>
)
}The examples on this page load their map from geo.kvirn.com, Kvirn’s own map service, hosted in the EU and setting no cookies. Your browser asks it for the map as soon as a map is shown, so it sees your IP address and the area you view. Move the map with the mouse, the arrow keys or the buttons, press a marker or a name in the list, and watch the list follow the view.
Use cases#
Finding a preschool near you
A parent looks for a preschool close to home. The list gives each name and address, and your own line under it, such as opening hours. A popup opens with a picture, the address and a few words, anchored to the place on the map.
import { Map } from '@kvirn-ui/map'
import { useMapTexts } from './texts.ts'
import { DocsMap } from './use-docs-provider.tsx'
const initialView = { center: { longitude: 18.07, latitude: 59.33 }, zoom: 13 }
export function PreschoolMap() {
const { texts } = useMapTexts()
return (
<DocsMap>
{(provider) => (
<Map.Root
provider={provider}
label={texts.preschoolsLabel}
places={texts.preschools}
initialView={initialView}
>
<Map.Skip />
<Map.Viewport>
<Map.Markers />
<Map.Controls />
<Map.Attribution />
</Map.Viewport>
<Map.List headingLevel="h4">
{(place) => <span className="kv-map-list-aside">{texts.hours[place.id]}</span>}
</Map.List>
<Map.Details />
</Map.Root>
)}
</DocsMap>
)
}Props in this example:
childrenon Map.Listimageon MapPlacedescriptionon MapPlace
Warning: Don't forget
Describe every picture in image.alt, or use an empty alt when it only decorates. Without it a screen reader user gets no idea what the picture shows (1.1.1 Non-text Content).
Showing only the kinds of place you want
A resident wants the hazardous waste depot, not the recycling stations. Layers let them show or hide each kind. Each layer’s checkbox says how many places it holds. Hiding a layer takes its markers and rows away and announces the new count, and focus stays on the checkbox. The card starts open; set defaultOpen={false} for a long list of layers, so it does not cover the map.
import { Map } from '@kvirn-ui/map'
import { useMapTexts } from './texts.ts'
import { DocsMap } from './use-docs-provider.tsx'
const initialView = { center: { longitude: 18.07, latitude: 59.33 }, zoom: 13 }
export function WasteMap() {
const { texts } = useMapTexts()
return (
<DocsMap>
{(provider) => (
<Map.Root
provider={provider}
label={texts.wasteLabel}
places={texts.wastePlaces}
layers={texts.layers}
initialView={initialView}
>
<Map.Skip />
<Map.Viewport>
<Map.Layers />
<Map.Markers />
<Map.Controls />
<Map.Attribution />
</Map.Viewport>
<Map.List headingLevel="h4" />
<Map.Details />
</Map.Root>
)}
</DocsMap>
)
}Props in this example:
Warning: Don't forget
Every layer has a name in the checkbox and in the list, so colour is never the only difference (1.4.1 Use of Color). If you give layers their own marker pictures, give each an icon or a shape too, not only another colour.
Many places close together
On election day the map shows every polling station in the municipality. Where several are close, the map groups them in one button with the number on it. Pressing it opens a popup that lists them, and choosing one opens its details, so no place hides behind another. Zoom in with the + button and the groups split.
import { Map } from '@kvirn-ui/map'
import { useMapTexts } from './texts.ts'
import { DocsMap } from './use-docs-provider.tsx'
const initialView = { center: { longitude: 18.07, latitude: 59.33 }, zoom: 11 }
export function PollingStationMap() {
const { texts } = useMapTexts()
return (
<DocsMap>
{(provider) => (
<Map.Root
provider={provider}
label={texts.pollingLabel}
places={texts.pollingStations}
initialView={initialView}
>
<Map.Skip />
<Map.Viewport>
<Map.Markers />
<Map.Controls />
<Map.Attribution />
</Map.Viewport>
<Map.List headingLevel="h4" />
<Map.Details />
<Map.ClusterPopup />
</Map.Root>
)}
</DocsMap>
)
}A list of your own
Your service already has a list with more than names: a distance, a filter, a link to book. Build it from useMapState and point Map.Skip at its heading. Opening a place from your list works like the library’s: focus moves to the title, and closing returns it to your button.
import { Map, useMapState } from '@kvirn-ui/map'
import { useMapTexts } from './texts.ts'
import { DocsMap } from './use-docs-provider.tsx'
const initialView = { center: { longitude: 18.07, latitude: 59.33 }, zoom: 13 }
const headingId = 'station-list-heading'
function StationList() {
const map = useMapState()
const { texts } = useMapTexts()
if (map.selectedPlace) {
return null
}
return (
<div>
<h4 id={headingId} tabIndex={-1}>
{texts.ownListHeading(map.placesInViewCount, map.visibleCount)}
</h4>
<ul>
{map.placesInView.map((place) => (
<li key={place.id}>
<button
id={`station-${place.id}`}
type="button"
className="kv-button"
aria-expanded={false}
aria-controls={map.ids.details}
onClick={() => map.select(place.id, `station-${place.id}`)}
>
{place.name}
</button>
</li>
))}
</ul>
</div>
)
}
export function OwnListMap() {
const { texts } = useMapTexts()
return (
<DocsMap>
{(provider) => (
<Map.Root
provider={provider}
label={texts.stationsLabel}
places={texts.stations}
initialView={initialView}
cluster={false}
>
<Map.Skip href={`#${headingId}`} />
<Map.Viewport>
<Map.Markers />
<Map.Controls />
<Map.Attribution />
</Map.Viewport>
<StationList />
<Map.Details />
</Map.Root>
)}
</DocsMap>
)
}Props in this example:
Warning: Don't forget
Without Map.List you must give people another way to reach and open every place. The library cannot check this (1.1.1 Non-text Content, 2.1.1 Keyboard, 2.5.7 Dragging Movements).
Letting people choose the map type
Some residents read a street map more easily than a plain one, or the other way round. Give the map two or more map types and add Map.BaseMapSwitch: a button that opens a small choice with a preview of each. The choice is announced, and the places, the list and the keyboard work the same on every map type. With fewer than two map types the switch renders nothing. See Map.BaseMapSwitch in the API.
import { Map } from '@kvirn-ui/map'
import { useMapTexts } from './texts.ts'
import { DocsMap } from './use-docs-provider.tsx'
const initialView = { center: { longitude: 18.07, latitude: 59.33 }, zoom: 13 }
export function MapTypesMap() {
const { texts } = useMapTexts()
return (
<DocsMap>
{(provider) => (
<>
<Map.Root
provider={provider}
label={texts.mapTypesLabel}
places={texts.stations}
initialView={initialView}
>
<Map.Skip />
<Map.Viewport>
<Map.BaseMapSwitch />
<Map.Markers />
<Map.Controls />
<Map.Attribution />
</Map.Viewport>
<Map.List headingLevel="h4" />
<Map.Details />
</Map.Root>
<p>{texts.mapTypesNote}</p>
</>
)}
</DocsMap>
)
}Warning: Don't forget
Give each map type a clear label and its own attribution. The label names the choice for a screen reader, and the attribution must change with the map type (1.1.1 Non-text Content).
Information: Implement like this
Add your own map types, such as an aerial photo, from a tile host you have an agreement with. This example does not load one.
import { maplibre, rasterStyle } from '@kvirn-ui/map/maplibre'
import { kvirnBaseMap } from '@kvirn-ui/map/kvirn'
export const provider = maplibre({
baseMaps: [
kvirnBaseMap({ url: 'https://geo.kvirn.com' }),
{
id: 'aerial',
label: 'Aerial photo',
attribution: '© Example municipality',
style: rasterStyle({
tiles: ['https://tiles.example.org/aerial/{z}/{x}/{y}.jpg'],
attribution: '© Example municipality',
}),
},
],
})Make it your own
A municipality shows its places for children and families: playgrounds, libraries and swimming halls. A resident sees a different shape and colour for each kind, the library names on the map, a popup with opening hours and a link for directions, and switches that say how many places each kind holds. You write the markup; names, focus, announcements and keyboard come from the parts, so they keep working.
import { Map } from '@kvirn-ui/map'
import { Field, Icon, Switch } from '@kvirn-ui/react'
import type { IconName } from '@kvirn-ui/react'
import { useMapTexts } from './texts.ts'
import { DocsMap } from './use-docs-provider.tsx'
// One icon per layer, so colour is never the only difference between the kinds of place.
const layerIcons: Record<string, IconName> = {
playgrounds: 'playground',
libraries: 'book',
pools: 'swimming-pool',
}
function LayerIcon({ layer }: { layer: string | undefined }) {
const icon = layerIcons[layer ?? '']
return icon ? <Icon name={icon} size="16" /> : null
}
const initialView = { center: { longitude: 18.07, latitude: 59.328 }, zoom: 13 }
export function FamilyMap() {
const { texts } = useMapTexts()
return (
<DocsMap>
{(provider) => (
<Map.Root
provider={provider}
label={texts.familyLabel}
places={texts.familyPlaces}
layers={texts.familyLayers}
initialView={initialView}
>
<Map.Skip />
<Map.Viewport>
<Map.Layers>
{({ layers, hiddenLayerIds, setLayerHidden, counts }) =>
layers.map((layer) => (
<Field.Root key={layer.id}>
<Switch
checked={!hiddenLayerIds.includes(layer.id)}
onCheckedChange={(checked) => setLayerHidden(layer.id, !checked)}
/>
<Field.Label marker="none">
{layer.label} ({counts[layer.id] ?? 0})
</Field.Label>
</Field.Root>
))
}
</Map.Layers>
<Map.BaseMapSwitch />
<Map.Markers
label={(place, layer) => `${place.name}, ${layer?.label}`}
markerClassName={(place) => `family-marker family-marker--${place.layer}`}
cluster={(cluster, { layer }) => (
<span className="family-cluster">
<LayerIcon layer={layer?.id} /> {cluster.count}
</span>
)}
>
{(place) => (
<>
<LayerIcon layer={place.layer} />
{place.layer === 'libraries' ? (
<span className="kv-map-marker-label">{place.name}</span>
) : null}
</>
)}
</Map.Markers>
<Map.Controls />
<Map.Attribution />
</Map.Viewport>
<Map.List headingLevel="h4" />
<Map.Details>
{({ place, titleProps }) => (
<div className="kv-map-details-content family-details">
<h3 {...titleProps}>{place.name}</h3>
<Map.DetailsClose />
<p>
<strong>{texts.openingHours}:</strong> {texts.familyHours[place.id]}
</p>
<p>{place.address}</p>
<a
className="kv-button kv-button--primary"
href={`https://www.openstreetmap.org/directions?to=${place.position.latitude}%2C${place.position.longitude}`}
>
{texts.directions}
</a>
</div>
)}
</Map.Details>
<Map.ClusterPopup>
<div className="kv-map-details-content">
<Map.ClusterPopupTitle />
<Map.ClusterPopupClose />
<Map.ClusterPopupPlaces
renderPlace={(place, select) => (
<button type="button" className="kv-map-cluster-place-trigger" onClick={select}>
<LayerIcon layer={place.layer} /> {place.name}
</button>
)}
/>
</div>
</Map.ClusterPopup>
</Map.Root>
)}
</DocsMap>
)
}Props in this example:
childrenon Map.MarkersmarkerClassNameon Map.Markerschildrenon Map.Layerschildrenon Map.DetailsrenderPlaceon Map.ClusterPopupPlaces
Warning: Don't forget
A custom popup must keep titleProps on its title and a Close button, so focus and the dialog’s name still work. Wrap a whole template, in the details or the cluster popup, in kv-map-details-content to get the popup’s padding. A custom switch must name each layer and call setLayerHidden. A custom marker is decoration: its name comes from label, and the shape, not only the colour, tells the layers apart (1.4.1 Use of Color).
Accessibility#
What it does for you#
- APG pattern: none. There is no APG map pattern. The keys follow the keyboard interface practice, and the markers follow the Toolbar arrow model.
- Deviations: the markers in view are one Tab stop and the arrow keys move between them, where a Tab stop per marker is unusable with many places. Arrows on the viewport pan and
+/-zoom, while it has focus. Approved by the maintainer. - Native elements used:
<div role="region">(Viewport),<div role="group">(Markers, Controls),<button>(marker, cluster, controls, list row trigger, place in a cluster, Close),<a>(skip link), radio group (BaseMapSwitch),<fieldset>and checkboxes (Layers), a heading (h2by default,headingLevelsets it) and<ul>(List),<dialog open>(Details and ClusterPopup, non-modal) with an<img>, a heading,<p>for the body and address,<p>(Attribution).
A Map shows places on a camera over a base map, with the same places as a list. It is one focusable region you can pan and zoom from the keyboard, with a set of markers that is a single Tab stop, buttons for every gesture, and a list that is the screen reader user's equivalent of the map.
| Part | Element / role | ARIA / state | Notes |
|---|---|---|---|
| Map.Root | <div class="kv-map"> | none | Owns the camera, the selected place and the base map. label is the viewport's name |
| Map.Skip | <a> skip link | none | map.skipToList. Goes to the details title while a place is open, else to Map.List, else to href; nothing is rendered with none (2.4.1) |
| Map.Viewport | <div role="region" tabindex="0"> | aria-label the consumer's label, aria-roledescription map.roleDescription, aria-describedby the summary and the hint | The engine's canvas inside is aria-hidden and out of the tab order. data-status is loading, ready or failed |
| Map.Markers | <div role="group"> | aria-label map.markersLabel | One Tab stop: tabindex="0" on the selected marker, else the first, -1 on the others |
| Marker | <button> | named by the place's name, aria-expanded, aria-controls the details | Opens the details. data-highlighted while its list row is hovered |
| Map.Controls | <div role="group"> | aria-label map.controlsLabel | Icon-only buttons named map.zoomIn, map.zoomOut, map.panNorth and so on, a text button map.reset last (the zoom pair, the pan disc and Whole map are one visual stack in that order) |
| Map.Attribution | <p> | aria-label map.attributionLabel | The consumer's text and links. Native links |
| Map.BaseMapSwitch | <div> with a <button> and a popover (role="dialog") holding a radio group | button: name map.baseMapLabel, aria-expanded, aria-controls; popover: aria-label map.baseMapLabel; legend map.baseMapLabel | The button shows the current map. Renders nothing with fewer than two base maps. Native radios, as on the RadioGroup and Popover pages. The render function form replaces the button and the popover |
| Cluster | <button class="kv-map-cluster"> | named map.clusterLabel / map.clusterLayerLabel, aria-haspopup="dialog", aria-expanded, aria-controls the popup | Shares the one Tab stop with the markers. The visible count is part of the name (2.5.3). When its layer has an icon, the icon is drawn before the count by default, aria-hidden and not part of the name (1.4.1). Moves the cluster low in the view without zooming, then opens the popup |
| Map.Layers | <fieldset role="none"> holding a <button> and a <fieldset aria-label>; with collapsible={false} a <fieldset> with <legend> | button map.layersLegend (plus map.layersHiddenValue while collapsed and a layer is hidden), aria-expanded, aria-controls; inner fieldset aria-label map.layersLegend; one checkbox per layer named with its count (map.layerCountValue: "Hotels 100") | Open by default (defaultOpen, or open and onOpenChange). Collapsed, the panel is hidden: its checkboxes are not exposed and not in the Tab order. The fieldset is only the card, so a collapsed card has one name (the button's) and an open one names the group once; disabled still reaches every checkbox. The layer's description is the checkbox's help text; the swatch is aria-hidden. Renders nothing without layers. Native checkboxes, as on the Checkbox page |
| Map.ClusterPopup | <dialog open aria-labelledby> with a heading | the heading is map.clusterTitle / map.clusterLayerTitle; Close is named map.clusterClose with the title | Same frame as Details. A list of buttons, one per place, with the address under it. Only one of the two popups is open at a time. No focus trap |
| Map.List | <h2 tabindex="-1"> (headingLevel sets the level) and <ul role="list"> | each row's trigger is a <button aria-expanded aria-controls> | The heading states the count (map.placesInView or map.placesAll). Empty: map.listEmpty |
| Map.Details | <dialog open aria-labelledby> with a heading | Close is named map.detailsClose with the title | Heading tabindex="-1" takes focus on open. A non-modal popup, at every width: above the marker, below when there is no room above, scrolling inside the room it has. It never covers the marker and is never a panel under the map. No focus trap (Tab leaves it). Image: alt is the consumer's, '' when decorative; image, body and address are optional |
These are the rules the map follows (the Keyboard table names the test for each key; not every rule below has a test):
- Equivalent. Every place in the data is in the list, and the viewport's description states the count (1.1.1, 1.3.1).
- Names. The viewport's name is the consumer's
labeland its role description ismap.roleDescription. - Layers and clusters. The layers card collapses behind a button (open by default, so a long list does not cover the map); collapsed it shows how many layers are hidden. Hiding a layer removes its markers, clusters and list rows, closes a popup of its place or cluster, leaves focus on the checkbox, and announces
map.placesInView(ormap.placesAll). A cluster holds one layer's places, changes on whole zoom steps only, and the selected place is never in one. An open cluster that no longer exists closes, and focus follows the chain below. - Focus. Opening details or a cluster popup moves focus to its heading. Closing returns it to the opener (the marker, the cluster or the list row), else the list heading. Never
body(2.4.3). - Keys are taken only while the viewport has focus and never with Control, Command or Alt, so browser zoom keeps working (1.4.4, 2.1.4).
- Pointer. Drag pans, one finger scrolls the page on touch and two fingers pan, the wheel scrolls the page and zooms with Control or Command. A hint (
map.gestureTouch,map.gestureWheel) shows until the next interaction. Every gesture has a button (2.5.1, 2.5.7). Buttons are at least 24 by 24 CSS px (2.5.8). - Failure. When tiles fail,
map.tilesFailedTitleandmap.tilesFailedBodyshow in the viewport and the list still works (3.3.1). Test:map.test.tsx › when the tiles fail the viewport says so and the list still opens a place. - WCAG SCs: listed with their proof under WCAG SCs covered.
What you need to do#
- Keep the list. Render
Map.List, or your own list built withuseMapStateand aMap.Skipwithhref. Without a list, people who cannot use the map have no way to reach a place (1.1.1 Non-text Content, 2.1.1 Keyboard, 2.5.7 Dragging Movements). The library cannot check this. - Name the map.
labelis required. Write it in the page's language. - Describe place pictures.
image.altis required: describe the picture, or usealt=""when it only decorates (1.1.1). - Never tell layers apart by colour alone. Marker content is decoration and the name comes from
labelandclusterLabel. Give each layer an icon or a shape (1.4.1 Use of Color; seticonon the layer and its clusters draw it before the count; tested inmap.test.tsx › a cluster of a layer with an icon draws it before the count, hidden from the name), and keep each shape at 3:1 contrast against the map (1.4.11 Non-text Contrast). Keep the marker and cluster buttons at least 24 by 24 CSS px (2.5.8 Target Size (Minimum)). - Put the chrome where the map expects it.
Map.Layers,Map.BaseMapSwitch,Map.ControlsandMap.Attributiongo insideMap.Viewport. Wrap any floating part of your own inMap.Overlay, so a focused marker is moved out from under it (2.4.11 Focus Not Obscured (Minimum)). - Give a replaced map type switch a visible label when you pass a function to
Map.BaseMapSwitch(3.3.2 Labels or Instructions). - Prefer vector tiles. Raster tiles are images of text that do not follow the visitor's text size (1.4.4 Resize Text, 1.4.5 Images of Text).
- Choose the tile host and say so. The library has no default tile source. The visitor's IP address reaches the host you choose when the first tile is requested, so name that host in your privacy notice. Nothing is requested until a
Map.Rootwith a provider mounts. - Show the attribution that your tile or data licence asks for with
Map.Attribution. Leaving it out is a licence problem, not an accessibility one. - Keep
places,layersand the provider stable between renders (a constant oruseMemo). - Install the engine's CSS yourself (
maplibre-gl/dist/maplibre-gl.css), and under Vite passworkerUrl. The package ships neither. - Keep clustering on for a large source. With
cluster={false}, every place in view is a button on the page.
Warning: Don't forget
Keep a list of every place, and name the map with label. Without a list, someone who cannot use the map cannot reach a place (2.1.1 Keyboard).
Visual and modes#
- Focus. A keyboard-focused marker, control and list row show a ring in the focus colour with a
canvasgap, so it reads on any tile. A focused marker under an overlay is panned clear of it (2.4.7, 2.4.11). - Over imagery. Anything drawn on the map has a
canvasedge, then a 1pxtextedge (the halo), one of them light and one dark in every theme, so its edge is at least 3:1 on any tile (1.4.11). The pairs are the theme's, checked bytheme:check; no new pair. - Not colour alone. The selected marker differs by shape as well as colour, a checked map type by a check, and a layer by its name and swatch (1.4.1).
- Target size. Controls, markers, the Layers and Map type buttons and list rows are 44px (32px compact) with a mark of at least 24px (2.5.8).
- Reflow. Below 40rem the chrome is a grid around the map: Layers, Map type, the map, Controls as a wrapping row, then Attribution. Nothing clips at 320px or at 400% zoom (1.4.10). The Controls stay the alternative to a two-finger pan (2.5.7).
- Forced colours. The viewport, hint, status, attribution and control surfaces use
Canvaswith aCanvasTextedge, markers use system colours with a different shape for the selected one, a checked tile isHighlightwithHighlightTextplus its check, and disabled isGrayText. - Reduced motion. Colour, background, border, shadow and opacity change only under
prefers-reduced-motion: no-preference. Under reduced motion the camera jumps instead of easing. Nothing moves, scales or runs on exit. - Right-to-left. The chrome uses logical properties. The map and the pan buttons are physical, so the viewport arrows never flip, and the marker arrows flip (
map.test.tsx › the arrows pan the same way in RTL,map.test.tsx › the arrows move between the markers in RTL). - Raster tiles. A raster tile's labels are an image of text that does not follow the text size (1.4.4 Resize Text, 1.4.5 Images of Text, both AA). The tile source is yours; vector tiles are advised.
Focus management#
- Initial focus: none. The map never moves focus on its own: a pan, a zoom, a changed map type and a result shown on the map leave focus where the user put it (3.2.2).
- Opening details: focus moves to the details heading (
tabindex="-1"), so a screen reader reads the place. - Closing details: focus returns to the marker or the list row that opened them, else the list heading. Never
body. - Never obscured by: floating chrome never covers a keyboard-focused marker or cluster (2.4.11).
Map.Controls,Map.Attributionand the consumer'sMap.Overlayregister their element, and focus pans the map the smallest distance (least movement; centred when nothing fits) that clears the marker, padded by the focus ring and a gap, of every overlay and of the viewport's edge. The popup is not an overlay: it is anchored to the marker, and its room is the map's own row (the engine element), so below 40rem it never covers the controls (map.test.tsx › the details popup stays inside the map row when the viewport has more rows below it). Nothing is sticky.
WCAG success criteria#
- 1.1.1 Non-text Content (A), 1.3.1 Info and Relationships (A), 1.3.2 Meaningful Sequence (A): the list holds every place and the viewport states the count; the canvas is
aria-hidden(the Equivalent and Names rules, andmap.test.tsx › a marker with no children shows a decorative pin and keeps the place name). - 1.4.1 Use of Color (A), 1.4.11 Non-text Contrast (AA): shapes and the halo, with the theme's pairs checked by
theme:check. No unit test asserts the shapes. - 1.4.4 Resize Text (AA), 1.4.10 Reflow (AA): the
reflowsweep project renders the stories at 320px, which is 400% zoom.mapis insweepComponents(vite.config.ts), but the map stories have not been swept yet, so this stays pending. - 1.4.13 Content on Hover or Focus (AA): nothing opens on hover or focus alone; a popup opens on Enter or Space and closes with Escape (
map.test.tsx › Escape closes the details and returns focus). - 2.1.1 Keyboard (A), 2.1.2 No Keyboard Trap (A), 2.4.3 Focus Order (A): every row of the Keyboard table names a test.
- 2.4.7 Focus Visible (AA): the focus-ring pair is checked by
theme:check, and theforced-colorssweep runs the stories once the map stories are swept (pending). No keyboard test asserts the ring. - 2.1.4 Character Key Shortcuts (A): the keys are taken only while the viewport has focus and never with Control, Command or Alt (the viewport rows of the Keyboard table).
- 2.4.1 Bypass Blocks (A): the skip link (
map.test.tsx › Tab reaches the skip link and the viewport). - 2.4.11 Focus Not Obscured (Minimum) (AA):
map.test.tsx › a marker focused by keyboard under an overlay is panned clear of it,map.test.tsx › Map.Controls count as an overlay. - 2.5.1 Pointer Gestures (A), 2.5.7 Dragging Movements (AA): every gesture has a button (
map.test.tsx › the control buttons zoom, pan and reset). - 2.5.3 Label in Name (A): markers are named by the place and clusters by their count (the Names rules). 2.5.8 Target Size (Minimum) (AA): the theme sizes the targets; no test asserts it.
- 3.2.1 On Focus (A), 3.2.2 On Input (A): the map never moves focus on its own (
address-search.test.tsx › show(result) fits the bounds or centres, draws the pin, keeps focus and announces addressShown once settled). - 3.3.1 Error Identification (A): the tile failure message shows in the viewport, and the list still works (
map.test.tsx › when the tiles fail the viewport says so and the list still opens a place). - 4.1.2 Name, Role, Value (A), 4.1.3 Status Messages (AA): the roles and names in the table above, and the announcements above.
Keyboard#
- Focus
- roving tabindex
- Selection follows focus
- no (Enter or Space opens the details)
- Arrows wrap
- yes (the markers)
- Shortcuts
- none
| Key | Where | What happens |
|---|---|---|
| Tab | before the map | Moves focus to the skip link, then the viewport. The viewport is one stop Test: map.test.tsx › Tab reaches the skip link and the viewport |
| Shift+Tab | on the viewport | Moves focus back to the skip link, then the previous focusable element Test: map.test.tsx › Shift+Tab leaves the viewport backwards |
| ArrowUp / ArrowDown | on the viewport | Pans the map north or south by a quarter of the viewport's shorter side Test: map.test.tsx › the arrows pan the map |
| ArrowLeft / ArrowRight | on the viewport | Pans the map west or east. Spatial, so never flipped in RTL Test: map.test.tsx › the arrows pan the same way in RTL |
| + / = | on the viewport | Zooms in. With Control or Command it is the browser's Test: map.test.tsx › plus zooms in |
| - | on the viewport | Zooms out. With Control or Command it is the browser's Test: map.test.tsx › minus zooms out |
| Escape | on the viewport | Hides the keyboard hint; otherwise the page's Test: map.test.tsx › Escape hides the keyboard hint |
| Tab | after the viewport | Enters the markers at the selected one, else the first in list order. Layers and Map type come first when you render them before the markers. The next Tab leaves the markers Test: map.test.tsx › the markers are one Tab stop |
| ArrowRight / ArrowDown | on a marker | Moves to the next marker in list order, and wraps. ArrowRight flips to ArrowLeft in RTL Test: map.test.tsx › the arrows move between the markers |
| ArrowLeft / ArrowUp | on a marker | Moves to the previous marker, and wraps. ArrowLeft flips to ArrowRight in RTL Test: map.test.tsx › the arrows move between the markers in RTL |
| Home / End | on a marker | Moves to the first or the last marker Test: map.test.tsx › Home and End move to the first and last marker |
| Tab / ArrowUp / ArrowDown / ArrowLeft / ArrowRight | onto a marker or cluster | Keyboard focus only: if the marker is under a Map.Overlay, Map.Controls or Map.Attribution, or outside the viewport, the map pans the least that clears it, with the motion preference. Not announced; a pointer press never pansTest: map.test.tsx › a marker focused by keyboard under an overlay is panned clear of it |
| Enter / Space | on a marker | Opens its details. Focus moves to the details heading Test: map.test.tsx › Enter and Space open the details |
| Enter / Space | on a control button | Zooms, pans or resets the map. The change is announced Test: map.test.tsx › the control buttons zoom, pan and reset |
| Tab / Shift+Tab | across the controls | Moves through zoom in, zoom out, the four pan buttons (north, west, east, south) and Whole map, in that order: the visual order. Layers and Map type come before them when you render them first Test: map.test.tsx › Tab moves through zoom in, zoom out, the four pan buttons and Whole map |
| Enter / Space | on a list row's trigger | Opens that place's details and moves focus to the details heading Test: map.test.tsx › a list row opens the details |
| Tab / Shift+Tab | in a virtualized list (over 50 rows) | Enters at the last focused or opened row, else the first rendered one; the next Tab or Shift+Tab leaves the list. Up to 50 rows, every row's trigger is a stop Test: map.test.tsx › a virtualized list is one Tab stop |
| ArrowDown / ArrowUp | on a row in a virtualized list or cluster popup | Moves to the next or previous row, rendering and focusing it. Does not wrap, is not flipped in RTL Test: map.test.tsx › the arrows move between virtualized rows, map.test.tsx › the arrows move between virtualized rows in the cluster popup |
| Home / End | on a row in a virtualized list | Moves to the first or the last row Test: map.test.tsx › Home and End move to the first and last virtualized row, map.test.tsx › Home and End move to the first and last virtualized row in the cluster popup |
| PageUp / PageDown | on a row in a virtualized list | Moves by the number of rows that fit the scroll element Test: map.test.tsx › PageUp and PageDown move by a page of rows, map.test.tsx › PageUp and PageDown move by a page of rows in the cluster popup |
| Escape | focus inside the details | Closes the details and returns focus to the opener, else the list heading. Never bodyTest: map.test.tsx › Escape closes the details and returns focus, map.test.tsx › Escape closes the details and returns focus to the list heading when the opener is gone |
| Enter / Space | on Close in the details | Closes the details and returns focus to the opener Test: map.test.tsx › Close closes the details and returns focus |
| Tab | after the viewport | Clusters and markers are in the same single stop: enters at the selected marker, else the first in view Test: map.test.tsx › clusters and markers share the one Tab stop |
| Enter / Space | on a cluster | Opens the cluster popup and moves focus to its heading. aria-expanded is trueTest: map.test.tsx › Enter and Space open the cluster popup |
| Tab / Shift+Tab | in the cluster popup | Moves through the place buttons and Close, then leaves the popup (no trap) Test: map.test.tsx › Tab moves through the cluster popup |
| Enter / Space | on a place in a cluster | Closes the popup and opens that place's details. Focus goes to the details heading Test: map.test.tsx › a place in a cluster opens its details |
| Escape | focus in the cluster popup | Closes it and returns focus to the cluster, else the list heading Test: map.test.tsx › Escape closes the cluster popup and returns focus, map.test.tsx › Escape closes the cluster popup and returns focus to the list heading when the cluster is gone |
| Enter / Space | on Close in the cluster popup | Closes it and returns focus to the cluster Test: map.test.tsx › Close closes the cluster popup and returns focus |
| Enter / Space | on the layers button | Collapses or opens the layers card; focus stays on the button, aria-expanded follows. Collapsed, the checkboxes leave the Tab orderTest: map.test.tsx › Enter and Space on the layers button collapse and open the layers |
| Tab / Shift+Tab | past the collapsed layers button | The checkboxes are hidden, so Tab skips them (defaultOpen={false})Test: map.test.tsx › defaultOpen false starts with the layer checkboxes out of the Tab order and not exposed |
| Enter / Space | on the layers button, with open set | Reports the new state in onOpenChange; the card follows openTest: map.test.tsx › open and onOpenChange control the layers card |
| Space | on a layer checkbox (a layer row) | Toggles the layer: its markers, clusters and list rows go or return, map.placesInView is announced, focus staysTest: map.test.tsx › a layer checkbox toggles with Space |
| Enter / Space | on the Map type button | Opens the popover without moving focus; the radios follow the button in the Tab order Test: map.test.tsx › Map type opens from its button, an arrow key changes the map, Escape returns focus |
| ArrowUp / ArrowDown / ArrowLeft / ArrowRight | on a map type radio | Native: moves the choice and changes the map type, which is announced Test: map.test.tsx › Map type opens from its button, an arrow key changes the map, Escape returns focus |
| Escape | focus in the Map type popover | Closes it and returns focus to the Map type button Test: map.test.tsx › Map type opens from its button, an arrow key changes the map, Escape returns focus |
The map takes no other key. Keys on the viewport are read only while the viewport itself has focus, so a button or a link inside keeps its own keys. Control, Command and Alt combinations are never taken.
Information: Did you know?
Only the map itself takes keys, and only while it has focus. Combinations with Control, Command or Alt are never taken, so the browser’s own zoom keeps working (2.1.4 Character Key Shortcuts).
Announcements#
Map tells screen reader users about these changes without moving focus. Each message waits until the screen reader is quiet (polite) or interrupts it (assertive).
| When | What it says | Message key | Politeness |
|---|---|---|---|
| The view settles (about 500 ms later) after a key, a button or Whole map moved it, and the count of places changed | 12 places in the map view. | map.placesInView map.placesAll | Polite |
| A layer is shown or hidden | 12 places in the map view. | map.placesInView map.placesAll | Polite |
| A zoom button or key is used at the limit | You can't zoom in any further. | map.zoomLimitIn map.zoomLimitOut | Polite |
| The tile source fails (once per failure) | The map can't be shown right now | map.tilesFailedTitle | Polite |
| The visitor changes the map type | Map type: Satellite. | map.baseMapChanged | Polite |
| The index of a large source starts to build (once) | Loading the places | map.indexing | Polite |
The text in all five languages
Change the text#
For your whole app, pass messages to KvirnProvider. For one Map, pass its messages prop.
<KvirnProvider messages={{ map: { placesInView: '12 places in the map view.' } }}>Warning: Don't forget
Announcements need a KvirnProvider around your app, outside any <form>, or an Announcer of your own. Without one nothing is announced, and a development warning says so.
API reference#
Install the package. Install MapLibre only if you use its adapter. Import the styles once, after the theme.
pnpm add @kvirn-ui/map
pnpm add maplibre-glimport '@kvirn-ui/theme/theme.css'
import '@kvirn-ui/theme/map.css'
import 'maplibre-gl/dist/maplibre-gl.css'Information: Implement like this
Create the provider once, outside your component, so the instance stays the same between renders. Use a tile host you have an agreement with, and say so in your privacy notice.
import { maplibre, rasterStyle } from '@kvirn-ui/map/maplibre'
// Create it once, outside your component. The tile address is yours.
export const provider = maplibre({
style: rasterStyle({
tiles: ['https://tiles.example.org/{z}/{x}/{y}.png'],
attribution: '© Example municipality',
}),
})import { Map, createMemoryProvider, useMap, useMapState } from '@kvirn-ui/map'
import { maplibre, rasterStyle } from '@kvirn-ui/map/maplibre'
import { createMapWorker } from '@kvirn-ui/map/worker'Map.Root
Renders <div class="kv-map">. It owns the camera, the open place and the map type, and it takes every attribute of a <div>. It is a container, so the layout changes at 40rem of the map’s own width, not the page’s. Put Map.Skip, Map.Viewport, Map.List and the popups inside. Also exported as MapRoot.
| Prop | Type | Default | Description |
|---|---|---|---|
provider | MapProvider | Required | The engine adapter that draws the map: maplibre({ style }), createMemoryProvider() or your own. Keep the same instance between renders. |
label | string | Required | The map’s name, which a screen reader reads for the map region. Write it in your language: “Map of preschools”. |
initialView | { center: { longitude, latitude }, zoom } | Required | Where the map starts, and where the Whole map button returns to. Changing the prop later does not move the camera. |
places | readonly MapPlace[] | – | The places, up to a few thousand. Keep the array the same between renders. For more, use source. |
source | MapPlaceSource | – | The places as columns, for tens of thousands to millions. No object exists for a place until a marker, a row or a popup needs it. Use it instead of places, and keep it the same between renders. |
indexIn | 'main' | (() => MapIndexer) | 'main' | “main” builds the index of a large source on the page, in slices of 8 ms. Pass createMapWorker from @kvirn-ui/map/worker to build it in a Web Worker instead. |
baseMap | string | – | The id of the active map type. Set it to control the map type yourself and update it in onBaseMapChange. Without it the map keeps its own. |
defaultBaseMap | string | The provider’s, else the first | The map type to start on when baseMap is not set. |
onBaseMapChange | (id: string) => void | – | Called with the id when a visitor picks a map type. |
layers | readonly MapLayer[] | – | The groups of places. A place joins one with its layer. Keep the array the same between renders. |
readonly string[] | – | The ids of the hidden layers. Set it to control them yourself and update it in onHiddenLayersChange. | |
readonly string[] | [] | The layers that start hidden when hiddenLayers is not set. | |
(ids: readonly string[]) => void | – | Called with the ids that are now hidden when a visitor shows or hides a layer. | |
cluster | boolean | { radius?: number } | true | Groups nearby places of one layer into a cluster. The radius is 64 CSS pixels, so two clusters stay about 44 pixels (one target) apart. false turns clustering off, and a layer with cluster: false is never clustered. A cluster holds places of one layer only. |
messages | Partial<KvirnMessages["map"]> | – | Changes the map’s texts for this map. See Strings below for every key and its English text. |
| Class or attribute | Values | Meaning |
|---|---|---|
--kv-map-block-size | a length | The height of the map. The default is clamp(15rem, 60vh, 40rem). Set it on the Root or on any element around it. |
Map.Skip
Renders A skip link (SkipLink) to the list. Put it before the viewport.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | map.skipToList | The link text. |
href | string | – | The target when you build your own list instead of Map.List, such as #my-list-heading. The link goes to the open place’s title while a place is open, else to Map.List, else to href. With none of them it renders nothing. |
Map.Viewport
Renders <div role="region" tabindex="0">, named by the Root’s label and described as a map. The engine draws into it, and the markers, controls, layers and attribution are its children. It takes every attribute of a <div> except the role, the tab index and the aria-* it sets. It shows the keyboard hint, the loading and failed messages, and the gesture hint.
| Class or attribute | Values | Meaning |
|---|---|---|
data-status | loading | ready | failed | On the viewport. Loading shows a spinner and the loading message, and failed shows that the tiles could not load. The list keeps working in both. |
data-dismissed | present or absent | On the keyboard hint, once Escape has hidden it. |
data-gesture | touch | wheel | On the gesture hint: the gesture the engine ignored so that the page can scroll (one finger, or the wheel without Control or Command). |
Map.Markers
Renders <div role="group"> of buttons, one per place and one per cluster in the map view. They are one Tab stop. It renders nothing while nothing is in view.
| Prop | Type | Default | Description |
|---|---|---|---|
children | (place, { selected, highlighted, layer }) => ReactNode | – | The content of a marker: a 16 pixel icon, or a name chip in kv-map-marker-label. It is decoration inside the one button, so it is not read. The name comes from label. |
label | (place, layer) => string | The place’s name | The marker’s accessible name. Put the information in it, such as the layer: “Torget recycling station, Recycling stations”. |
markerClassName | string | ((place, layer) => string) | – | A class on every marker, or one per place, for example one per layer. |
cluster | (cluster, { opened, layer }) => ReactNode | The number of places | The content of a cluster’s button. |
clusterLabel | (cluster, layer) => string | map.clusterLabel | The cluster’s accessible name. The default is the number of places, with the layer’s name when it has one. |
clusterClassName | string | ((cluster, layer) => string) | – | A class on every cluster, or one per cluster, for example one per layer. |
| Class or attribute | Values | Meaning |
|---|---|---|
data-selected | present or absent | On a marker whose details are open. |
data-highlighted | present or absent | On a marker while its list row is hovered, and on the row while the marker is. |
aria-expanded | true | false | On a marker or cluster while its popup is open. |
Map.Marker, Map.Cluster
Renders One native <button> each, a large touch target (44 pixels by default). A cluster has aria-haspopup="dialog". Pressing a marker opens its details, and pressing a cluster opens its popup. Use Map.Markers, which renders them.
| Prop | Type | Default | Description |
|---|---|---|---|
place | MapPlace | Required | On Map.Marker: the place the button stands for. Use Map.Markers, which renders the set. |
cluster | MapCluster | Required | On Map.Cluster: the cluster the button stands for. Use Map.Markers, which renders the set. |
Map.Controls
Renders <div role="group"> of buttons: zoom in, zoom out, four pan buttons and Whole map, in that order. Each is the single-pointer alternative to a drag or a two-finger gesture. It takes every attribute of a <div>.
Map.Overlay
Renders <div class="kv-map-overlay"> for chrome of your own that floats over the map, such as a search box or a legend. Put it inside Map.Viewport and position it with your own classes. A marker reached by keyboard is moved out from under it.
| Prop | Type | Default | Description |
|---|---|---|---|
as | ElementType | 'div' | Another tag or component to render. |
Map.Attribution
Renders A <p> named “Map data”, with the text and links of the active map type. Native links.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | ((baseMap) => ReactNode) | The active map type’s attribution | The text and links your tile or data licence asks for. It renders nothing without text. |
Map.BaseMapSwitch
Renders A button showing the current map type that opens a popover of preview tiles, one native radio each. It renders nothing with fewer than two map types. It takes every attribute of a <div>.
| Prop | Type | Default | Description |
|---|---|---|---|
icon | (baseMap) => ReactNode | A plain preview | A decorative preview of a map type, such as a small tile image. It is not read. |
children | ({ baseMaps, baseMap, setBaseMap, label }) => ReactNode | – | Replaces the button and the tiles, for example with a native select in a Field. Give your control a visible label and render it outside Map.Viewport. |
Map.Layers
Renders A card titled “Show on the map” that collapses behind a button, and one native checkbox per layer, named with its count: “Hotels 100”. While collapsed, the button says how many layers are hidden. A layer’s description is the checkbox’s help text. It renders nothing without layers.
| Prop | Type | Default | Description |
|---|---|---|---|
icon | (layer) => ReactNode | – | A decorative swatch before the layer’s name, such as the layer’s marker icon. It is not read: the name and count are. |
layerClassName | (layer) => string | undefined | – | A class on each layer’s row, so a swatch can match its markers. |
children | ({ layers, hiddenLayerIds, setLayerHidden, counts }) => ReactNode | – | Replaces the checkboxes, for example with a switch per layer. |
collapsible | boolean | true | Lets the visitor collapse the card behind its title. `false` keeps it always open, with no button. |
defaultOpen | boolean | true | Whether the layers start shown. Set `false` for a long list of layers, so the card does not cover the map. |
open | boolean | – | Controlled: whether the layers are shown. Pair it with `onOpenChange`. |
onOpenChange | (open: boolean) => void | – | Called when the visitor opens or closes the card, with the new state. |
Map.List
Renders A heading that states the count, then a <ul> with a button per place in the map view. It is hidden while a place’s details are open. It is the equivalent of the map for people who do not use it.
| Prop | Type | Default | Description |
|---|---|---|---|
icon | (place) => ReactNode | – | A decorative swatch before each row, such as the place’s marker icon. |
rowClassName | (place) => string | undefined | – | A class on each row. |
children | (place) => ReactNode | – | Extra facts under the name, such as opening hours. Keep them non-interactive: the whole row is one button. A node with the class kv-map-list-aside sits at the row’s end. |
| Class or attribute | Values | Meaning |
|---|---|---|
data-highlighted | present or absent | On a row while its marker is hovered. |
data-virtualized | present or absent | On the scroll element past 50 places. Only the rows in view are rendered, each with aria-setsize and aria-posinset, and the list is one Tab stop. |
Map.Details
Renders <dialog open>, a non-modal popup anchored to the open place’s marker: above it, below when there is no room, and scrolling inside the room it has. It has no focus trap. Focus moves to its title, and Escape or Close returns it to the marker or the list row that opened it. It renders nothing while no place is open.
| Prop | Type | Default | Description |
|---|---|---|---|
as | ElementType | 'dialog' | Another tag or component to render. The default is an open, non-modal dialog. |
children | ReactNode | ((state) => ReactNode) | – | Without children: the picture, the title with Close, the body and the address, each only when the place has it. With nodes: exactly those, in your order, from the Map.Details parts or your own markup. With a function: the whole template, from { place, close, titleProps, side }. Keep a Map.DetailsTitle or put titleProps on your heading: it names the dialog. |
| Class or attribute | Values | Meaning |
|---|---|---|
--kv-map-popup-inline-size | a length | The width of a popup. The default is 22rem, and it never goes past the map. |
--kv-map-popup-radius | a length | The corner radius of a popup. The default is the theme’s medium radius. |
kv-map-details-footer | a class | Put it on a row of your own actions at the end of the popup. It stays at the bottom while the content scrolls. |
Map.DetailsImage, Map.DetailsTitle, Map.DetailsBody, Map.DetailsAddress, Map.DetailsClose
Renders The parts of a popup, for when you rearrange it. The picture is an <img> with the place’s alt, the title is an <h3> that names the dialog and takes focus, and Close is an icon button named “Close” plus the title. The picture, body and address render nothing when the place has none.
| Prop | Type | Default | Description |
|---|---|---|---|
as | ElementType | img, h3, p, p | On DetailsImage, DetailsTitle, DetailsBody and DetailsAddress: another tag for the part, such as h2 for the title. DetailsClose has no as. |
children | ReactNode | The place’s own text | On DetailsTitle (the place’s name), DetailsBody (its description) and DetailsAddress (its address). DetailsClose shows a close icon. |
Map.ClusterPopup
Renders <dialog open> with the places of a cluster, in the same frame as the details. Only one of the two popups is open at a time. It renders nothing while no cluster is open.
| Prop | Type | Default | Description |
|---|---|---|---|
as | ElementType | 'dialog' | Another tag or component to render. The default is an open, non-modal dialog. |
children | ReactNode | ((state) => ReactNode) | – | Without children: the title with Close, then one button per place. With nodes: exactly those, from the Map.ClusterPopup parts. With a function: the whole template, from { cluster, close, select, titleProps, side }, where select(placeId) closes the popup and opens that place’s details. |
Map.ClusterPopupPlaces
Renders A <ul> with a button per place and its address under it. Past 50 places it shows only the rows in view and is one Tab stop.
| Prop | Type | Default | Description |
|---|---|---|---|
renderPlace | (place, select) => ReactNode | A button with the name and the address under it | Replaces a row. Call select to open that place’s details. |
Map.ClusterPopupTitle, Map.ClusterPopupClose
Renders The title (an <h3>, which takes focus and names the dialog) and the Close button of a cluster popup. The title takes as.
MapPlace
Renders nothing: it is the object you pass in places.
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | Required | A stable id, used for the marker, the row and the focus. |
name | string | Required | The place’s name: the marker’s name, the list row’s text and the popup’s title. |
position | { longitude: number; latitude: number } | Required | Where it is. |
layer | string | – | The id of the layer the place belongs to. |
address | string | – | Shown under the name in the list and in the popup. |
description | string | – | The body of the popup. |
image | { src: string; alt: string } | – | The picture at the top of the popup. alt is required and in your language: use an empty string when the picture only decorates. |
data | Data | – | Your own object for the place, handed back to every render function. |
MapLayer
Renders nothing: it is the object you pass in layers.
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | Required | The id a place names in its layer. |
label | string | Required | The layer’s name, in the checkbox and in cluster names. |
description | string | – | Help text for the layer’s checkbox. |
cluster | boolean | true | false: places of this layer are never grouped into clusters. |
MapPlaceSource
Renders nothing: it is the object you pass in source, for a very large set of places.
| Prop | Type | Default | Description |
|---|---|---|---|
count | number | Required | How many places there are. |
positions | Float64Array | Required | Longitude and latitude of every place, interleaved: length count × 2. |
layers | Uint16Array | – | For each place, the index of its layer in layers, or NO_LAYER (from @kvirn-ui/core) for none. |
get | (index: number) => MapPlace | Promise<MapPlace> | Required | The place at an index, built when a marker, a row or a popup needs it. It may return a promise (a server call); a failed one is not tried again. placesToSource(places, layers) from @kvirn-ui/core shows the shape. |
maplibre
Renders nothing: maplibre(options) from @kvirn-ui/map/maplibre returns the provider for MapLibre GL. MapLibre is an optional peer: install it only for this adapter. These are its options.
| Prop | Type | Default | Description |
|---|---|---|---|
style | string | StyleSpecification | – | A MapLibre style document, or the URL of one. There is no default: you choose the tile source. Use style or baseMaps. |
baseMaps | readonly { id, label, attribution?, style }[] | – | Instead of style: a list of map types the visitor can switch between with Map.BaseMapSwitch. |
defaultBaseMap | string | The first | With baseMaps: the id to start on. |
workerUrl | string | – | The URL of maplibre-gl/dist/maplibre-gl-worker.mjs. A bundler that pre-bundles dependencies (Vite in development) needs it. |
attribution | string | – | Attribution that the style’s sources do not already carry. |
rasterStyle
Renders nothing: rasterStyle(options) from @kvirn-ui/map/maplibre returns a MapLibre style from your own tile addresses, for maplibre({ style }). These are its options.
| Prop | Type | Default | Description |
|---|---|---|---|
tiles | string[] | Required | URL templates with {z}, {x} and {y} from your tile host. The library names none. |
attribution | string | Required | The source’s licence text. Show it with Map.Attribution. |
tileSize | number | 256 | The size of a tile in pixels. |
minzoom | number | – | The lowest zoom the source has. |
maxzoom | number | – | The highest zoom the source has. |
createMemoryProvider
Renders nothing: createMemoryProvider(options) returns a provider with no engine. It keeps the camera, draws nothing and sends nothing, so it suits tests and pages with no picture. These are its options.
| Prop | Type | Default | Description |
|---|---|---|---|
size | { width: number; height: number } | { width: 800, height: 600 } | The size the camera works with, in pixels. The provider draws nothing, so it cannot read the real size. |
baseMaps | readonly MapBaseMap[] | – | Map types to list, so Map.BaseMapSwitch and Map.Attribution have something to show. |
defaultBaseMap | string | – | The map type to start on. |
createMapWorker
Renders nothing: a function from @kvirn-ui/map/worker that you pass as indexIn. The map creates the Web Worker when it builds the index of a large source and stops it afterwards, so you own nothing. The entry is ESM only.
useMap
The state behind Map.Root: it takes the same options and returns the same object as useMapState. Map.Root calls it for you, so you rarely need it.
Options
| Prop | Type | Default | Description |
|---|---|---|---|
provider | MapProvider | Required | The engine adapter that draws the map: maplibre({ style }), createMemoryProvider() or your own. Keep the same instance between renders. |
label | string | Required | The map’s name, which a screen reader reads for the map region. Write it in your language: “Map of preschools”. |
initialView | { center: { longitude, latitude }, zoom } | Required | Where the map starts, and where the Whole map button returns to. Changing the prop later does not move the camera. |
places | readonly MapPlace[] | – | The places, up to a few thousand. Keep the array the same between renders. For more, use source. |
source | MapPlaceSource | – | The places as columns, for tens of thousands to millions. No object exists for a place until a marker, a row or a popup needs it. Use it instead of places, and keep it the same between renders. |
indexIn | 'main' | (() => MapIndexer) | 'main' | “main” builds the index of a large source on the page, in slices of 8 ms. Pass createMapWorker from @kvirn-ui/map/worker to build it in a Web Worker instead. |
baseMap | string | – | The id of the active map type. Set it to control the map type yourself and update it in onBaseMapChange. Without it the map keeps its own. |
defaultBaseMap | string | The provider’s, else the first | The map type to start on when baseMap is not set. |
onBaseMapChange | (id: string) => void | – | Called with the id when a visitor picks a map type. |
layers | readonly MapLayer[] | – | The groups of places. A place joins one with its layer. Keep the array the same between renders. |
readonly string[] | – | The ids of the hidden layers. Set it to control them yourself and update it in onHiddenLayersChange. | |
readonly string[] | [] | The layers that start hidden when hiddenLayers is not set. | |
(ids: readonly string[]) => void | – | Called with the ids that are now hidden when a visitor shows or hides a layer. | |
cluster | boolean | { radius?: number } | true | Groups nearby places of one layer into a cluster. The radius is 64 CSS pixels, so two clusters stay about 44 pixels (one target) apart. false turns clustering off, and a layer with cluster: false is never clustered. A cluster holds places of one layer only. |
messages | Partial<KvirnMessages["map"]> | – | Changes the map’s texts for this map. See Strings below for every key and its English text. |
useMapState
Reads the map’s state inside Map.Root, so you can build a part the library does not render, such as your own list of places. It throws outside Map.Root. This is a selection of what it returns.
Result
| Prop | Type | Default | Description |
|---|---|---|---|
placesInView | MapPlace[] | – | The places in the map view, on a visible layer. It builds every place, so use it for a short list only. |
visiblePlaces | MapPlace[] | – | Every place on a visible layer. It builds every place too. |
visibleCount | number | – | How many places are on a visible layer. |
placesInViewCount | number | – | How many of them are in the map view. |
getPlaceInView | (index: number) => MapPlace | undefined | – | The place at a position in the list of places in view, in source order. Use it with placesInViewCount for a long list. |
indexing | boolean | – | True while the index of a large source is being built. Markers appear when it is done. |
layerCounts | Record<string, number> | – | How many places each layer has. |
layers | readonly MapLayer[] | – | The layers you passed. |
readonly string[] | – | The ids of the hidden layers. | |
(layerId: string, hidden: boolean) => void | – | Shows or hides a layer. It closes a popup of a place or cluster on that layer and announces the new count. | |
markersInView | MapMarkerItem[] | – | The places and clusters drawn as markers. |
selectedPlace | MapPlace | null | – | The place whose details are open. |
openedCluster | MapCluster | null | – | The cluster whose popup is open. |
select | (placeId: string, openerId?: string) => void | – | Opens a place’s details. Focus moves to the title, and closing returns it to the element with openerId. |
close | () => void | – | Closes the details. |
openCluster | (clusterId: string | null, openerId?: string) => void | – | Opens a cluster’s popup, or closes it with null. |
clusterMarkerId | (clusterId: string) => string | – | The id of a cluster’s button, for openCluster. |
baseMaps | readonly MapBaseMap[] | – | The provider’s map types. |
baseMap | string | null | – | The active map type’s id. |
setBaseMap | (id: string) => void | – | Changes the map type, keeps the camera and announces the change. |
zoomIn | () => void | – | Zooms in one step, or announces the limit. |
zoomOut | () => void | – | Zooms out one step, or announces the limit. |
reset | () => void | – | Returns to initialView. |
view | MapView | – | The camera: center and zoom. |
status | 'loading' | 'ready' | 'failed' | – | Whether the tiles have loaded. |
messages | ResolvedMessages | – | The map’s texts, with your overrides applied. |
ids | object | – | The ids the parts use, such as details (for aria-controls) and listHeading (for your own list’s skip link). |
show | (target: MapPlace | AddressResult) => void | – | Centres the map on a place or an address, or fits the address’s bounds, without moving focus. A place also opens its details. An address draws the result pin and announces that the map shows it once the view settles. |
searchResult | AddressResult | null | – | The address that show drew a pin for, until clearResult. |
clearResult | () => void | – | Removes the result pin. It announces nothing. |
setHighlightedPlaceId | (placeId: string | null) => void | – | Highlights a marker and its row, as hovering one does. |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one Map, pass its messages prop.
The map’s texts exist in all five languages. Have a native speaker review the Swedish, Finnish and Norwegian ones before you launch. Your map’s label, your layer names and your place data are yours, so write them in the page’s language.
| Message key | Parameters | Default text in English | Used for |
|---|---|---|---|
roleDescription | – | map | The role a screen reader says for the map region. |
summary | count | The map shows 12 places. The same places are in the list. | Read after the map’s name: how many places are drawn. |
keyboardHint | – | Move the map with the arrow keys. Zoom with + and −. | The hint on the map until the next interaction. |
skipToList | – | Skip the map, go to the list of places | The text of the skip link. |
controlsLabel | – | Map controls | The name of the group of control buttons. |
markersLabel | – | Places in the map view | The name of the group of markers. |
zoomIn | – | Zoom in | The name of the zoom in button. |
zoomOut | – | Zoom out | The name of the zoom out button. |
zoomLimitIn | – | You can't zoom in any further. | Announced when the map cannot zoom in any further. |
zoomLimitOut | – | You can't zoom out any further. | Announced when the map cannot zoom out any further. |
reset | – | Whole map | The text of the button that returns to the start view. |
panNorth | – | Move the map north | The name of the pan north button. |
panSouth | – | Move the map south | The name of the pan south button. |
panEast | – | Move the map east | The name of the pan east button. |
panWest | – | Move the map west | The name of the pan west button. |
placesInView | count | 12 places in the map view. | Announced after the view settles, and the list’s heading, when some places are out of view. |
placesAll | count | 12 places. | Announced, and the list’s heading, when every place is in view. |
loading | – | Loading the map | Shown in the viewport while the map loads. |
tilesFailedTitle | – | The map can't be shown right now | Shown, and announced once, when the tiles fail. |
tilesFailedBody | – | You can still find every place in the list. | Shown under the failed title: the list still works. |
gestureTouch | – | Use two fingers to move the map | The hint when one finger is used on a touch screen. |
gestureWheel | modifier | Hold Ctrl and scroll to zoom the map | The hint when the wheel is used without the modifier key. |
detailsClose | – | Close | The first part of the popup’s Close name. |
listEmpty | – | There are no places in the map view. Zoom out or move the map. | Shown in place of the list when no place is in view. |
indexing | – | Loading the places | Announced once while the index of a large source builds. |
attributionLabel | – | Map data | The name of the attribution text. |
baseMapLabel | – | Map type | The name and legend of the map type switch. |
baseMapChanged | label | Map type: Satellite. | Announced when the visitor changes the map type. |
clusterLabel | count | 12 places | The name of a cluster button. |
clusterLayerLabel | count layer | Hotels: 12 places | The name of a cluster button when it belongs to a layer. |
clusterTitle | count | 12 places | The title of a cluster popup. |
clusterLayerTitle | count layer | Hotels: 12 places | The title of a cluster popup when it belongs to a layer. |
clusterClose | – | Close | The first part of a cluster popup’s Close name. |
layersLegend | – | Show on the map | The title of the layers card and its button. |
count | 3 hidden | After the title while the card is collapsed and layers are hidden. | |
layerCountValue | count | 100 | The count after a layer’s name in its checkbox. |
Known issues#
- Review the translations before you launch. Have a native speaker review the Swedish, Finnish, Norwegian Bokmål and Norwegian Nynorsk texts before you launch. Override any text with the
messagesprop or the provider'smapcatalog. Your own map label, layer names and place data are in your language already. - Markers under the floating cards cannot be pressed there. Where the Layers or Map type card covers a marker, use the list or the keyboard, which pans the marker clear (2.4.11).
- Test with your users and their assistive technology. A map is hard to make equal for everyone, so check the viewport, the layer checkboxes, the pan buttons and the list with the assistive technology your users have.
- Markers of different layers can touch. Layers cluster separately, so a cluster of one layer can sit on a marker or cluster of another. Every place stays reachable from the keyboard (arrow keys between markers) and in the list.
cluster={false}with a large source puts every place in view on the page as a button. The map warns once in development past 2,000 markers, and does not cap them. Keep clustering on, or turn it off only for small layers.- The map has no address search of its own. To let a visitor search for an address, put an AddressSearch beside the map (
address-search.a11y.md). A visitor otherwise finds a place by the markers, the list and the layers.
Information: Did you know?
If an issue here affects your service, list it in your accessibility statement with its workaround.
Testing#
The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.
| AT + browser + OS | Agent check | Human check | Result | Notes |
|---|---|---|---|---|
| Automated (re-runnable tests) | ||||
| axe, WCAG 2.2 A and AA, every story, 4 themes | pass | n/a | pass | map.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pending | n/a | pending | the test has no axe check |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 35 rows, each names a test (map.test.tsx › Tab reaches the skip link and the viewport) |
| Focus order and management | pass | n/a | pass | map.test.tsx asserts focus (toHaveFocus); first rule: Tab reaches the skip link and the viewport |
| Display modes (forced colours, 320px reflow, text spacing, reduced motion) | pending | n/a | pending | map is in sweepComponents (vite.config.ts), so the four sweep projects run its stories in CI |
| Core (required for beta) | ||||
| NVDA + Chrome + Windows | pending | pending | pending | |
| VoiceOver + Safari + iOS | pending | pending | pending | |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | pending | pending | pending | |
| TalkBack + Chrome + Android | pending | pending | pending | |
| VoiceOver + Safari + macOS | pending | pending | pending |
Information: Did you know?
The map is checked with automated accessibility tests and keyboard tests. Test with the assistive technology your residents use before you rely on the map, and keep the list.