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/app-sidebar-nested.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`AppSidebar`: nested items with only `onSelect` are working buttons in the expanded sidebar (they were inert and announced as disabled), a third level of `items` is shown instead of dropped, and `badge: 0` no longer draws an empty pill.
5 changes: 5 additions & 0 deletions .changeset/file-input-text-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

A mounted `FileInput` dropzone no longer cancels text dropped elsewhere on the page, such as into a textarea or the editor.
5 changes: 5 additions & 0 deletions .changeset/filter-panel-scope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`FilterPanel`'s count badge and Clear all now cover only the filters in the panel, so tabs and `ListingPage` query filters are no longer counted or cleared by it.
5 changes: 5 additions & 0 deletions .changeset/filter-render-label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

A custom filter `render` control is now named by the filter's label: the label is a real `<label for>` the `id` it receives, and `render` also gets `labelId` for `aria-labelledby`.
5 changes: 5 additions & 0 deletions .changeset/normalize-url-host-port.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`normalizeUrl` (used by `TextInput type="url"` and the editor's link and image dialogs) reads `host:port` as a host, so `localhost:3000` and `example.mv:8080/x` get the protocol instead of being rejected.
5 changes: 5 additions & 0 deletions .changeset/pagination-server-links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`Pagination` builds page links from the URLs a Laravel paginator sends, so the query string (search, filters) and a custom `pageName` are kept instead of being replaced by `path?page=N`.
5 changes: 5 additions & 0 deletions .changeset/record-column-visible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

The record column (the `primary` one, or the first when none is marked) can no longer be hidden from the Columns menu or by saved column visibility, so the row link stays on the page.
5 changes: 5 additions & 0 deletions .changeset/row-click-portals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

Clicking inside a row's actions menu or confirm dialog no longer opens the row in `DataTable`, `ListView` and the other collection views.
5 changes: 5 additions & 0 deletions .changeset/sidebar-none-dir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`Sidebar` with `collapsible="none"` keeps its `dir` prop.
5 changes: 5 additions & 0 deletions .changeset/top-nav-onselect-button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`TopNav` items with only `onSelect` (no `href`) render as buttons instead of links to `#`.
5 changes: 5 additions & 0 deletions .changeset/upload-ignore-aborted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

A cancelled, removed or replaced upload no longer lands in the `FileInput` value when a custom `upload` ignores its abort signal, and Cancel marks the upload cancelled straight away.
4 changes: 2 additions & 2 deletions docs/layout-and-navigation/app-sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ Inside a panel `AppLayout` (the default) the sidebar uses `surface="shell"`: Pro
Items use the shared `NavItem` shape: `{ label, href?, icon?, badge?, badgeTone?, color?, isActive?, disabled?, external?, items?, onSelect? }`.

- `icon`: a semantic icon name (`"home"`) or any node.
- `badge`: a number (shown as a count, "99+" above 99, with "3 new" for screen readers) or any node. On an item with nested items the badge sits inside the button, before the chevron or the submenu toggle, so the two never overlap (LTR and RTL).
- `items`: nested items. A parent with an `href` gets a separate expand button; without one, the whole row toggles.
- `badge`: a number (shown as a count, "99+" above 99, with "3 new" for screen readers; `0` shows nothing) or any node. On an item with nested items the badge sits inside the button, before the chevron or the submenu toggle, so the two never overlap (LTR and RTL).
- `items`: nested items. A parent with an `href` gets a separate expand button; without one, the whole row toggles. A nested item with only `onSelect` is a button. A third level shows as an indented list under its item (a submenu in the collapsed flyout); an item that only heads that level, with no `href` or `onSelect`, is plain text.
- **Active state**: the item matching `currentHref` gets `aria-current="page"`; its parent starts expanded, and expands when `currentHref` moves into it later. `match="prefix"` (default) keeps `/users` active on `/users/12/edit`; set `isActive` to override. Items whose `href` has a query string (`/users?status=active`) also match on its parameters.
- **Collapsed to icons**: labels become tooltips and nested items open in a flyout menu.
- On phones the drawer takes focus itself when it opens (so a filter or search field at the top doesn't bring up the keyboard; <kbd>Tab</kbd> moves into it) and closes after an item is chosen.
Expand Down
2 changes: 1 addition & 1 deletion docs/layout-and-navigation/top-nav.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { TopNav } from "@javaabu/onu"
/>
```

Items use the shared `NavItem` shape: `{ label, href?, icon?, badge?, description?, isActive?, disabled?, external?, items?, onSelect? }`, plus `columns?` and `featured?` (a `TopNavItem`). Links render through `OnuProvider linkComponent` (R16.2).
Items use the shared `NavItem` shape: `{ label, href?, icon?, badge?, description?, isActive?, disabled?, external?, items?, onSelect? }`, plus `columns?` and `featured?` (a `TopNavItem`). Links render through `OnuProvider linkComponent` (R16.2); an item with `onSelect` and no `href` renders as a button.

## Active state

Expand Down
2 changes: 1 addition & 1 deletion docs/listing-pages/column-visibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ColumnVisibility } from "@javaabu/onu"
;<ColumnVisibility columns={columns} value={state.columnVisibility} onValueChange={state.setColumnVisibility} />
```

[`DataTable`](data-table) hides columns set to `false` in `state.columnVisibility` (TanStack's column visibility).
[`DataTable`](data-table) hides columns set to `false` in `state.columnVisibility` (TanStack's column visibility). The record column (the `primary` one, else the first) carries the row link, so the menu never offers it and the table keeps it visible; columns with `hideable: false` aren't offered either.

## Props

Expand Down
2 changes: 1 addition & 1 deletion docs/listing-pages/data-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The table always shows the rows it is given (it never sorts or pages by itself):
- **Sorting**: clicking a sortable header sorts ascending and shows an arrow; clicking again reverses; another header starts ascending. Headers expose `aria-sort` and the change is announced ("Sorted by Name, ascending").
- **Selection**: row checkboxes; the header checkbox selects or clears every row on this page and shows a dash when only some are selected. As soon as a row is selected the bulk bar appears.
- **Row actions**: `rowActions(row)` lists the ⋯ menu; only `permitted` actions show; destructive ones confirm ("Delete Jane Doe?").
- **Opening a record**: `getRowHref` makes the primary column a link (through `OnuProvider linkComponent`) and clicking the row follows it; or use `onRowClick`.
- **Opening a record**: `getRowHref` makes the primary column (or the first, when none is marked) a link (through `OnuProvider linkComponent`) and clicking the row follows it; or use `onRowClick`.
- **Empty states**: "No users yet" with `emptyAction`, or "No users match your search" naming the search and filters with Clear search / Clear filters.
- **Trash**: `trash` removes checkboxes and the bulk bar; use `trashActions(t, { onRestore, onForceDelete })` for the ⋯ menu.
- **Look**: Ant Design's table: a grey (`--muted`, #fafafa) header with semibold labels and short split lines between header cells, 12px 16px cells (`density="compact"` gives 8px, `comfortable` 16px), hairline row dividers, a #fafafa hover and selected rows in the brand's lightest step (`--primary-1`). The table has no outer frame; put it in a [Card](../layout-and-navigation/card) for one. Sort arrows are grey, and brand-coloured on the sorted column.
Expand Down
8 changes: 4 additions & 4 deletions docs/listing-pages/filter-panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ For a classic filter bar that you render yourself (a `GET` form above a server-r

- Changes in the panel are a draft: the list doesn't change until **Apply**.
- **Cancel**, <kbd>Escape</kbd> or clicking outside close the panel and throw the draft away.
- **Clear all** removes every filter straight away and closes the panel.
- **Clear all** removes every filter in the panel straight away and closes the panel. The button's count and Clear all cover only the panel's `filters`: tabs and `queryFilters` in the same `value` are left alone.
- Each filter has its own **Clear** link.
- Reopening the panel always shows the filters currently applied.

Expand All @@ -92,17 +92,17 @@ For a classic filter bar that you render yourself (a `GET` form above a server-r
| `boolean` | Any / Yes / No select | `"1"` \| `"0"` |
| `text` | A text box (`thaana` supported) | `string` |
| `trashed` | Hide / Include / Only | `"with"` \| `"only"` |
| `custom` | Your `render({ value, onValueChange, id, definition })` | anything |
| `custom` | Your `render({ value, onValueChange, id, labelId, definition })` | anything |

Every definition also accepts `render` (replace the built-in control) and `format(value)` (the pill text).
Every definition also accepts `render` (replace the built-in control) and `format(value)` (the pill text). The filter's label is a `<label for>` the `id` passed to `render`, so a form control with that id is named; for a group or a custom widget, use `aria-labelledby={labelId}`.

## Props

| Prop | Type | Default | Description |
| ----------------------- | ---------------------------------------------------------- | --------------- | -------------------------------------- |
| `filters` | `FilterDefinition[]` | | Filters on offer |
| `value` | `FilterValues` | | Applied filters |
| `onApply` | `(filters) => void` | | Apply (and `{}` on Clear all) |
| `onApply` | `(filters) => void` | | Apply, and Clear all (the panel's filters removed) |
| `open` / `onOpenChange` | `boolean` / `(open) => void` | | Controlled open state |
| `defaultOpen` | `boolean` | `false` | Initial open state when uncontrolled |
| `sheet` | `boolean` | below 768px | Force the bottom sheet or the dropdown |
Expand Down
1 change: 1 addition & 0 deletions docs/listing-pages/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Pagination } from "@javaabu/onu"
- Previous is disabled on the first page and Next on the last (or when a simple paginator has no `next_page_url`).
- With numbered pages the previous and next buttons are icon-only (their accessible names stay "Go to previous page" / "Go to next page"). Without a total (simple paginators) or with `numbered={false}` they show their labels.
- With `getPageHref`, or a paginator with a `path` / `links`, pages are links rendered with `OnuProvider linkComponent` (Inertia, Next). Plain clicks still call `onPageChange` when given.
- Page links from a paginator come from the URLs the server sent (`links`, `first_page_url`, `prev_page_url`, …), so the query string from `->withQueryString()` and a custom `pageName` are kept. Pages the server didn't list swap the page number in one of those URLs; `path` is used only when the server sent no URLs.

## Props

Expand Down
2 changes: 1 addition & 1 deletion docs/text-inputs/text-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Addons sit at the inline start and end, so they swap sides in RTL.

For a sign-in form, pass `autoComplete="username"` to the email field so password managers pair it with the password field.

A URL without a scheme gets `urlProtocol` (default `https://`) when the user leaves the field: `javaabu.com` becomes `https://javaabu.com`. The value is set the way a user would type it (a native input event), so `onChange`, controlled state and `react-hook-form` all see it. `urlProtocol={false}` keeps the value as typed, e.g. for site-relative paths. The same rule is exported as `normalizeUrl(value, protocol?)`.
A URL without a scheme gets `urlProtocol` (default `https://`) when the user leaves the field: `javaabu.com` becomes `https://javaabu.com`, and `localhost:3000` becomes `https://localhost:3000` (a host and port is not read as a scheme). The value is set the way a user would type it (a native input event), so `onChange`, controlled state and `react-hook-form` all see it. `urlProtocol={false}` keeps the value as typed, e.g. for site-relative paths. The same rule is exported as `normalizeUrl(value, protocol?)`.

## Props

Expand Down
31 changes: 31 additions & 0 deletions packages/onu/src/components/files/file-input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ describe("FileInput appearance=dropzone", () => {
expect(screen.getByLabelText("Browse file")).toBe(input(container))
// A file dropped next to the zone does not replace the page.
expect(fireEvent.drop(document.body, { dataTransfer: filesData([dropped]) })).toBe(false)
// Text dropped elsewhere on the page (a textarea, the editor) is left alone.
expect(fireEvent.drop(document.body, { dataTransfer: { types: ["text/plain"], files: [] } })).toBe(true)
})

it("accepts pasted files on the field and, optionally, the document", async () => {
Expand Down Expand Up @@ -692,6 +694,35 @@ describe("FileInput uploads", () => {
expect(screen.getByText("a.pdf removed")).toBeInTheDocument()
})

it("keeps cancelled and replaced uploads out of the value when the uploader ignores the signal", async () => {
const calls: { resolve: (v: unknown) => void }[] = []
const upload = vi.fn(() => new Promise((resolve) => calls.push({ resolve })))
const onUploaded = vi.fn()
const { container, unmount } = renderWithOnu(
<FileInput multiple aria-label="Docs" name="docs" upload={upload} onUploaded={onUploaded} />,
)
await user().upload(input(container), [file("a.pdf"), file("b.pdf")])
await userEvent.click(screen.getByRole("button", { name: "Cancel upload of a.pdf" }))
expect(await screen.findByText("Upload of a.pdf cancelled")).toBeInTheDocument()
await userEvent.click(screen.getByRole("button", { name: "Cancel upload of b.pdf" }))
await userEvent.click(await screen.findByRole("button", { name: "Remove b.pdf" }))
await act(async () => calls[0]!.resolve({ id: 1 }))
await act(async () => calls[1]!.resolve({ id: 2 }))
expect(hiddenValues(container, "docs")).toEqual([])
expect(onUploaded).not.toHaveBeenCalled()
expect(screen.getByText("Cancelled")).toBeInTheDocument()
unmount()

// Single mode: the file picked last wins, whichever request finishes last.
calls.length = 0
const single = renderWithOnu(<FileInput aria-label="Slip" name="slip" upload={upload} />)
await user().upload(input(single.container), file("old.pdf"))
await user().upload(input(single.container), file("new.pdf"))
await act(async () => calls[1]!.resolve({ id: 20 }))
await act(async () => calls[0]!.resolve({ id: 10 }))
expect(hiddenValues(single.container, "slip")).toEqual(["20"])
})

it("shows Laravel errors and calls onError", async () => {
const { upload, calls } = controllableUploader()
const onError = vi.fn()
Expand Down
1 change: 1 addition & 0 deletions packages/onu/src/components/files/file-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ export function FileInput<R = unknown>({
if (hasFiles(e.dataTransfer)) e.preventDefault()
}
const drop = (e: DragEvent) => {
if (!hasFiles(e.dataTransfer)) return
const target = e.target as HTMLInputElement | null
if (!(target?.tagName === "INPUT" && target.type === "file")) e.preventDefault()
}
Expand Down
21 changes: 19 additions & 2 deletions packages/onu/src/components/files/use-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,19 @@ export function useUploadQueue<R = unknown>(options: UseUploadQueueOptions<R>) {
onProgress: (progress) => update(id, { progress: Math.max(0, Math.min(100, progress)) }),
}).then(
(response) => {
// A custom uploader may ignore the signal: a cancelled, removed or replaced upload still resolves.
if (controller.signal.aborted) return
controllers.current.delete(id)
const patch = { status: "success", progress: 100, response } as const
update(id, patch)
setAnnouncement(t("file.uploadedFile", { name: file.name }))
callbacks.current.onUploaded?.({ id, file, ...patch })
},
(error: unknown) => {
// Cancelling already marked it; a removed or replaced upload has left the list.
if (controller.signal.aborted) return
controllers.current.delete(id)
if (isAbortError(error) || controller.signal.aborted) {
if (isAbortError(error)) {
update(id, { status: "cancelled" })
setAnnouncement(t("file.cancelledFile", { name: file.name }))
return
Expand Down Expand Up @@ -229,7 +233,18 @@ export function useUploadQueue<R = unknown>(options: UseUploadQueueOptions<R>) {
[start],
)

const cancel = React.useCallback((id: string) => controllers.current.get(id)?.abort(), [])
const cancel = React.useCallback(
(id: string) => {
const controller = controllers.current.get(id)
if (!controller) return
controllers.current.delete(id)
controller.abort()
update(id, { status: "cancelled" })
const item = items.find((i) => i.id === id)
if (item) setAnnouncement(t("file.cancelledFile", { name: item.file.name }))
},
[items, update, t],
)

const retry = React.useCallback(
(id: string) => {
Expand All @@ -241,11 +256,13 @@ export function useUploadQueue<R = unknown>(options: UseUploadQueueOptions<R>) {

const remove = React.useCallback((id: string) => {
controllers.current.get(id)?.abort()
controllers.current.delete(id)
setItems((list) => list.filter((item) => item.id !== id))
}, [])

const clear = React.useCallback(() => {
for (const controller of controllers.current.values()) controller.abort()
controllers.current.clear()
setItems([])
}, [])

Expand Down
Loading
Loading