Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat(react): phone parts for record pages — split-button and icon cells in the bar, no autofocus on phones, read-only rich text, a shared tab bar
aashuf914cdf3f86a
diff --git a/packages/documents/src/utils/index.ts b/packages/documents/src/utils/index.tsindex 5a8527a790..7a2122b4b0 100644--- a/packages/documents/src/utils/index.ts+++ b/packages/documents/src/utils/index.ts@@ -8,3 +8,4 @@export { getPurchaseOrderDisplayId } from "./purchase-order";export { getQuoteDisplayId } from "./quote";export { withRevisionSuffix } from "./revision";+export { getLineTotal as getSalesOrderLineTotal } from "./sales-order";diff --git a/packages/printing/src/ui/PrintButton.tsx b/packages/printing/src/ui/PrintButton.tsxindex 391709032d..1b106526b4 100644--- a/packages/printing/src/ui/PrintButton.tsx+++ b/packages/printing/src/ui/PrintButton.tsx@@ -15,7 +15,7 @@ import {useDisclosure} from "@carbon/react";import { Trans } from "@lingui/react/macro";-import type { ComponentProps } from "react";+import type { ComponentProps, ReactNode } from "react";import { useEffect, useState } from "react";import { LuCheck, LuPrinter } from "react-icons/lu";import { useFetcher } from "react-router";@@ -38,7 +38,8 @@ export function PrintButton({disabled,variant = "secondary",size,- isIcon = false+ isIcon = false,+ label}: {sourceDocument: string;sourceDocumentId: string;@@ -52,6 +53,8 @@ export function PrintButton({// Render as an icon-only button (printer glyph, no label) instead of the// default labeled button. Same print/download flow either way.isIcon?: boolean;+ /** The labeled button's text. Defaults to "Print". */+ label?: ReactNode;}) {const { printerRoutes, resolvePrinterRoute, printPath } = usePrinting();const modal = useDisclosure();@@ -122,7 +125,7 @@ export function PrintButton({disabled={disabled}onClick={handleClick}>- <Trans>Print</Trans>+ {label ?? <Trans>Print</Trans>}</Button>)}diff --git a/packages/react/src/ActionPresentation.tsx b/packages/react/src/ActionPresentation.tsxindex 33e242b187..5e986f14a2 100644--- a/packages/react/src/ActionPresentation.tsx+++ b/packages/react/src/ActionPresentation.tsx@@ -8,13 +8,24 @@ import { createContext, useContext } from "react";/*** How a record action renders on phones, set by the ERP's RecordAction:* - `bar`: a cell of the bottom action bar, filled (`primary`) or outline- * (`secondary`) whatever variant the caller passed.+ * (`secondary`) whatever variant the caller passed; `iconOnly` makes it a+ * square icon cell (Preview).* - `row`: a row of the ⋯ action sheet; choosing it calls `onSelect` (closes* the sheet).* Desktop and everything outside a RecordAction see `null`.*/export type ActionPresentation =- | { kind: "bar"; emphasis: "primary" | "secondary" }+ | {+ kind: "bar";+ emphasis: "primary" | "secondary";+ /** A square cell: the left icon only, the label for screen readers. */+ iconOnly?: boolean;+ /**+ * Renders buttons as rows of the record's ⋯ menu. A bar cell holds one+ * action, so a split button sends its dropdown items here.+ */+ overflow?: (buttons: ReactNode) => ReactNode;+ }| { kind: "row"; onSelect: () => void };const Context = createContext<ActionPresentation | null>(null);diff --git a/packages/react/src/BarProgress.tsx b/packages/react/src/BarProgress.tsxindex c6658e471a..6aa79b4bd1 100644--- a/packages/react/src/BarProgress.tsx+++ b/packages/react/src/BarProgress.tsx@@ -83,6 +83,8 @@ interface BarProgressProps {activeClassName?: string;/** Class name for the inactive (unfilled) bars */inactiveClassName?: string;+ /** Phones: label above the bar, value under it, value not truncated. */+ stackOnPhone?: boolean;}export function BarProgress({@@ -95,7 +97,8 @@ export function BarProgress({segments,className,activeClassName = "bg-emerald-500",- inactiveClassName = "bg-muted"+ inactiveClassName = "bg-muted",+ stackOnPhone = false}: BarProgressProps) {const containerRef = useRef<HTMLDivElement>(null);const [barCount, setBarCount] = useState(0);@@ -158,14 +161,27 @@ export function BarProgress({return (<div className={cn("w-full", className)}>{hasHeader && (- <div className="mb-0.5 flex items-baseline justify-between">+ <div className="mb-0.5 flex items-baseline justify-between gap-2">{label ? (- <span className="text-sm font-medium text-foreground">{label}</span>+ <span+ className={cn(+ "shrink-0 text-sm font-medium text-foreground",+ stackOnPhone && "max-md:min-w-0 max-md:truncate max-md:text-xs"+ )}+ >+ {label}+ </span>) : (<div />)}{value && (- <span className="text-xs font-mono tabular-nums text-muted-foreground">+ <span+ title={value}+ className={cn(+ "min-w-0 truncate text-xs font-mono tabular-nums text-muted-foreground",+ stackOnPhone && "max-md:hidden"+ )}+ >{value}</span>)}@@ -198,6 +214,11 @@ export function BarProgress({))}<span className="sr-only">{Math.round(percentage)}%</span></div>+ {stackOnPhone && value ? (+ <span className="mt-1 hidden break-words text-xs font-mono tabular-nums text-muted-foreground max-md:block">+ {value}+ </span>+ ) : null}</div>);}diff --git a/packages/react/src/BottomSheet.tsx b/packages/react/src/BottomSheet.tsxindex fa9c111307..8243993033 100644--- a/packages/react/src/BottomSheet.tsx+++ b/packages/react/src/BottomSheet.tsx@@ -18,7 +18,7 @@ import { ActionPresentationBoundary } from "./ActionPresentation";import { ClientOnly } from "./ClientOnly";import { DialogRoot, useDialogDismissable } from "./Modal";import { cn } from "./utils/cn";-import { useViewport } from "./Viewport";+import { usePhoneOpenAutoFocus, useViewport } from "./Viewport";/*** A sheet that slides up from the bottom. Every compact (phone) sheet shares@@ -60,6 +60,7 @@ const BottomSheetContent = forwardRef<>(({ className, children, size = "auto", ...props }, ref) => {const { t } = useLingui();const { isPhone } = useViewport();+ const onOpenAutoFocus = usePhoneOpenAutoFocus(props.onOpenAutoFocus);const dismissable = useDialogDismissable();return (<ClientOnly fallback={null}>@@ -77,6 +78,7 @@ const BottomSheetContent = forwardRef<className)}{...props}+ onOpenAutoFocus={onOpenAutoFocus}><divclassName={cn(diff --git a/packages/react/src/Button.tsx b/packages/react/src/Button.tsxindex 40eb724484..2bd178b9db 100644--- a/packages/react/src/Button.tsx+++ b/packages/react/src/Button.tsx@@ -206,6 +206,9 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(// Phones, inside a record action: a bottom-bar cell or an action-sheet// row (see ActionPresentation).const isRow = presentation?.kind === "row";+ // A square bar cell (Preview): the left icon, the label for screen readers.+ const isIconCell =+ presentation?.kind === "bar" && presentation.iconOnly === true;const onClick = isRow? (event: MouseEvent<HTMLButtonElement>) => {props.onClick?.(event);@@ -230,12 +233,13 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(: variant,size: presentation ? "lg" : size,isDisabled,- isIcon,+ isIcon: isIcon || isIconCell,isLoading,isRound,className}),- presentation?.kind === "bar" && "w-full min-w-0",+ presentation?.kind === "bar" &&+ (isIconCell ? "shrink-0" : "w-full min-w-0"),isRow &&"h-12 w-full min-w-0 shrink justify-start rounded-sm px-3 text-[15px] font-normal text-foreground shadow-none",isRow && variant === "destructive" && "text-destructive"@@ -259,13 +263,21 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>({!isLoading &&leftIcon &&cloneElement(leftIcon, {- className: !leftIcon.props?.size- ? cn("mr-2 h-4 w-4 flex-shrink-0", leftIcon.props.className)- : cn("mr-2 flex-shrink-0", leftIcon.props.className)+ className: isIconCell+ ? cn("size-5 flex-shrink-0", leftIcon.props.className)+ : !leftIcon.props?.size+ ? cn("mr-2 h-4 w-4 flex-shrink-0", leftIcon.props.className)+ : cn("mr-2 flex-shrink-0", leftIcon.props.className)})}{/* An icon button's icon arrives as children — while loading, thespinner must REPLACE it or both clip inside the square hit area. */}- {isIcon && isLoading ? null : <Slottable>{children}</Slottable>}+ {isIcon && isLoading ? null : isIconCell ? (+ <span className="sr-only">+ <Slottable>{children}</Slottable>+ </span>+ ) : (+ <Slottable>{children}</Slottable>+ )}{badgeShortcut && (<ShortcutKeyshortcut={badgeShortcut}@@ -275,6 +287,7 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>({/* The badge owns the trailing slot — a rightIcon next to it readscluttered, so the badge wins while it's visible. */}{!badgeShortcut &&+ !isIconCell &&rightIcon &&cloneElement(rightIcon, {className: !rightIcon.props?.sizediff --git a/packages/react/src/Combobox.tsx b/packages/react/src/Combobox.tsxindex 86d15c9af3..c5cd1e0726 100644--- a/packages/react/src/Combobox.tsx+++ b/packages/react/src/Combobox.tsx@@ -11,12 +11,13 @@ import { CommandTrigger } from "./Command";import { HStack } from "./HStack";import { IconButton } from "./IconButton";import type { PickerListOption } from "./PickerList";-import { PickerList, usePickerOpenAutoFocus } from "./PickerList";+import { PickerList } from "./PickerList";import { Popover, PopoverContent, PopoverTrigger } from "./Popover";import { Spinner } from "./Spinner";import { TruncatedTooltipText } from "./TruncatedTooltipText";import { cn } from "./utils/cn";import { reactNodeToString } from "./utils/react";+import { usePhoneOpenAutoFocus } from "./Viewport";export type ComboboxOption = {label: string | JSX.Element;@@ -82,7 +83,7 @@ const Combobox = forwardRef<HTMLButtonElement, ComboboxProps>(// it — honor it instead of silently overwriting it below.const isReadOnly = isReadOnlyProp || disabled;const [open, setOpen] = useState(false);- const openAutoFocus = usePickerOpenAutoFocus(options.length);+ const openAutoFocus = usePhoneOpenAutoFocus();const isInlinePreview = !!inline;const selectedOption = useMemo(() => options.find((option) => option.value === value),diff --git a/packages/react/src/CreateableCombobox.tsx b/packages/react/src/CreateableCombobox.tsxindex ebd1ca23ce..fca8c0181b 100644--- a/packages/react/src/CreateableCombobox.tsx+++ b/packages/react/src/CreateableCombobox.tsx@@ -10,11 +10,12 @@ import { CommandTrigger } from "./Command";import { HStack } from "./HStack";import { IconButton } from "./IconButton";import type { PickerListOption } from "./PickerList";-import { PickerList, usePickerOpenAutoFocus } from "./PickerList";+import { PickerList } from "./PickerList";import { Popover, PopoverContent, PopoverTrigger } from "./Popover";import { TruncatedTooltipText } from "./TruncatedTooltipText";import { cn } from "./utils/cn";import { reactNodeToString } from "./utils/react";+import { usePhoneOpenAutoFocus } from "./Viewport";export type CreatableComboboxProps = Omit<ComponentPropsWithoutRef<"button">,@@ -72,7 +73,7 @@ const CreatableCombobox = forwardRef<HTMLButtonElement, CreatableComboboxProps>(const isReadOnly = isReadOnlyProp || disabled;const [open, setOpen] = useState(false);const [search, setSearch] = useState("");- const openAutoFocus = usePickerOpenAutoFocus(options.length);+ const openAutoFocus = usePhoneOpenAutoFocus();// Reset the search box whenever the dropdown closes.useEffect(() => {diff --git a/packages/react/src/CreateableMultiSelect.tsx b/packages/react/src/CreateableMultiSelect.tsxindex 5bc289fdae..e3ac8cceda 100644--- a/packages/react/src/CreateableMultiSelect.tsx+++ b/packages/react/src/CreateableMultiSelect.tsx@@ -10,11 +10,12 @@ import { CommandTrigger } from "./Command";import { HStack } from "./HStack";import { IconButton } from "./IconButton";import type { PickerListOption } from "./PickerList";-import { PickerList, usePickerOpenAutoFocus } from "./PickerList";+import { PickerList } from "./PickerList";import { Popover, PopoverContent, PopoverTrigger } from "./Popover";import { TruncatedTooltipText } from "./TruncatedTooltipText";import { cn } from "./utils/cn";import { reactNodeToString } from "./utils/react";+import { usePhoneOpenAutoFocus } from "./Viewport";export type CreatableMultiSelectProps = Omit<ComponentPropsWithoutRef<"button">,@@ -80,7 +81,7 @@ const CreatableMultiSelect = forwardRef<const isReadOnly = isReadOnlyProp || disabled;const [open, setOpen] = useState(false);const [search, setSearch] = useState("");- const openAutoFocus = usePickerOpenAutoFocus(options.length);+ const openAutoFocus = usePhoneOpenAutoFocus();const id = useId();diff --git a/packages/react/src/Drawer.tsx b/packages/react/src/Drawer.tsxindex 1b4b483fb1..6dce495b4a 100644--- a/packages/react/src/Drawer.tsx+++ b/packages/react/src/Drawer.tsx@@ -23,7 +23,7 @@ import {useDialogDismissable} from "./Modal";import { cn } from "./utils/cn";-import { useViewport } from "./Viewport";+import { usePhoneOpenAutoFocus, useViewport } from "./Viewport";const Drawer = DialogRoot;@@ -88,8 +88,10 @@ const DrawerBody = ({);DrawerBody.displayName = "DrawerBody";+// Phones show every drawer as a bottom sheet, so it also slides up from the+// bottom whatever its desktop side.const sheetVariants = cva(- "flex flex-col z-50 scale-100 bg-accent dark:bg-card opacity-100 shadow-button-base dark:shadow-[inset_0_0.5px_0_rgb(255_255_255_/_0.08),_inset_0_0_1px_rgb(255_255_255_/_0.24),_0_0_0_0.5px_rgb(0,0,0,1),0px_0px_4px_rgba(0,_0,_0,_0.08)] border border-border transition-[background-color,box-shadow,border-color] duration-100 focus-visible:outline-none focus-visible:ring-0 rounded-xl max-md:max-h-[calc(100dvh-env(safe-area-inset-top)-12px)] max-md:w-full max-md:max-w-none max-md:overflow-hidden max-md:rounded-t-[14px] max-md:rounded-b-none max-md:border-0 max-md:bg-card max-md:h-auto max-md:[&>form]:min-h-0",+ "flex flex-col z-50 scale-100 bg-accent dark:bg-card opacity-100 shadow-button-base dark:shadow-[inset_0_0.5px_0_rgb(255_255_255_/_0.08),_inset_0_0_1px_rgb(255_255_255_/_0.24),_0_0_0_0.5px_rgb(0,0,0,1),0px_0px_4px_rgba(0,_0,_0,_0.08)] border border-border transition-[background-color,box-shadow,border-color] duration-100 focus-visible:outline-none focus-visible:ring-0 rounded-xl max-md:max-h-[calc(100dvh-env(safe-area-inset-top)-12px)] max-md:w-full max-md:max-w-none max-md:overflow-hidden max-md:rounded-t-[14px] max-md:rounded-b-none max-md:border-0 max-md:bg-card max-md:h-auto max-md:[&>form]:min-h-0 max-md:data-[state=open]:[--tw-enter-translate-x:0] max-md:data-[state=open]:[--tw-enter-translate-y:100%] max-md:data-[state=closed]:[--tw-exit-translate-x:0] max-md:data-[state=closed]:[--tw-exit-translate-y:100%]",{variants: {position: {@@ -205,6 +207,7 @@ const DrawerContent = forwardRef<) => {const dismissable = useDialogDismissable();const { isPhone } = useViewport();+ const onOpenAutoFocus = usePhoneOpenAutoFocus(props.onOpenAutoFocus);return (<ClientOnly fallback={null}>{() => (@@ -214,13 +217,7 @@ const DrawerContent = forwardRef<ref={ref}className={cn(sheetVariants({ position, size }), className)}{...props}- onOpenAutoFocus={(event) => {- // Phones: focusing the first field pops the keyboard (or a- // picker that opens on focus) over the form; keep focus on- // the sheet itself.- if (isPhone) event.preventDefault();- props.onOpenAutoFocus?.(event);- }}+ onOpenAutoFocus={onOpenAutoFocus}>{isPhone && (<div className="mx-auto mt-1.5 h-[5px] w-9 shrink-0 rounded-full bg-muted-foreground/20" />diff --git a/packages/react/src/Editor/Editor.tsx b/packages/react/src/Editor/Editor.tsxindex a25732de39..f060d5819e 100644--- a/packages/react/src/Editor/Editor.tsx+++ b/packages/react/src/Editor/Editor.tsx@@ -30,7 +30,7 @@ import { lazy, Suspense, useEffect, useMemo, useRef, useState } from "react";import { toast } from "sonner";import { Separator } from "../Separator";import { cn } from "../utils/cn";-import { useViewport } from "../Viewport";+import { usePhoneAutoFocus, useViewport } from "../Viewport";import { ColorSelector } from "./components/ColorSelector";import { LinkSelector } from "./components/LinkSelector";import { Toolbar } from "./components/Toolbar";@@ -122,6 +122,7 @@ const Editor = ({}: EditorProp) => {const { t } = useLingui();const { isPhone } = useViewport();+ const phoneAutoFocus = usePhoneAutoFocus(autoFocus);const titleMode = !!title;const titlePlaceholder = title?.placeholder ?? "Untitled";// The editor reads its extensions only once on mount, so the placeholder@@ -288,7 +289,9 @@ const Editor = ({initialContent: initialContentRef.current})}extensions={extensions}- autofocus={autoFocus}+ // tiptap focuses on mount when `autofocus` is undefined (desktop+ // today); phones get `false`.+ autofocus={phoneAutoFocus}editorProps={{handleDOMEvents: {keydown: (_view, event) => handleCommandNavigation(event)diff --git a/packages/react/src/HTML.tsx b/packages/react/src/HTML.tsxindex fd25b4b76c..b3f1cb9437 100644--- a/packages/react/src/HTML.tsx+++ b/packages/react/src/HTML.tsx@@ -9,7 +9,9 @@ import type { JSONContent } from "@tiptap/react";import { generateHTML as DefaultGenerateHTML } from "@tiptap/react";import StarterKit from "@tiptap/starter-kit";import pkg from "dompurify";+import type { ReactNode } from "react";import { defaultExtensions } from "./Editor/extensions";+import { cn } from "./utils/cn";const { sanitize } = pkg;@@ -52,4 +54,59 @@ const HTML = ({ text }: HTMLProps) => {);};-export { generateHTML, HTML };+// Nodes that only hold other nodes: empty unless something inside is not.+const CONTAINER_NODES = new Set([+ "doc",+ "paragraph",+ "heading",+ "hardBreak",+ "bulletList",+ "orderedList",+ "listItem",+ "blockquote"+]);++/**+ * True when rich text holds nothing to show: no text, image, mention or+ * other leaf. Reads the JSON, not the HTML, so the server (where+ * `generateHTML` returns "") agrees with the browser.+ */+const isRichTextEmpty = (content?: JSONContent | null): boolean => {+ if (!content) return true;+ if (content.type === "text") return !content.text?.trim();+ if (content.type && !CONTAINER_NODES.has(content.type)) return false;+ return (content.content ?? []).every(isRichTextEmpty);+};++/**+ * Read-only rich text (notes on a locked document). Phones show `empty` when+ * there is nothing, so the card does not read as broken; desktop keeps the+ * blank body it always had.+ */+const RichTextView = ({+ content,+ empty,+ className+}: {+ content?: JSONContent | null;+ empty: ReactNode;+ className?: string;+}) => {+ if (isRichTextEmpty(content)) {+ return (+ <p className="hidden text-sm text-muted-foreground max-md:block">+ {empty}+ </p>+ );+ }+ return (+ <div+ className={cn("prose dark:prose-invert", className)}+ dangerouslySetInnerHTML={{+ __html: generateHTML(content as JSONContent)+ }}+ />+ );+};++export { generateHTML, HTML, isRichTextEmpty, RichTextView };diff --git a/packages/react/src/Input.tsx b/packages/react/src/Input.tsxindex 9123a6cfea..a6418ae624 100644--- a/packages/react/src/Input.tsx+++ b/packages/react/src/Input.tsx@@ -10,6 +10,7 @@ import * as ReactAria from "react-aria-components";import { cn } from "./utils/cn";import { getValidChildren } from "./utils/react";+import { usePhoneAutoFocus } from "./Viewport";const InputGroupContext = createContext<boolean>(false);@@ -206,6 +207,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>() => {const isInputGroup = useContext(InputGroupContext) ?? false;const disabled = isDisabled ?? props.disabled ?? false;+ const autoFocus = usePhoneAutoFocus(props.autoFocus);return (<ReactAria.Input@@ -223,6 +225,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(className)}{...props}+ autoFocus={autoFocus}// Explicit disabled must survive the spread; it was being overwritten.disabled={disabled}readOnly={isReadOnly}diff --git a/packages/react/src/InputOTP.tsx b/packages/react/src/InputOTP.tsxindex 1d2e47940f..c6b1e3bef0 100644--- a/packages/react/src/InputOTP.tsx+++ b/packages/react/src/InputOTP.tsx@@ -7,6 +7,7 @@ import { OTPInput, OTPInputContext } from "input-otp";import * as React from "react";import { LuMinus } from "react-icons/lu";import { cn } from "./utils/cn";+import { usePhoneAutoFocus } from "./Viewport";function InputOTP({className,@@ -15,6 +16,7 @@ function InputOTP({}: React.ComponentProps<typeof OTPInput> & {containerClassName?: string;}) {+ const autoFocus = usePhoneAutoFocus(props.autoFocus);return (<OTPInputdata-slot="input-otp"@@ -24,6 +26,7 @@ function InputOTP({)}className={cn("disabled:cursor-not-allowed", className)}{...props}+ autoFocus={autoFocus}/>);}diff --git a/packages/react/src/Modal.tsx b/packages/react/src/Modal.tsxindex 1b4a2c7ec8..fffc97dcc9 100644--- a/packages/react/src/Modal.tsx+++ b/packages/react/src/Modal.tsx@@ -19,7 +19,7 @@ import { LuX } from "react-icons/lu";import { ActionPresentationBoundary } from "./ActionPresentation";import { ClientOnly } from "./ClientOnly";import { cn } from "./utils/cn";-import { useViewport } from "./Viewport";+import { usePhoneOpenAutoFocus, useViewport } from "./Viewport";// A dialog held open with no `onOpenChange` cannot be closed by the X, Escape// or a click outside, so it does not offer the X. Leave `onOpenChange` off to@@ -157,6 +157,7 @@ const ModalContent = forwardRef<) => {const dismissable = useDialogDismissable();const { isPhone } = useViewport();+ const phoneOpenAutoFocus = usePhoneOpenAutoFocus(onOpenAutoFocus);return (<ClientOnly fallback={null}>{() => (@@ -166,10 +167,7 @@ const ModalContent = forwardRef<ref={ref}className={cn(ModalContentVariants({ size }), className)}onOpenAutoFocus={(event) => {- // Phones: focusing the first field pops the keyboard over- // the sheet before the user has done anything.- if (isPhone) event.preventDefault();- onOpenAutoFocus?.(event);+ phoneOpenAutoFocus(event);if (!event.defaultPrevented) focusPrimaryAction(event);}}{...props}diff --git a/packages/react/src/MultiSelect.tsx b/packages/react/src/MultiSelect.tsxindex 5af1b3ecb9..00ffdbd18a 100644--- a/packages/react/src/MultiSelect.tsx+++ b/packages/react/src/MultiSelect.tsx@@ -10,11 +10,12 @@ import { CommandTrigger } from "./Command";import { HStack } from "./HStack";import { IconButton } from "./IconButton";import type { PickerListOption } from "./PickerList";-import { PickerList, usePickerOpenAutoFocus } from "./PickerList";+import { PickerList } from "./PickerList";import { Popover, PopoverContent, PopoverTrigger } from "./Popover";import { TruncatedTooltipText } from "./TruncatedTooltipText";import { cn } from "./utils/cn";import { reactNodeToString } from "./utils/react";+import { usePhoneOpenAutoFocus } from "./Viewport";export type MultiSelectProps = Omit<ComponentPropsWithoutRef<"button">,@@ -69,7 +70,7 @@ const MultiSelect = forwardRef<HTMLButtonElement, MultiSelectProps>(const isReadOnly = isReadOnlyProp || disabled;const [open, setOpen] = useState(false);const [search, setSearch] = useState("");- const openAutoFocus = usePickerOpenAutoFocus(options.length);+ const openAutoFocus = usePhoneOpenAutoFocus();const id = useId();diff --git a/packages/react/src/NavRail.tsx b/packages/react/src/NavRail.tsxindex bf24c7f40e..d58b541f2a 100644--- a/packages/react/src/NavRail.tsx+++ b/packages/react/src/NavRail.tsx@@ -6,7 +6,7 @@import { Trans } from "@lingui/react/macro";import { Slot, Slottable } from "@radix-ui/react-slot";-import type { ButtonHTMLAttributes, ReactNode } from "react";+import type { ButtonHTMLAttributes, MouseEvent, ReactNode } from "react";import {createContext,forwardRef,@@ -16,6 +16,7 @@ import {useRef,useState} from "react";+import { LuArrowUpRight } from "react-icons/lu";import type { LinkProps } from "react-router";import { Link, useLocation } from "react-router";import { Drawer, DrawerContent, DrawerTitle } from "./Drawer";@@ -165,22 +166,46 @@ export function NavRail({);if (isMobile) {+ // A tap on a link closes the sheet, also when it is the current page and+ // so no navigation follows.+ const closeOnLink = (event: MouseEvent<HTMLElement>) => {+ if ((event.target as Element).closest("a")) setOpenMobile(false);+ };+ // The footer (Clock In, My Hours, the user) stays pinned under the+ // scrolling groups, so it shows without a scroll.return (<Drawer open={openMobile} onOpenChange={setOpenMobile}>- <DrawerContent- position="left"- size="content"- className="w-[17rem] max-w-[85vw] p-0"- >- <DrawerTitle className="px-6 py-4">+ <DrawerContent position="left" size="content" className="p-0">+ <DrawerTitle className="px-6 py-4 max-md:px-4 max-md:text-[17px] max-md:font-semibold max-md:text-foreground"><Trans>Navigation</Trans></DrawerTitle>- <nav- data-state="expanded"- className="group flex-1 overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent pb-4"- >- {content}- </nav>+ <NavRailHoldContext.Provider value={hold}>+ <nav+ data-state="expanded"+ onClick={closeOnLink}+ className="group min-h-0 flex-1 overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent"+ >+ <VStack spacing={1} className="px-2">+ {header ? <div className="w-full pb-2">{header}</div> : null}+ {children}+ </VStack>+ {/* A static fade: it pins to the bottom while rows sit under+ the footer, and is only end padding once scrolled down. */}+ <div+ aria-hidden+ className="pointer-events-none sticky bottom-0 h-8 bg-gradient-to-t from-card"+ />+ </nav>+ {footer ? (+ <div+ data-state="expanded"+ onClick={closeOnLink}+ className="group shrink-0 border-t border-border px-2 pt-2 pb-[max(0.5rem,env(safe-area-inset-bottom))]"+ >+ <VStack spacing={1}>{footer}</VStack>+ </div>+ ) : null}+ </NavRailHoldContext.Provider></DrawerContent></Drawer>);@@ -335,7 +360,7 @@ export const NavRailItem = forwardRef<HTMLButtonElement, NavRailItemProps>({icon}</span>{tag ? (- <span className="absolute top-1 right-1 min-w-4 h-4 px-1 rounded-full bg-primary text-primary-foreground text-[10px] font-medium leading-4 text-center tabular-nums">+ <span className="absolute top-1 right-1 min-w-4 h-4 px-1 rounded-full bg-primary text-primary-foreground text-[10px] font-medium leading-4 text-center tabular-nums max-md:top-1/2 max-md:right-3 max-md:h-5 max-md:min-w-5 max-md:-translate-y-1/2 max-md:text-xs max-md:leading-5">{tag}</span>) : null}@@ -345,7 +370,8 @@ export const NavRailItem = forwardRef<HTMLButtonElement, NavRailItemProps>(className={cn("absolute left-7 right-3 min-w-32 group-data-[state=expanded]:left-12","flex items-center gap-2",- "opacity-0 group-data-[state=expanded]:opacity-100 max-md:opacity-100"+ "opacity-0 group-data-[state=expanded]:opacity-100 max-md:opacity-100",+ tag ? "max-md:right-11" : null)}><span@@ -438,6 +464,10 @@ export function NavRailBrand({>{label}</span>+ <LuArrowUpRight+ aria-hidden+ className="hidden size-4 shrink-0 text-muted-foreground max-md:block"+ /></a>);}diff --git a/packages/react/src/PickerList.tsx b/packages/react/src/PickerList.tsxindex deec4580da..037e39d8db 100644--- a/packages/react/src/PickerList.tsx+++ b/packages/react/src/PickerList.tsx@@ -78,8 +78,6 @@ export type PickerListProps = {showCreateOptionOnEmpty?: boolean;};-/** Phones: the search field takes focus on open only past this many options. */-const SEARCH_AUTOFOCUS_MIN_OPTIONS = 7;const COMPACT_ITEM_HEIGHT = 44;const labelOf = (option: PickerListOption) =>@@ -87,22 +85,6 @@ const labelOf = (option: PickerListOption) =>? option.label: reactNodeToString(option.label);-const preventAutoFocus = (event: Event) => event.preventDefault();--/**- * `onOpenAutoFocus` for a picker's `PopoverContent`: on phones the search- * field is focused (keyboard up) only when there are more than 7 options.- * Desktop keeps Radix's default focus.- */-export function usePickerOpenAutoFocus(- optionCount: number-): ((event: Event) => void) | undefined {- const { isPhone } = useViewport();- return isPhone && optionCount <= SEARCH_AUTOFOCUS_MIN_OPTIONS- ? preventAutoFocus- : undefined;-}-/*** The searchable, virtualized option list shared by Combobox,* CreatableCombobox, MultiSelect and CreatableMultiSelect.diff --git a/packages/react/src/SplitButton.tsx b/packages/react/src/SplitButton.tsxindex 4b22405321..218214fbb2 100644--- a/packages/react/src/SplitButton.tsx+++ b/packages/react/src/SplitButton.tsx@@ -56,6 +56,9 @@ const SplitButton = forwardRef<HTMLButtonElement, SplitButtonProps>(// render plainly (the boundary) so only these classes apply.const presentation = useActionPresentation();const presented = presentation !== null;+ // A bar cell shows the main action only; the dropdown's items become+ // rows of the record's ⋯, so the 44pt bar has one target.+ const inBar = presentation?.kind === "bar";const mainVariant =presentation?.kind === "bar"? presentation.emphasis@@ -81,7 +84,8 @@ const SplitButton = forwardRef<HTMLButtonElement, SplitButtonProps>(isLoading={isLoading}isDisabled={isDisabled}className={cn(- `rounded-r-none before:rounded-r-none hover:scale-100 focus-visible:scale-100`,+ !inBar &&+ `rounded-r-none before:rounded-r-none hover:scale-100 focus-visible:scale-100`,presented && "min-w-0 flex-1",presentation?.kind === "row" &&"h-12 justify-start rounded-sm px-3 text-[15px] font-normal text-foreground shadow-none",@@ -90,35 +94,51 @@ const SplitButton = forwardRef<HTMLButtonElement, SplitButtonProps>(>{children}</Button>- <DropdownMenu>- <DropdownMenuTrigger asChild>- <Button- variant={mainVariant}- size={presented ? "lg" : size}- isDisabled={isDisabled || isLoading}- className={cn(- "rounded-l-none border-l px-1 before:rounded-l-none border-none shadow-none",- mainVariant === "primary" &&- "dark:shadow-[inset_0px_0.5px_0px_rgb(255_255_255_/_0.32)] dark:hover:shadow-button-primary hover:scale-100 focus-visible:scale-100",- presented && "w-11 shrink-0 justify-center px-0"- )}- >- <LuChevronDown />- </Button>- </DropdownMenuTrigger>- <DropdownMenuContent>- {dropdownItems.map((item, index) => (- <DropdownMenuItem+ {inBar ? (+ presentation.overflow?.(+ dropdownItems.map((item, index) => (+ <Buttonkey={index}+ variant="secondary"+ leftIcon={item.icon}+ isDisabled={item.disabled}onClick={item.onClick}- disabled={item.disabled}>- {item.icon && <DropdownMenuIcon icon={item.icon} />}{item.label}- </DropdownMenuItem>- ))}- </DropdownMenuContent>- </DropdownMenu>+ </Button>+ ))+ )+ ) : (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button+ variant={mainVariant}+ size={presented ? "lg" : size}+ isDisabled={isDisabled || isLoading}+ className={cn(+ "rounded-l-none border-l px-1 before:rounded-l-none border-none shadow-none",+ mainVariant === "primary" &&+ "dark:shadow-[inset_0px_0.5px_0px_rgb(255_255_255_/_0.32)] dark:hover:shadow-button-primary hover:scale-100 focus-visible:scale-100",+ presented && "w-11 shrink-0 justify-center px-0"+ )}+ >+ <LuChevronDown />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent>+ {dropdownItems.map((item, index) => (+ <DropdownMenuItem+ key={index}+ onClick={item.onClick}+ disabled={item.disabled}+ >+ {item.icon && <DropdownMenuIcon icon={item.icon} />}+ {item.label}+ </DropdownMenuItem>+ ))}+ </DropdownMenuContent>+ </DropdownMenu>+ )}</div></ActionPresentationBoundary>);diff --git a/packages/react/src/TabBar.tsx b/packages/react/src/TabBar.tsxnew file mode 100644index 0000000000..03e3dd6b5e--- /dev/null+++ b/packages/react/src/TabBar.tsx@@ -0,0 +1,104 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,+// including ports, remain AGPLv3; serving them over a network requires releasing their source.++import type { HTMLAttributes, ReactNode } from "react";+import { Link } from "react-router";+import { cn } from "./utils/cn";++const tabBarItemClassName =+ "flex min-h-11 min-w-0 flex-1 flex-col items-center justify-center gap-0.5 text-[10.5px] font-medium leading-none outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50";++/** The phone bottom tab bar. Hidden at md and up. */+export function TabBar({+ className,+ children,+ ...props+}: HTMLAttributes<HTMLElement>) {+ return (+ <nav+ className={cn(+ "md:hidden flex shrink-0 items-stretch border-t border-border bg-card/92 px-1 pt-1 pb-safe backdrop-blur",+ className+ )}+ {...props}+ >+ {children}+ </nav>+ );+}++type TabBarItemProps = {+ icon: ReactNode;+ label: string;+ isActive?: boolean;+ /** A count on the icon. Hidden when 0 or missing. */+ count?: number;+ /** A pill behind the icon of the active tab. */+ pill?: boolean;+} & (+ | { to: string; onClick?: never }+ | {+ to?: never;+ onClick: () => void;+ /** Buttons that open a sheet: announce it. */+ "aria-haspopup"?: "dialog";+ "aria-expanded"?: boolean;+ }+);++/** One tab: a link when `to` is set, else a button. */+export function TabBarItem(props: TabBarItemProps) {+ const { icon, label, isActive = false, count, pill = false } = props;+ const content = (+ <>+ <span+ className={cn(+ "relative flex items-center justify-center [&>svg]:size-5",+ pill ? "h-7 w-12 rounded-full" : "size-6",+ pill && isActive && "bg-active",+ isActive ? "text-foreground" : "text-muted-foreground"+ )}+ >+ {icon}+ {count ? (+ <span className="absolute -top-1 left-1/2 ml-1 h-4 min-w-4 rounded-full bg-primary px-1 text-center text-[10px] font-medium leading-4 text-primary-foreground tabular-nums">+ {count}+ </span>+ ) : null}+ </span>+ <span+ className={cn(+ "max-w-full truncate",+ isActive ? "text-foreground" : "text-muted-foreground"+ )}+ >+ {label}+ </span>+ </>+ );++ if (props.to !== undefined) {+ return (+ <Link+ to={props.to}+ className={tabBarItemClassName}+ aria-current={isActive ? "page" : undefined}+ >+ {content}+ </Link>+ );+ }++ return (+ <button+ type="button"+ className={tabBarItemClassName}+ onClick={props.onClick}+ aria-haspopup={props["aria-haspopup"]}+ aria-expanded={props["aria-expanded"]}+ >+ {content}+ </button>+ );+}diff --git a/packages/react/src/Textarea.tsx b/packages/react/src/Textarea.tsxindex ed0b6c1d02..61482d772a 100644--- a/packages/react/src/Textarea.tsx+++ b/packages/react/src/Textarea.tsx@@ -7,6 +7,7 @@ import { cva } from "class-variance-authority";import type { TextareaHTMLAttributes } from "react";import { forwardRef } from "react";import { cn } from "./utils/cn";+import { usePhoneAutoFocus } from "./Viewport";const textareaVariants = cva("flex min-h-[2lh] max-h-[10lh] w-full border border-input bg-transparent shadow-xs transition-[color,box-shadow] placeholder:text-muted-foreground outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 read-only:bg-muted read-only:cursor-not-allowed dark:aria-invalid:ring-destructive/40",@@ -30,11 +31,13 @@ export interface TextareaPropsconst Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(({ className, size, ...props }, ref) => {+ const autoFocus = usePhoneAutoFocus(props.autoFocus);return (<textareaclassName={cn(textareaVariants({ size }), className)}ref={ref}{...props}+ autoFocus={autoFocus}/>);}diff --git a/packages/react/src/Viewport.tsx b/packages/react/src/Viewport.tsxindex b2c4a48493..ec1854405e 100644--- a/packages/react/src/Viewport.tsx+++ b/packages/react/src/Viewport.tsx@@ -83,6 +83,27 @@ export function useViewport(): {);}+/*+ * Phones never move focus on their own: focusing a text field pops the+ * keyboard over the page. These two hooks are the one place that rule lives.+ */++export function usePhoneAutoFocus(autoFocus: boolean | undefined) {+ return useViewport().isPhone ? false : autoFocus;+}++/**+ * A Radix `onOpenAutoFocus` that skips the first focus on phones and then+ * runs the caller's own handler.+ */+export function usePhoneOpenAutoFocus(handler?: (event: Event) => void) {+ const { isPhone } = useViewport();+ return (event: Event) => {+ if (isPhone) event.preventDefault();+ handler?.(event);+ };+}+/*** Phones: a 44x44 tap target around a smaller control. A child element rather* than the control's ::after, which already draws the focus ring. Place itdiff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsxindex ef315122c8..26f738e6dc 100644--- a/packages/react/src/index.tsx+++ b/packages/react/src/index.tsx@@ -167,7 +167,7 @@ import {import { Heading } from "./Heading";import { HoverCard, HoverCardContent, HoverCardTrigger } from "./HoverCard";import { HStack } from "./HStack";-import { generateHTML, HTML } from "./HTML";+import { generateHTML, HTML, isRichTextEmpty, RichTextView } from "./HTML";import type {Modifier,Shortcut,@@ -348,6 +348,7 @@ import { Subheading } from "./Subheading";import { Switch } from "./Switch";import type { MenuItemShortcut } from "./shortcuts";import { MENU_ITEM_SHORTCUTS, SHORTCUTS } from "./shortcuts";+import { TabBar, TabBarItem } from "./TabBar";import { Table, TableCaption, Tbody, Td, Tfoot, Th, Thead, Tr } from "./Table";import { Tabs, TabsContent, TabsList, TabsTrigger } from "./Tabs";import type { TextareaProps } from "./Textarea";@@ -510,6 +511,7 @@ export {FormLabel,HStack,HTML,+ RichTextView,Heading,HoverCard,HoverCardContent,@@ -661,6 +663,8 @@ export {Status,Subheading,Switch,+ TabBar,+ TabBarItem,Table,TableCaption,Tabs,@@ -694,6 +698,7 @@ export {cn,copyToClipboard,generateHTML,+ isRichTextEmpty,getValidChildren,multiSelectTriggerVariants,reactNodeToString,