Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/focus-after-processing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

Focus no longer drops to the page while a form is busy. `Form` gives focus back to the field you were in after an Enter submit (its fields are disabled while it processes), and `CommentThread`'s composer puts focus back in the text box after posting.
5 changes: 5 additions & 0 deletions .changeset/number-input-locale-digits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`NumberInput` reads and edits numbers in a `numberLocale` with its own digits (for example Arabic-Indic `١٢٣` in `ar-EG`). It used to reject them, so it couldn't parse its own draft. `numberSymbols()` also returns the locale's `digits`.
5 changes: 5 additions & 0 deletions .changeset/optional-map-peers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

An app that uses `@javaabu/onu/charts` without the optional map peers (`@vis.gl/react-google-maps`, deck.gl) now builds with webpack too; it used to fail with "Module not found". `MapChart` loads them on demand and, when they are missing, shows a note and the data table instead of the map.
5 changes: 5 additions & 0 deletions .changeset/slash-menu-in-dialog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

The `BlockEditor` slash menu works inside a modal: it now opens inside the dialog, so it can be clicked and screen readers can reach it.
5 changes: 5 additions & 0 deletions .changeset/time-series-zoom-reset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`TimeSeriesChart` with `brush` resets its zoom when `data` changes to cover other dates, instead of keeping a range (and "Showing …" read-out) from the old data. Inline `data` with the same dates keeps the zoom.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- run: pnpm install --frozen-lockfile
- run: pnpm exec playwright install --with-deps chromium
- run: pnpm build:web
- run: pnpm e2e:chromium e2e/a11y.spec.ts e2e/thaana.spec.ts
- run: pnpm e2e:chromium e2e/a11y.spec.ts e2e/thaana.spec.ts e2e/browser.spec.ts
- uses: actions/upload-artifact@v4
if: failure()
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ssr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ on:
paths:
- packages/onu/**
- e2e/nextjs/**
- e2e/optional-peers/**
- scripts/check-optional-peers.mjs
- pnpm-lock.yaml
- pnpm-workspace.yaml
- .github/workflows/ssr.yml
pull_request:
paths:
- packages/onu/**
- e2e/nextjs/**
- e2e/optional-peers/**
- scripts/check-optional-peers.mjs
- pnpm-lock.yaml
- pnpm-workspace.yaml
- .github/workflows/ssr.yml
Expand Down Expand Up @@ -50,3 +54,5 @@ jobs:
run: pnpm --filter onu-nextjs-fixture build
- name: Check the server HTML and hydration
run: pnpm --filter onu-nextjs-fixture test:ssr
- name: Build an app without the optional peers (webpack and Turbopack)
run: node scripts/check-optional-peers.mjs
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pnpm build && pnpm --filter @javaabu/onu size # build + bundle budgets
pnpm build:web # docs site
node scripts/check-docs.mjs # every component has a docs page with Props + Accessibility
node scripts/check-pack.mjs # no test files in the npm tarballs
node scripts/check-optional-peers.mjs # an app without the optional peers still builds (after pnpm build)
pnpm e2e:chromium # Playwright (a11y with axe, visual)
```

Expand Down
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ The files in `packages/onu/src/ui` started as shadcn/ui's components (Radix base

E2E (Playwright) runs in two tiers:

- **Smoke, on pull requests.** The **E2E smoke** workflow runs `e2e/a11y.spec.ts` and `e2e/thaana.spec.ts` in Chromium, with no screenshots, when a pull request touches `packages/onu/**`, `web/**` or `e2e/**`.
- **Smoke, on pull requests.** The **E2E smoke** workflow runs `e2e/a11y.spec.ts`, `e2e/thaana.spec.ts` and `e2e/browser.spec.ts` in Chromium, with no screenshots, when a pull request touches `packages/onu/**`, `web/**` or `e2e/**`.
- **Full, on demand.** The **E2E** workflow (accessibility in five browsers, and Chromium screenshots) is slow, so CI runs it only when the last commit pushed to `main` starts with `e2e` (for example `e2e: new date picker`), or when you run it by hand from the Actions tab.

Run either locally with `pnpm e2e:chromium`, adding the two spec files for the smoke tier.
Run either locally with `pnpm e2e:chromium`, adding the three spec files for the smoke tier.

`e2e/browser.spec.ts` covers behaviour jsdom can't show (focus after re-renders, inert modal backgrounds, `IntersectionObserver`, downloads, chart layout). Each scenario is a small page in `web/src/e2e/<name>.harness.tsx`, served at `#/e2e/<name>` and left out of the navigation and the a11y and visual runs.

Server rendering has its own check. The **Server rendering** workflow builds the Next.js app in `e2e/nextjs` against the workspace copy of Onu, then checks its server HTML and hydration in English and Dhivehi, when a pull request touches `packages/onu/**` or `e2e/nextjs/**`. Run it locally with `pnpm build && pnpm --filter onu-nextjs-fixture build && pnpm --filter onu-nextjs-fixture test:ssr`.

Expand Down
2 changes: 1 addition & 1 deletion docs/charts/map-chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sidebar_position: 9
A choropleth map: regions shaded by value on Google Maps, drawn with a deck.gl `GeoJsonLayer` (`GoogleMapsOverlay`). It has a stepped legend, a tap/hover read-out and a data table. Without a Google Maps API key it shows an accessible notice and the table instead.

:::info
Needs the optional peers `@vis.gl/react-google-maps`, `@deck.gl/core`, `@deck.gl/layers` and `@deck.gl/google-maps`. The map code is loaded lazily, only when an API key is configured.
Needs the optional peers `@vis.gl/react-google-maps`, `@deck.gl/core`, `@deck.gl/layers` and `@deck.gl/google-maps`. The map code is loaded lazily, only when an API key is configured. If those peers are not installed, the app still builds (with webpack or Turbopack) and the chart shows a note and the data table instead of the map.
:::

```tsx
Expand Down
2 changes: 1 addition & 1 deletion docs/text-inputs/number-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ With a `name` (or inside a `FormField` with `name`), the raw number is submitted
| `startAddon` / `endAddon` | `ReactNode` | | Your own addons; the unit sits between them and the number |
| `classNames` | `{ root, input, startAddon, endAddon, unit, unitTrigger, decrement, increment }` | | Classes for each part |

Also exported: `parseLocaleNumber(text, numberLocale)`, `numberSymbols(numberLocale)`, `numberInputVariants` and the `NumberInputUnitOption`, `NumberInputFieldProps` and `NumberInputStepperProps` types.
Also exported: `parseLocaleNumber(text, numberLocale)`, `numberSymbols(numberLocale)` (group and decimal separators, and the locale's digits), `numberInputVariants` and the `NumberInputUnitOption`, `NumberInputFieldProps` and `NumberInputStepperProps` types.

## RTL and Thaana

Expand Down
107 changes: 107 additions & 0 deletions e2e/browser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { expect, test, waitForPage } from "./fixtures"

// Real-browser checks for behaviour jsdom can't show: focus after re-renders, inert
// modal backgrounds, IntersectionObserver, downloads and chart layout (#66). Each
// scenario lives in web/src/e2e/<name>.harness.tsx, served at #/e2e/<name>.
async function open(page: import("@playwright/test").Page, name: string) {
await page.goto(`/#/e2e/${name}`)
await waitForPage(page, `/#/e2e/${name}`)
}

test.describe("focus", () => {
test("SortableList keeps focus on the moved item (Move down and Alt+ArrowDown)", async ({ page }) => {
await open(page, "sortable-list")
const items = page.getByRole("list", { name: "Islands" }).getByRole("listitem")

await page.getByRole("button", { name: "Move Malé down" }).click()
await expect(items.nth(1)).toContainText("Malé")
await expect(page.getByRole("button", { name: "Move Malé down" })).toBeFocused()

await page.getByRole("button", { name: "Drag to reorder Malé" }).focus()
await page.keyboard.press("Alt+ArrowDown")
await expect(items.nth(2)).toContainText("Malé")
await expect(page.getByRole("button", { name: "Drag to reorder Malé" })).toBeFocused()
})

test("Form keeps focus in the field after an Enter submit", async ({ page }) => {
await open(page, "form-enter")
const name = page.getByLabel("Name")
await name.click()
await page.keyboard.press("Enter")
await expect(page.locator("form")).toHaveAttribute("data-status", "success")
await expect(name).toBeFocused()
})

test("the top-level comment composer keeps focus after posting", async ({ page }) => {
await open(page, "composer")
const box = page.getByRole("textbox", { name: "Write a comment…" })
await box.fill("First!")
await page.getByRole("button", { name: "Comment", exact: true }).click()
await expect(page.getByText("First!")).toBeVisible()
await expect(box).toHaveValue("")
await expect(box).toBeFocused()
})

test("the slash menu works inside a modal dialog", async ({ page }) => {
await open(page, "slash-menu-modal")
const editor = page.getByRole("dialog").getByRole("textbox", { name: "Page content" })
await editor.click()
await page.keyboard.type("/head")
const option = page.getByRole("option", { name: /Heading 1/ })
await expect(option).toBeVisible()
// Inside the dialog, and next to the editor rather than thrown off by the dialog's transform.
await expect(page.getByRole("dialog").locator("[data-slot=slash-menu]")).toBeVisible()
const menu = (await page.locator("[data-slot=slash-menu]").boundingBox())!
const field = (await editor.boundingBox())!
expect(menu.y).toBeGreaterThan(field.y)
expect(menu.y).toBeLessThan(field.y + 120)
await option.click()
await expect(editor.locator("h1")).toHaveCount(1)
})
})

test("LoadMore auto doesn't load again while a load is starting", async ({ page }) => {
await open(page, "load-more-auto")
// Each load adds 5 items after 600 ms; a second call before `loading` is set would be a duplicate request.
await page.waitForTimeout(2500)
const items = await page.getByRole("listitem").count()
const calls = Number(await page.getByTestId("calls").textContent())
expect(calls).toBeLessThanOrEqual((items - 5) / 5 + 1)
})

test("QrCode downloads PNG and SVG files", async ({ page }) => {
await open(page, "qr-download")
for (const name of [/PNG/, /SVG/]) {
const [download] = await Promise.all([page.waitForEvent("download"), page.getByRole("button", { name }).click()])
expect(await download.failure()).toBeNull()
const chunks: Buffer[] = []
for await (const chunk of await download.createReadStream()) chunks.push(chunk as Buffer)
expect(Buffer.concat(chunks).length).toBeGreaterThan(100)
}
})

test("TimeSeriesChart drops its zoom range when the data changes", async ({ page }) => {
await open(page, "time-series-zoom")
const status = page.locator("[data-slot=chart-zoom-status]")
const traveller = page.locator(".recharts-brush-traveller").first()
const box = (await traveller.boundingBox())!
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2)
await page.mouse.down()
await page.mouse.move(box.x + 250, box.y + box.height / 2, { steps: 10 })
await page.mouse.up()
await expect(page.getByRole("button", { name: "Reset zoom" })).toBeVisible()

await page.getByRole("button", { name: "Switch data" }).click()
// The new data is 1–10 May: nothing from the old January–March range may remain.
await expect(status).not.toContainText(/Jan|Feb|Mar/)
await expect(page.getByRole("button", { name: "Reset zoom" })).toHaveCount(0)
})

test("InlineEdit: clicking Cancel doesn't save", async ({ page }) => {
await open(page, "inline-edit")
await page.getByRole("button", { name: /Edit Name/ }).click()
await page.getByRole("textbox", { name: "Name" }).fill("Changed")
await page.getByRole("button", { name: "Cancel" }).click()
await expect(page.getByTestId("saves")).toHaveText("")
await expect(page.getByRole("button", { name: /Edit Name/ })).toContainText("Aishath Shifa")
})
10 changes: 10 additions & 0 deletions e2e/optional-peers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Optional peers fixture

A Next.js app that uses `@javaabu/onu`, `@javaabu/onu/charts` (Recharts only) and
`@javaabu/onu/export` with **none** of the optional peers that Onu loads on demand
(deck.gl, `@vis.gl/react-google-maps`, `write-excel-file`, …) installed.

It is not part of the pnpm workspace on purpose: inside the workspace every peer
resolves from the monorepo, which hides a missing one. `scripts/check-optional-peers.mjs`
packs the library, installs this app from the tarball in a temporary folder and builds
it with webpack and with Turbopack.
7 changes: 7 additions & 0 deletions e2e/optional-peers/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
21 changes: 21 additions & 0 deletions e2e/optional-peers/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use client"

import { Button } from "@javaabu/onu"
import { CategoryChart, MapChart } from "@javaabu/onu/charts"
import { exportCsv, exportExcel } from "@javaabu/onu/export"

const rows = [{ name: "Malé", value: 1 }]
const columns = [{ header: "Name", accessor: "name" as const }]

// MapChart lazy-loads deck.gl and @vis.gl/react-google-maps, and exportExcel loads
// write-excel-file: none are installed here, and the app must still build.
export default function Page() {
return (
<main>
<CategoryChart title="Sales" data={rows} categoryKey="name" config={{ value: { label: "Value" } }} />
<MapChart title="Atolls" geojson={{ type: "FeatureCollection", features: [] }} data={[]} />
<Button onClick={() => exportCsv({ rows, columns })}>CSV</Button>
<Button onClick={() => exportExcel({ rows, columns })}>Excel</Button>
</main>
)
}
20 changes: 20 additions & 0 deletions e2e/optional-peers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "onu-optional-peers-fixture",
"private": true,
"type": "module",
"dependencies": {
"@javaabu/onu": "file:ONU_TARBALL",
"@tanstack/react-query": "^5.104.1",
"next": "^16.4.3",
"react": "^19.3.0",
"react-dom": "^19.3.0",
"react-hook-form": "^7.89.0",
"recharts": "^3.2.1",
"tailwindcss": "^4.3.3"
},
"devDependencies": {
"@types/node": "^26.6.4",
"@types/react": "^19.3.0",
"typescript": "~6.0.3"
}
}
19 changes: 19 additions & 0 deletions e2e/optional-peers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ES2022",
"lib": ["dom", "esnext"],
"jsx": "react-jsx",
"module": "esnext",
"moduleResolution": "bundler",
"strict": true,
"skipLibCheck": true,
"noEmit": true,
"esModuleInterop": true,
"isolatedModules": true,
"resolveJsonModule": true,
"allowJs": true,
"plugins": [{ "name": "next" }]
},
"include": ["**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
12 changes: 10 additions & 2 deletions packages/onu/src/charts/_map-chart-google.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from "@testing-library/react"
import * as React from "react"
import { afterEach, describe, expect, it, vi } from "vitest"

import GoogleChoropleth, { resolveCssColor } from "./_map-chart-google"
import GoogleChoropleth, { loadMapPeers, resolveCssColor, type MapPeers } from "./_map-chart-google"
import { choroplethRegions, type GeoJsonFeatureCollection } from "./choropleth"

const overlays: { setMap: ReturnType<typeof vi.fn>; setProps: ReturnType<typeof vi.fn> }[] = []
Expand Down Expand Up @@ -82,7 +82,14 @@ describe("resolveCssColor", () => {
})

describe("GoogleChoropleth", () => {
it("adds a deck.gl GeoJsonLayer to the map and reports hover and tap", () => {
it("loads the map peers when they are installed", async () => {
const peers = await loadMapPeers()
expect(peers?.deckLayers.GeoJsonLayer).toBeDefined()
expect(peers?.vis.APIProvider).toBeDefined()
})

it("adds a deck.gl GeoJsonLayer to the map and reports hover and tap", async () => {
const peers = (await loadMapPeers()) as MapPeers
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue(null)
const { regions } = choroplethRegions(geojson, [{ id: "K", value: 10 }])
const onSelect = vi.fn()
Expand All @@ -96,6 +103,7 @@ describe("GoogleChoropleth", () => {
center={{ lat: 3, lng: 73 }}
zoom={6}
onSelect={onSelect}
peers={peers}
/>,
)
expect(getByTestId("api")).toHaveAttribute("data-key", "key")
Expand Down
Loading
Loading