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

`Autocomplete`: the suggestion list now filters by a controlled `value` set from outside, so resetting the field from the parent shows the full list again.
5 changes: 5 additions & 0 deletions .changeset/date-calendar-page-limits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`DateCalendar`: in the months, years and year-range views, Page Up/Down and arrow keys past the edge no longer page beyond `min` or `max` while the Previous / Next buttons are disabled.
5 changes: 5 additions & 0 deletions .changeset/hijri-picker-focus-time.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`HijriDatePicker`: a value or `today` that carries a time on the last day of a Hijri month now opens with that day focused instead of the 1st.
5 changes: 5 additions & 0 deletions .changeset/inline-edit-blur-focus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`InlineEdit`: saving or cancelling on blur no longer pulls focus back to the value, so clicking another field after editing lands there. A failing `validate` on blur keeps the error showing without trapping focus in the editor.
5 changes: 5 additions & 0 deletions .changeset/number-input-stepper-typing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`NumberInput`: a stepper field can now be cleared and retyped (it falls back to `min` only on blur), and the arrow keys step exactly like the − / + buttons instead of rounding to the step's decimals.
5 changes: 5 additions & 0 deletions .changeset/reporting-period-abandoned-custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`ReportingPeriodPicker`: a half-picked custom range is dropped when you then pick a month, quarter or year, instead of replacing your choice when the popover closes.
5 changes: 5 additions & 0 deletions .changeset/search-box-clear-once.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`SearchBox`: clicking ✕ with unsubmitted text now runs one search for `""`, instead of first searching the draft on blur.
5 changes: 5 additions & 0 deletions .changeset/slug-input-typed-spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`SlugInput`: typing a space by hand now inserts the separator (`my custom slug` gives `my-custom-slug`), including with a custom `separator` such as `_`. `toSlug(text, { preserveTrailing: true })` keeps a trailing word break for any separator.
5 changes: 5 additions & 0 deletions .changeset/tags-input-disabled-suggestions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`TagsInput`: Enter no longer adds a disabled suggestion, and the arrow keys skip disabled suggestions.
5 changes: 5 additions & 0 deletions .changeset/wizard-finish-once.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`Wizard`: Finish stays busy until `onComplete` settles, so a second click can no longer run `onComplete` twice.
2 changes: 1 addition & 1 deletion docs/date-and-time/date-calendar.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Without `today`, "today" is the browser's date. When server-rendered, no day is

## Accessibility

See the [DatePicker keyboard table](./date-picker#accessibility). The caption is a button ("March 2026: choose a month"); page changes are announced through a polite live region; the current month/year/range has `aria-current="date"`.
See the [DatePicker keyboard table](./date-picker#accessibility); in every view, Page Up/Down and arrows past the edge stop at `min` and `max` like the Previous and Next buttons. The caption is a button ("March 2026: choose a month"); page changes are announced through a polite live region; the current month/year/range has `aria-current="date"`.

- With `events`, each day's accessible name includes its event count, so the dots (hidden from screen readers) aren't the only signal.
- With `readOnly`, the clicked day's event list is a polite live region, so it is read out when it changes. <kbd>Enter</kbd> or <kbd>Space</kbd> on a day lists its events.
Expand Down
2 changes: 1 addition & 1 deletion docs/form-scaffolding/inline-edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ If the thrown error has a `message`, it is shown; otherwise "Couldn’t save. Pl

- The value is a button named "Edit Name: Aishath Shifa".
- In edit mode the input is labelled by `label` and described by the key hint; errors are announced (`role="alert"`) and linked with `aria-describedby`.
- After saving or cancelling, focus returns to the value; "Name saved" is announced.
- After saving or cancelling with the keyboard or the buttons, focus returns to the value; "Name saved" is announced. When focus leaves the editor (`blurBehavior`), it stays where the user moved it, and a failing `validate` keeps the editor open with its error without pulling focus back.
- While saving, the input is read-only and `aria-busy`.

| Key | Action |
Expand Down
2 changes: 1 addition & 1 deletion docs/layout-and-navigation/wizard.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Wizard } from "@javaabu/onu"
/>
```

`validate` can be async (e.g. react-hook-form's `trigger`). While it runs, Next shows a spinner and ignores further clicks. If it returns `false`, the step is marked "Has errors" and the wizard stays.
`validate` can be async (e.g. react-hook-form's `trigger`). While it runs, and on the last step until `onComplete` settles, Next (or Finish) shows a spinner and ignores further clicks, so `onComplete` runs once. If it returns `false`, the step is marked "Has errors" and the wizard stays.

## Navigation

Expand Down
4 changes: 2 additions & 2 deletions docs/text-inputs/number-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The selected unit is controlled with `unitValue` / `onUnitChange` (uncontrolled:

## Stepper

`stepper` adds large − and + buttons at the sides, for cart quantities, tickets and guest counts. Holding a button repeats the step (`repeatDelay`, then every `repeatInterval` ms); arrow keys work in the field as usual.
`stepper` adds large − and + buttons at the sides, for cart quantities, tickets and guest counts. Holding a button repeats the step (`repeatDelay`, then every `repeatInterval` ms); arrow keys in the field step exactly like the buttons.

```tsx
const [tickets, setTickets] = useState(1)
Expand All @@ -53,7 +53,7 @@ const [tickets, setTickets] = useState(1)
</FormField>
```

A stepper always holds a number: `min` defaults to `0`, `defaultValue` to `min`, and clearing the field falls back to `min`, so `value` and `onValueChange` use `number` rather than `number | null`. `size="sm" | "default" | "lg"` sets its height and width (variants exported as `numberInputVariants`); on touch screens the buttons are at least 44px in every size, and `lg` suits kiosks. A `unit` can sit next to the number between the buttons.
A stepper always holds a number: `min` defaults to `0`, `defaultValue` to `min`, and a field left empty falls back to `min` on blur (you can clear it and type a new number), so `value` and `onValueChange` use `number` rather than `number | null`. `size="sm" | "default" | "lg"` sets its height and width (variants exported as `numberInputVariants`); on touch screens the buttons are at least 44px in every size, and `lg` suits kiosks. A `unit` can sit next to the number between the buttons.

## Form submission

Expand Down
2 changes: 2 additions & 0 deletions docs/text-inputs/slug-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const [title, setTitle] = useState("")
</FormField>
```

When the user types the slug by hand it is normalised as they type: a space (or any other word break) becomes the `separator`, and a trailing one is dropped on blur.

On an edit page, pass the saved slug as `defaultValue` (or `value`). It then starts unlocked, so editing the title does not change a published URL until the user locks it again.

## Thaana titles
Expand Down
2 changes: 1 addition & 1 deletion docs/text-inputs/tags-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ With `thaana`, the field types Thaana (`dir="rtl"`, `lang="dv"`), and the Thaana
| ---------------------------------- | ------------------------------------------------------------ |
| <kbd>Enter</kbd> / <kbd>,</kbd> | Add the typed tag (Enter on an empty field submits the form) |
| <kbd>Backspace</kbd> (empty field) | Remove the last tag |
| <kbd>↓</kbd> / <kbd>↑</kbd> | Move through suggestions |
| <kbd>↓</kbd> / <kbd>↑</kbd> | Move through suggestions, skipping disabled ones |
| <kbd>Esc</kbd> | Close suggestions |
12 changes: 10 additions & 2 deletions packages/onu/src/components/date/_period-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface GridKeyboardOptions {
onPage?: (delta: number) => void
/** Moving past the first or last cell: page in that direction and land on `index` of the new page. */
onOverflow?: (delta: number, index: number) => void
/** Whether paging in a direction (-1 back, +1 forward) is allowed. When not, PageUp/PageDown do nothing and arrows stop at the edge. */
canPage?: (delta: number) => boolean
/** Wrap around at the ends (clock faces). */
wrapAround?: boolean
/** Every arrow moves by one (a clock face has no rows). */
Expand Down Expand Up @@ -53,15 +55,15 @@ export function handleGridKey(e: React.KeyboardEvent, o: GridKeyboardOptions): b
case "PageDown":
if (!o.onPage) return false
e.preventDefault()
o.onPage(e.key === "PageUp" ? -1 : 1)
if (o.canPage?.(e.key === "PageUp" ? -1 : 1) ?? true) o.onPage(e.key === "PageUp" ? -1 : 1)
return true
default:
return false
}
e.preventDefault()
if (target < 0 || target >= o.count) {
if (o.wrapAround) target = wrap(target, o.count)
else if (o.onOverflow) {
else if (o.onOverflow && (o.canPage?.(target < 0 ? -1 : 1) ?? true)) {
o.onOverflow(target < 0 ? -1 : 1, wrap(target, o.count))
return true
} else target = Math.max(0, Math.min(o.count - 1, target))
Expand Down Expand Up @@ -91,6 +93,9 @@ export interface PeriodGridProps {
label: string
onSelect: (index: number) => void
onPage?: (delta: number) => void
/** Whether there is a previous / next page; when not, the keyboard stops at this one. Default `true`. */
canPrev?: boolean
canNext?: boolean
/** Cell that is focusable first. Defaults to the selected cell, then the current one, then the first. */
activeIndex?: number
/** Focus the active cell when mounted. */
Expand All @@ -117,6 +122,8 @@ export function PeriodGrid({
label,
onSelect,
onPage,
canPrev = true,
canNext = true,
activeIndex,
initialFocus,
layout = "grid",
Expand Down Expand Up @@ -162,6 +169,7 @@ export function PeriodGrid({
onPage(delta)
}
: undefined,
canPage: (delta) => (delta < 0 ? canPrev : canNext),
wrapAround: clock,
linear: clock,
})
Expand Down
21 changes: 21 additions & 0 deletions packages/onu/src/components/date/date-calendar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,27 @@ describe("DateCalendar — zooming out (§25.1)", () => {
expect(caption()).toHaveTextContent("2004–2015")
})

it("does not page past min or max from the keyboard in the zoomed views", async () => {
const user = userEvent.setup()
renderWithOnu(
<DateCalendar minView="month" today={TODAY} min={new Date(2026, 0, 1)} max={new Date(2026, 11, 31)} />,
)
expect(screen.getByRole("button", { name: "Previous year" })).toBeDisabled()
const months = screen.getByRole("grid", { name: "Months" })
act(() => within(months).getByRole("button", { name: "January 2026" }).focus())
await user.keyboard("{PageUp}")
expect(caption()).toHaveTextContent("2026")
await user.keyboard("{ArrowUp}")
expect(caption()).toHaveTextContent("2026")
expect(document.activeElement).toHaveAccessibleName("January 2026")
act(() => within(months).getByRole("button", { name: "December 2026" }).focus())
await user.keyboard("{PageDown}")
expect(caption()).toHaveTextContent("2026")
await user.keyboard("{ArrowRight}")
expect(caption()).toHaveTextContent("2026")
expect(document.activeElement).toHaveAccessibleName("December 2026")
})

it("turns into a month picker with minView", async () => {
const user = userEvent.setup()
const onPeriodSelect = vi.fn()
Expand Down
2 changes: 2 additions & 0 deletions packages/onu/src/components/date/date-calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ export function DateCalendar(props: DateCalendarProps) {
label={t(view === "month" ? "date.months" : view === "year" ? "date.years" : "date.decades")}
initialFocus={focusGrid}
onPage={(delta) => (delta < 0 ? nav.prev() : nav.next())}
canPrev={nav.canPrev}
canNext={nav.canNext}
onSelect={(index) => {
const target = items[index]!.date
if (atBottom) {
Expand Down
5 changes: 3 additions & 2 deletions packages/onu/src/components/date/hijri-date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export function HijriCalendar({
const lead = (first.getDay() - weekStartsOn + 7) % 7
const weeks = Math.ceil((lead + daysInMonth) / 7)
const cells = Array.from({ length: weeks * 7 }, (_, i) => addDays(first, i - lead))
const lastDay = addDays(first, daysInMonth - 1)
const inMonth = (d: Date) => d >= first && d <= lastDay
// Up to the next month's midnight, so a date with a time on the last day still counts.
const nextMonth = addDays(first, daysInMonth)
const inMonth = (d: Date) => d >= first && d < nextMonth
const focusTarget = [focused, selected, today].find((d): d is Date => !!d && inMonth(d)) ?? first

React.useEffect(() => {
Expand Down
13 changes: 13 additions & 0 deletions packages/onu/src/components/date/hijri-date.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ describe("HijriDatePicker", () => {
}
})

it("opens focused on today or the value when it carries a time", async () => {
const days = hijriDaysInMonth(1447, 9)
const lastDay = fromHijri({ year: 1447, month: 9, day: days })
const afternoon = new Date(lastDay.getFullYear(), lastDay.getMonth(), lastDay.getDate(), 15, 30)
const { user, unmount } = setup(<HijriDatePicker aria-label="Date" today={afternoon} />)
await user.click(screen.getByRole("combobox"))
expect(focused()).toHaveAccessibleName(new RegExp(`^(Today, )?${days} Ramadan 1447`))
unmount()
setup(<HijriDatePicker aria-label="Date" today={TODAY} defaultValue={afternoon} />)
await userEvent.click(screen.getByRole("combobox"))
expect(focused()).toHaveAccessibleName(new RegExp(`^(Today, )?${days} Ramadan 1447`))
})

it("does not pick days outside min/max", async () => {
const onChange = vi.fn()
const { user } = setup(
Expand Down
12 changes: 12 additions & 0 deletions packages/onu/src/components/date/reporting-period-picker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ describe("ReportingPeriodPicker", () => {
expect(screen.getByRole("combobox")).toHaveTextContent("03/03/2026 – 17/03/2026")
})

it("drops an abandoned custom click when another period is picked", async () => {
const onChange = vi.fn()
const { user } = setup(<ReportingPeriodPicker aria-label="Period" today={TODAY} onValueChange={onChange} />)
await user.click(screen.getByRole("combobox"))
await user.click(radio("Custom range"))
await user.click(button(/March 12th, 2026/))
await user.click(radio("Monthly"))
await user.click(button("May 2026"))
expect(onChange).toHaveBeenLastCalledWith({ type: "monthly", from: new Date(2026, 4, 1), to: end(2026, 4, 31) })
expect(screen.getByRole("combobox")).toHaveTextContent("May 2026")
})

it("keeps half a custom range as a one-day range on Done", async () => {
const onChange = vi.fn()
const { user } = setup(
Expand Down
3 changes: 2 additions & 1 deletion packages/onu/src/components/date/reporting-period-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export function ReportingPeriodPicker({
const display = value ? describe(value) : null

const commit = (next: ReportingPeriod, close: () => void) => {
// A custom range left half-picked is abandoned; closing must not turn it into the value.
setPending(null)
setValue({ ...next, from: startOfDay(next.from), to: endOfDay(next.to) })
close()
}
Expand Down Expand Up @@ -242,7 +244,6 @@ export function ReportingPeriodPicker({
onSelect={(range) => {
setPending(range)
if (range.from && range.to && range.from.getTime() !== range.to.getTime()) {
setPending(null)
commit({ type: "custom", from: range.from, to: range.to }, close)
}
}}
Expand Down
46 changes: 46 additions & 0 deletions packages/onu/src/components/form/inline-edit.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,52 @@ describe("InlineEdit", () => {
expect(onSave).toHaveBeenCalledTimes(1)
})

it("leaves focus where the user moved it when blur saves or cancels", async () => {
const onSave = vi.fn()
const { rerender } = renderWithOnu(
<>
<InlineEdit label="A" defaultValue="1" onSave={onSave} />
<input aria-label="other" />
</>,
)
await userEvent.click(screen.getByRole("button", { name: /Edit A/ }))
await userEvent.type(screen.getByRole("textbox", { name: "A" }), "2")
await userEvent.click(screen.getByRole("textbox", { name: "other" }))
expect(onSave).toHaveBeenCalledWith("12")
expect(screen.getByRole("textbox", { name: "other" })).toHaveFocus()
// Unchanged: closes on blur without saving, focus still stays put.
await userEvent.click(screen.getByRole("button", { name: /Edit A/ }))
await userEvent.click(screen.getByRole("textbox", { name: "other" }))
expect(screen.getByRole("textbox", { name: "other" })).toHaveFocus()
rerender(
<>
<InlineEdit label="A" defaultValue="1" onSave={onSave} blurBehavior="cancel" />
<input aria-label="other" />
</>,
)
await userEvent.click(screen.getByRole("button", { name: /Edit A/ }))
await userEvent.click(screen.getByRole("textbox", { name: "other" }))
expect(screen.getByRole("textbox", { name: "other" })).toHaveFocus()
})

it("lets the user leave a field that fails validation", async () => {
renderWithOnu(
<>
<InlineEdit label="Name" defaultValue="Ali" validate={(v) => (v ? null : "Required")} />
<input aria-label="other" />
</>,
)
await userEvent.click(screen.getByRole("button", { name: /Edit Name/ }))
await userEvent.clear(screen.getByRole("textbox", { name: "Name" }))
await userEvent.click(screen.getByRole("textbox", { name: "other" }))
expect(screen.getByRole("alert")).toHaveTextContent("Required")
expect(screen.getByRole("textbox", { name: "other" })).toHaveFocus()
// The editor stays open with the error, and Enter still refocuses it.
await userEvent.click(screen.getByRole("textbox", { name: "Name" }))
await userEvent.keyboard("{Enter}")
expect(screen.getByRole("textbox", { name: "Name" })).toHaveFocus()
})

it("is controlled, multiline (Ctrl+Enter saves) and reports changes", async () => {
function Controlled() {
const [value, setValue] = React.useState("Line 1")
Expand Down
Loading
Loading