:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(quill): add tooltip, disabledReason, menu description and compact input to primitives (#119635)
Adam Leith0ed6297e6c10
diff --git a/packages/quill/packages/primitives/AGENTS.md b/packages/quill/packages/primitives/AGENTS.mdindex 17051d43f8bf..72dc305d158f 100644--- a/packages/quill/packages/primitives/AGENTS.md+++ b/packages/quill/packages/primitives/AGENTS.md@@ -135,22 +135,22 @@ Don't hand-roll `<p className="text-xs text-muted-foreground">` when `<Text size## Component Catalog-| Component | Variants | Sizes | Notes |-| ------------ | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| Button | default, primary, secondary, outline, destructive, destructive-outline, link, link-muted | default, xs, sm, lg, icon, icon-xs, icon-sm, icon-lg, row, inline | `loading` overlays a centered spinner and disables the button (width stays stable). `row` is the full-width, regular-weight list row that menu, combobox and autocomplete items render. `inline` is a link inside a sentence: no height or padding, and it inherits the sentence's font size and line height. `elevated` adds heavy CTA chrome — see Elevated button. |-| Badge | default, info, destructive, warning, success, completed | — | Semantic status |-| Toggle | default, outline | default, sm, lg, icon | |-| Chip | outline | sm | Use with ChipClose |-| Separator | — | — | orientation: horizontal/vertical |-| Spinner | — | — | SVG, accepts svg props |-| Skeleton | — | — | Pulsing placeholder div |-| SkeletonText | — | — | lines, minWidth, maxWidth |-| Progress | — | — | value: 0-100 |-| Slider | — | — | value, min, max |-| Avatar | — | lg, default, sm, xs | Compose `Avatar > AvatarImage + AvatarFallback`; image errors fall back to initials/icon |-| ChatGlobe | — | — | Sweeping globe for "browsing the web"; sizes from its container. Still globe under reduced motion |-| AvatarGroup | — | default, sm, xs | Row of Avatars; `stacked` overlaps + spreads on hover (no reflow), `reverse` spreads left; `size` forwards to children |-| IconStack | — | — | Fanned colored icon tiles (`IconStackItem`, `color` per product, grey default); spreads on hover. The Empty icon, or a trailing set of items after text |+| Component | Variants | Sizes | Notes |+| ------------ | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| Button | default, primary, secondary, outline, destructive, destructive-outline, link, link-muted | default, xs, sm, lg, icon, icon-xs, icon-sm, icon-lg, row, inline | `loading` overlays a centered spinner and disables the button (width stays stable). `row` is the full-width, regular-weight list row that menu, combobox and autocomplete items render. `inline` is a link inside a sentence: no height or padding, and it inherits the sentence's font size and line height. `elevated` adds heavy CTA chrome — see Elevated button. `tooltip` adds a hover and focus tooltip. `disabledReason` disables the button and shows the reason in that tooltip. A `render` that carries a link destination (`to`, `href`) or is a non-button element turns off `nativeButton` by itself; a disabled button drops that destination. |+| Badge | default, info, destructive, warning, success, completed | — | Semantic status |+| Toggle | default, outline | default, sm, lg, icon | |+| Chip | outline | sm | Use with ChipClose |+| Separator | — | — | orientation: horizontal/vertical |+| Spinner | — | — | SVG, accepts svg props |+| Skeleton | — | — | Pulsing placeholder div |+| SkeletonText | — | — | lines, minWidth, maxWidth |+| Progress | — | — | value: 0-100 |+| Slider | — | — | value, min, max |+| Avatar | — | lg, default, sm, xs | Compose `Avatar > AvatarImage + AvatarFallback`; image errors fall back to initials/icon |+| ChatGlobe | — | — | Sweeping globe for "browsing the web"; sizes from its container. Still globe under reduced motion |+| AvatarGroup | — | default, sm, xs | Row of Avatars; `stacked` overlaps + spreads on hover (no reflow), `reverse` spreads left; `size` forwards to children |+| IconStack | — | — | Fanned colored icon tiles (`IconStackItem`, `color` per product, grey default); spreads on hover. The Empty icon, or a trailing set of items after text |---@@ -339,6 +339,8 @@ For a select-all over a partly selected list, pass `indeterminate`: the box fillSwitch has sizes: `<Switch size="sm" />` or `<Switch size="default" />`+`disabledReason` on a Checkbox or Switch disables it and shows the reason in a tooltip.+### Select```tsx@@ -512,6 +514,20 @@ Same shell as Dialog (shared `quill-dialog__*` styles) but `role="alertdialog"`,Destructive items (`variant="destructive"` on DropdownMenuItem/ContextMenuItem/MenubarItem) forward straight to Button's `destructive` variant, so a delete row in a menu reads exactly like a standalone destructive Button: a red fill at rest, brighter on hover or keyboard highlight. The item owns that mapping — don't pass a Button variant through `render` to restyle a menu item.+A row with a second line takes `description`; the row grows to fit, and the description lines up past a leading icon. Any item, sub trigger, checkbox or radio item takes `tooltip` and `disabledReason`; both open beside the row, and `disabledReason` also disables it. A disabled row ignores the pointer, so don't hand-wrap it in a Tooltip yourself.++```tsx+<DropdownMenuItem description="Start from an empty folder">+ <FolderIcon />+ New folder+</DropdownMenuItem>+<DropdownMenuItem variant="destructive" disabledReason="Only owners can delete this folder">+ Delete+</DropdownMenuItem>+```++The popup sizes to its longest row, never narrower than its trigger and never wider than the space on screen. Don't set a width on `DropdownMenuContent` unless the content needs a fixed one.+Checkbox/radio items:```tsx@@ -631,6 +647,8 @@ The arrow inherits the popup's border and background, so restyling the popover c### Tooltip+A Button, menu item, Checkbox or Switch that only needs a text tooltip or a disabled reason takes the `tooltip` / `disabledReason` prop; reach for the composed form below for anything else.+```tsx<Tooltip><TooltipTrigger render={<Button size="icon" />}>?</TooltipTrigger>@@ -1255,7 +1273,7 @@ Primitives carry their own padding and heights. Adding `p-*`/`h-*` via `classNam| Primitive | Built-in || ---------------------------------- | ------------------------------------------------------------------------------------- || Button | h-7 px-2 (default), h-6 (sm), h-5 (xs), h-8 (lg); gap-2 icon spacing |-| Input | h-8, px-2 |+| Input / InputGroup | h-8, px-2; `size="sm"` is h-7, to sit in a row with default-size Buttons || Card / CardHeader / CardContent | 1rem block + inline padding, gap-4 between sections (0.75rem / gap-3 for `size="sm"`) || Menu popups (Dropdown/Context/...) | p-1 scroller; items pad themselves || Item | py-2.5 px-3 (default/sm), py-2 px-2.5 (xs) |diff --git a/packages/quill/packages/primitives/src/button.stories.tsx b/packages/quill/packages/primitives/src/button.stories.tsxindex 0f7afd358fe2..1c1e96311afe 100644--- a/packages/quill/packages/primitives/src/button.stories.tsx+++ b/packages/quill/packages/primitives/src/button.stories.tsx@@ -257,6 +257,27 @@ export const Disabled = {),} satisfies Story+export const Tooltips = {+ render: () => (+ <div className="flex flex-wrap items-center gap-2">+ <Button size="icon" aria-label="Delete" tooltip="Delete">+ <TrashIcon />+ </Button>+ <Button variant="outline" tooltip="Saves a copy you can come back to">+ Save draft+ </Button>+ <Button variant="primary" disabledReason="Add a name before you publish">+ Publish+ </Button>+ {/* A story has no router; a plain anchor shows the non-button render. */}+ {/* eslint-disable-next-line react/forbid-elements */}+ <Button variant="outline" render={<a href="#docs" />} disabledReason="Docs are not available offline">+ Read the docs+ </Button>+ </div>+ ),+} satisfies Story+export const Loading = {render: () => {const [saving, setSaving] = useState(false)diff --git a/packages/quill/packages/primitives/src/button.tsx b/packages/quill/packages/primitives/src/button.tsxindex 69ca03001856..8ac275e569c7 100644--- a/packages/quill/packages/primitives/src/button.tsx+++ b/packages/quill/packages/primitives/src/button.tsx@@ -6,6 +6,7 @@ import * as React from 'react'import { cn } from './lib/utils'import { Spinner } from './spinner'+import { hasTooltipContent, withTooltip } from './with-tooltip'const buttonVariants = cva('quill-button group/button inline-flex shrink-0 items-center justify-center whitespace-nowrap',@@ -66,7 +67,45 @@ export type ButtonProps = ButtonPrimitive.Props &* Use with `primary` or `outline`. At most two in a row; any further button is a flat `default`. See AGENTS.md.*/elevated?: boolean+ /** Text shown on hover and focus. Icon-only buttons need one, matching their `aria-label`. */+ tooltip?: React.ReactNode+ /**+ * Disables the button and says why in its tooltip. The button stays hoverable and focusable,+ * so the reason is always reachable. Takes the place of `tooltip` while set. A rendered link+ * loses its destination while disabled, so a modifier click cannot open it either.+ */+ disabledReason?: React.ReactNode+ }++/**+ * Whether the `render` element needs Base UI's non-native button handling. A plain element is a+ * button only when it is `<button>`. A component is assumed to render one unless it carries a link+ * destination: `LinkPrimitive` renders an anchor only when given `to`, and composed triggers such+ * as `ComboboxTrigger` render a real `<button>`.+ */+function rendersNonButton(render: ButtonPrimitive.Props['render']): boolean {+ if (!React.isValidElement<{ to?: unknown; href?: unknown }>(render)) {+ return false+ }+ if (typeof render.type === 'string') {+ return render.type !== 'button'}+ return render.props.to !== undefined || render.props.href !== undefined+}++/**+ * A disabled button keeps no destination. The browser handles a modifier click on a rendered link+ * before any click guard runs, so a kept `href` or `to` would still open in a new tab.+ */+function withoutDestination(render: ButtonPrimitive.Props['render']): ButtonPrimitive.Props['render'] {+ if (!React.isValidElement<{ to?: unknown; href?: unknown }>(render)) {+ return render+ }+ if (render.props.to === undefined && render.props.href === undefined) {+ return render+ }+ return React.cloneElement(render, { to: undefined, href: undefined })+}const Button = React.forwardRef<HTMLButtonElement, ButtonProps>((@@ -79,12 +118,19 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(elevated = false,loading = false,disabled,+ tooltip,+ disabledReason,+ nativeButton,+ render,children,...props},ref) => {- return (+ const hasDisabledReason = hasTooltipContent(disabledReason)+ const isDisabled = disabled || loading || hasDisabledReason+ const renderTarget = isDisabled ? withoutDestination(render) : render+ const button = (<ButtonPrimitiveref={ref}data-quill@@ -92,12 +138,14 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(data-size={size}data-loading={loading || undefined}aria-busy={loading || undefined}- disabled={disabled || loading}+ disabled={isDisabled}+ nativeButton={nativeButton ?? !rendersNonButton(renderTarget)}+ render={renderTarget}// While loading, stay focusable: Base UI then renders aria-disabled instead of// the native disabled attribute, keeping the button in the tab order so screen- // readers can reach it and announce busy. Activation stays blocked.-- focusableWhenDisabled={loading ? true : focusableWhenDisabled}+ // readers can reach it and announce busy. Activation stays blocked. A disabled+ // reason needs the same, because its tooltip only opens on hover or focus.+ focusableWhenDisabled={loading || hasDisabledReason ? true : focusableWhenDisabled}className={cn(buttonVariants({ variant, size, className, focusableWhenDisabled, left, elevated }))}{...props}>@@ -105,6 +153,10 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>({loading && <Spinner className="quill-button__spinner" />}</ButtonPrimitive>)+ return withTooltip(button, hasDisabledReason ? disabledReason : tooltip, {+ target: 'self',+ delay: size?.startsWith('icon') ? 0 : undefined,+ })})Button.displayName = 'Button'diff --git a/packages/quill/packages/primitives/src/checkbox.tsx b/packages/quill/packages/primitives/src/checkbox.tsxindex 95e4ca90876c..ed1af1880777 100644--- a/packages/quill/packages/primitives/src/checkbox.tsx+++ b/packages/quill/packages/primitives/src/checkbox.tsx@@ -6,6 +6,7 @@ import { CheckIcon, MinusIcon } from 'lucide-react'import * as React from 'react'import { cn } from './lib/utils'+import { hasTooltipContent, withTooltip } from './with-tooltip'const checkboxIndicatorVariants = cva('quill-checkbox-indicator flex shrink-0 items-center justify-center', {variants: {@@ -64,13 +65,18 @@ const checkboxVariants = cva('quill-checkbox peer flex shrink-0 items-center jusconst Checkbox = React.forwardRef<React.ComponentRef<typeof CheckboxPrimitive.Root>,- CheckboxPrimitive.Root.Props & VariantProps<typeof checkboxVariants>->(function Checkbox({ className, size = 'default', ...props }, ref) {- return (+ CheckboxPrimitive.Root.Props &+ VariantProps<typeof checkboxVariants> & {+ /** Disables the checkbox and says why in a tooltip. */+ disabledReason?: React.ReactNode+ }+>(function Checkbox({ className, size = 'default', disabled, disabledReason, ...props }, ref) {+ return withTooltip(<CheckboxPrimitive.Rootref={ref}data-quilldata-slot="checkbox"+ disabled={disabled || hasTooltipContent(disabledReason)}className={cn(checkboxVariants({ size }), className)}{...props}>@@ -84,7 +90,9 @@ const Checkbox = React.forwardRef<<CheckboxIndicator checked size={size ?? 'default'} className="border-none bg-transparent" />)}</CheckboxPrimitive.Indicator>- </CheckboxPrimitive.Root>+ </CheckboxPrimitive.Root>,+ disabledReason,+ { target: 'inline', focusable: hasTooltipContent(disabledReason) })})diff --git a/packages/quill/packages/primitives/src/dropdown-menu.stories.tsx b/packages/quill/packages/primitives/src/dropdown-menu.stories.tsxindex 06b5029928e5..8e114fe4a5b7 100644--- a/packages/quill/packages/primitives/src/dropdown-menu.stories.tsx+++ b/packages/quill/packages/primitives/src/dropdown-menu.stories.tsx@@ -155,6 +155,41 @@ export const Checkboxes: Story = {},} satisfies Story+export const DescriptionsAndDisabledReasons: Story = {+ render: () => (+ <DropdownMenu defaultOpen>+ <DropdownMenuTrigger render={<Button variant="primary" size="icon" aria-label="New" tooltip="New" />}>+ <MoreVertical />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem description="Start from an empty folder">+ <Folder />+ New folder+ </DropdownMenuItem>+ <DropdownMenuItem description="Make an exact copy, including its settings">+ <Copy />+ Duplicate+ </DropdownMenuItem>+ <DropdownMenuSub>+ <DropdownMenuSubTrigger description="Rename, move or change who can see it">+ <Pencil />+ Edit+ </DropdownMenuSubTrigger>+ <DropdownMenuSubContent>+ <DropdownMenuItem>Rename</DropdownMenuItem>+ <DropdownMenuItem>Move</DropdownMenuItem>+ </DropdownMenuSubContent>+ </DropdownMenuSub>+ <DropdownMenuSeparator />+ <DropdownMenuItem variant="destructive" disabledReason="Only owners can delete this folder">+ <TrashIcon />+ Delete+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ ),+} satisfies Story+export const Radios: Story = {render: () => {const [open, setOpen] = useState(true)diff --git a/packages/quill/packages/primitives/src/dropdown-menu.tsx b/packages/quill/packages/primitives/src/dropdown-menu.tsxindex 2dc4ef012383..5749c24f0099 100644--- a/packages/quill/packages/primitives/src/dropdown-menu.tsx+++ b/packages/quill/packages/primitives/src/dropdown-menu.tsx@@ -10,6 +10,38 @@ import { Kbd } from './kbd'import { cn } from './lib/utils'import { MenuLabel } from './menu-label'import { RadioIndicator } from './radio-group'+import { hasTooltipContent, withTooltip } from './with-tooltip'++type MenuItemExtras = {+ /** Text shown in a tooltip beside the item. */+ tooltip?: React.ReactNode+ /** Disables the item and says why in a tooltip beside it. Takes the place of `tooltip` while set. */+ disabledReason?: React.ReactNode+}++type DescribedMenuItemExtras = MenuItemExtras & {+ /** A muted second line under the label. The row grows to fit it, and its text lines up past a leading icon. */+ description?: React.ReactNode+}++/** Disabled items ignore the pointer, so the tooltip listens on a wrapper and opens beside the row. */+function withItemTooltip(+ item: React.ReactElement,+ { tooltip, disabledReason }: Pick<MenuItemExtras, 'tooltip' | 'disabledReason'>+): React.ReactElement {+ const content = hasTooltipContent(disabledReason) ? disabledReason : tooltip+ return withTooltip(item, content, { target: 'block', side: 'inline-end' })+}++function MenuItemBody({ children, description }: { children: React.ReactNode; description: React.ReactNode }): React.ReactElement {+ return (+ <span className="quill-menu-item__body">+ <span className="quill-menu-item__title">{children}</span>+ <span className="quill-menu-item__description">{description}</span>+ </span>+ )+}+function DropdownMenu({ ...props }: MenuPrimitive.Root.Props): React.ReactElement {return <MenuPrimitive.Root data-slot="dropdown-menu" {...props} />@@ -48,7 +80,7 @@ const DropdownMenuContent = React.forwardRef<<MenuPrimitive.Popupref={ref}data-slot="dropdown-menu-content"- className={cn('quill-menu__content w-(--anchor-width)', className)}+ className={cn('quill-menu__content w-max min-w-(--anchor-width) max-w-(--available-width)', className)}{...props}><div className="quill-menu__scroller scroll-mask-y-4 scroll-py-4">{children}</div>@@ -84,20 +116,27 @@ const DropdownMenuLabel = React.forwardRef<const DropdownMenuItem = React.forwardRef<React.ComponentRef<typeof MenuPrimitive.Item>,- MenuPrimitive.Item.Props & {- inset?: boolean- variant?: 'default' | 'destructive'- }->(function DropdownMenuItem({ className, inset, variant = 'default', ...props }, ref) {- return (+ MenuPrimitive.Item.Props &+ DescribedMenuItemExtras & {+ inset?: boolean+ variant?: 'default' | 'destructive'+ }+>(function DropdownMenuItem(+ { className, inset, variant = 'default', disabled, tooltip, disabledReason, description, children, ...props },+ ref+) {+ const described = hasTooltipContent(description)+ return withItemTooltip(<MenuPrimitive.Itemref={ref}data-slot="dropdown-menu-item"data-inset={inset}data-variant={variant}+ disabled={disabled || hasTooltipContent(disabledReason)}className={cn("group/dropdown-menu-item relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",inset && 'quill-menu-item--inset',+ described && 'quill-menu-item--described',className)}// The default render is a real <button>; only declare nativeButton when the@@ -105,7 +144,10 @@ const DropdownMenuItem = React.forwardRef<nativeButton={!('render' in props)}render={<Button variant={variant} size="row" className="[&_kbd]:ml-auto" left />}{...props}- />+ >+ {described ? <MenuItemBody description={description}>{children}</MenuItemBody> : children}+ </MenuPrimitive.Item>,+ { tooltip, disabledReason })})@@ -115,18 +157,25 @@ function DropdownMenuSub({ ...props }: MenuPrimitive.SubmenuRoot.Props): React.Rconst DropdownMenuSubTrigger = React.forwardRef<React.ComponentRef<typeof MenuPrimitive.SubmenuTrigger>,- MenuPrimitive.SubmenuTrigger.Props & {- inset?: boolean- }->(function DropdownMenuSubTrigger({ className, inset, children, ...props }, ref) {- return (+ MenuPrimitive.SubmenuTrigger.Props &+ DescribedMenuItemExtras & {+ inset?: boolean+ }+>(function DropdownMenuSubTrigger(+ { className, inset, disabled, tooltip, disabledReason, description, children, ...props },+ ref+) {+ const described = hasTooltipContent(description)+ return withItemTooltip(<MenuPrimitive.SubmenuTriggerref={ref}data-slot="dropdown-menu-sub-trigger"data-inset={inset}+ disabled={disabled || hasTooltipContent(disabledReason)}className={cn(- "flex cursor-default items-center outline-hidden select-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",+ "flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",inset && 'quill-menu-item--inset',+ described && 'quill-menu-item--described',className)}// The default render is a real <button>; only declare nativeButton when the@@ -135,9 +184,10 @@ const DropdownMenuSubTrigger = React.forwardRef<render={<Button size="row" left />}{...props}>- {children}+ {described ? <MenuItemBody description={description}>{children}</MenuItemBody> : children}<ChevronRightIcon className="rtl:rotate-180 ms-auto" />- </MenuPrimitive.SubmenuTrigger>+ </MenuPrimitive.SubmenuTrigger>,+ { tooltip, disabledReason })})@@ -164,15 +214,20 @@ const DropdownMenuSubContent = React.forwardRef<const DropdownMenuCheckboxItem = React.forwardRef<React.ComponentRef<typeof MenuPrimitive.CheckboxItem>,- MenuPrimitive.CheckboxItem.Props & {- inset?: boolean- }->(function DropdownMenuCheckboxItem({ className, children, checked, inset, ...props }, ref) {- return (+ MenuPrimitive.CheckboxItem.Props &+ MenuItemExtras & {+ inset?: boolean+ }+>(function DropdownMenuCheckboxItem(+ { className, children, checked, inset, disabled, tooltip, disabledReason, ...props },+ ref+) {+ return withItemTooltip(<MenuPrimitive.CheckboxItemref={ref}data-slot="dropdown-menu-checkbox-item"data-inset={inset}+ disabled={disabled || hasTooltipContent(disabledReason)}className={cn("quill-menu-item--inset relative flex cursor-default items-center pe-2 outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",className@@ -194,7 +249,8 @@ const DropdownMenuCheckboxItem = React.forwardRef<</MenuPrimitive.CheckboxItemIndicator></span>{children}- </MenuPrimitive.CheckboxItem>+ </MenuPrimitive.CheckboxItem>,+ { tooltip, disabledReason })})@@ -207,15 +263,17 @@ const DropdownMenuRadioGroup = React.forwardRef<const DropdownMenuRadioItem = React.forwardRef<React.ComponentRef<typeof MenuPrimitive.RadioItem>,- MenuPrimitive.RadioItem.Props & {- inset?: boolean- }->(function DropdownMenuRadioItem({ className, children, inset, ...props }, ref) {- return (+ MenuPrimitive.RadioItem.Props &+ MenuItemExtras & {+ inset?: boolean+ }+>(function DropdownMenuRadioItem({ className, children, inset, disabled, tooltip, disabledReason, ...props }, ref) {+ return withItemTooltip(<MenuPrimitive.RadioItemref={ref}data-slot="dropdown-menu-radio-item"data-inset={inset}+ disabled={disabled || hasTooltipContent(disabledReason)}className={cn("quill-menu-item--inset relative flex min-h-7 cursor-default items-center pe-2 outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",className@@ -236,7 +294,8 @@ const DropdownMenuRadioItem = React.forwardRef<</MenuPrimitive.RadioItemIndicator></span>{children}- </MenuPrimitive.RadioItem>+ </MenuPrimitive.RadioItem>,+ { tooltip, disabledReason })})diff --git a/packages/quill/packages/primitives/src/input-group.css b/packages/quill/packages/primitives/src/input-group.cssindex 299a7edf6282..8f27c90ef206 100644--- a/packages/quill/packages/primitives/src/input-group.css+++ b/packages/quill/packages/primitives/src/input-group.css@@ -15,6 +15,10 @@border-color 0.15s ease;}+ .quill-input-group--size-sm {+ height: 1.75rem;+ }+:is(.dark, [theme='dark']) .quill-input-group {background-color: color-mix(in oklab, var(--input) 30%, transparent);}diff --git a/packages/quill/packages/primitives/src/input-group.tsx b/packages/quill/packages/primitives/src/input-group.tsxindex c63d9699a55f..573a9271d44a 100644--- a/packages/quill/packages/primitives/src/input-group.tsx+++ b/packages/quill/packages/primitives/src/input-group.tsx@@ -8,14 +8,25 @@ import { Input } from './input'import { cn } from './lib/utils'import { Textarea } from './textarea'-const InputGroup = React.forwardRef<HTMLDivElement, React.ComponentProps<'div'>>(({ className, ...props }, ref) => {+const InputGroup = React.forwardRef<+ HTMLDivElement,+ React.ComponentProps<'div'> & {+ /** `sm` matches a default-size Button, for a field that shares a row with buttons. */+ size?: 'default' | 'sm'+ }+>(({ className, size = 'default', ...props }, ref) => {return (<divref={ref}data-quilldata-slot="input-group"+ data-size={size}role="group"- className={cn('quill-input-group group/input-group flex items-center', className)}+ className={cn(+ 'quill-input-group group/input-group flex items-center',+ size === 'sm' && 'quill-input-group--size-sm',+ className+ )}{...props}/>)@@ -102,7 +113,7 @@ const InputGroupText = React.forwardRef<HTMLSpanElement, React.ComponentProps<'sreturn <span ref={ref} className={cn('quill-input-group__text flex items-end gap-2', className)} {...props} />})-const InputGroupInput = React.forwardRef<HTMLInputElement, React.ComponentProps<'input'>>(+const InputGroupInput = React.forwardRef<HTMLInputElement, Omit<React.ComponentProps<'input'>, 'size'>>(({ className, ...props }, ref) => {return (<Inputdiff --git a/packages/quill/packages/primitives/src/input.css b/packages/quill/packages/primitives/src/input.cssindex 69825117db3b..1016ee7309d9 100644--- a/packages/quill/packages/primitives/src/input.css+++ b/packages/quill/packages/primitives/src/input.css@@ -16,6 +16,10 @@border-color 0.15s ease;}+ .quill-input--size-sm {+ height: 1.75rem;+ }+:is(.dark, [theme='dark']) .quill-input {background-color: color-mix(in oklab, var(--input) 30%, transparent);}diff --git a/packages/quill/packages/primitives/src/input.tsx b/packages/quill/packages/primitives/src/input.tsxindex 006c7414f6c1..9505fef29dfd 100644--- a/packages/quill/packages/primitives/src/input.tsx+++ b/packages/quill/packages/primitives/src/input.tsx@@ -4,15 +4,21 @@ import * as React from 'react'import './input.css'import { cn } from './lib/utils'-const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<'input'>>(- ({ className, type, ...props }, ref) => {+const Input = React.forwardRef<+ HTMLInputElement,+ Omit<React.ComponentProps<'input'>, 'size'> & {+ /** `sm` matches a default-size Button, for a field that shares a row with buttons. */+ size?: 'default' | 'sm'+ }+>(({ className, type, size = 'default', ...props }, ref) => {return (<InputPrimitiveref={ref}type={type}data-quilldata-slot="input"- className={cn('quill-input', className)}+ data-size={size}+ className={cn('quill-input', size === 'sm' && 'quill-input--size-sm', className)}{...props}/>)diff --git a/packages/quill/packages/primitives/src/menu.css b/packages/quill/packages/primitives/src/menu.cssindex 4556cffe43b8..f7eafd5e1242 100644--- a/packages/quill/packages/primitives/src/menu.css+++ b/packages/quill/packages/primitives/src/menu.css@@ -90,6 +90,58 @@padding-inline-start: 1.875rem;}+ /*+ * A row with a `description`: it grows past the one-line row height, and its+ * trailing parts (submenu chevron, kbd) sit on the label's line.+ */+ .quill-button.quill-menu-item--described {+ align-items: flex-start;+ height: auto;+ min-height: 1.75rem;+ padding-block: 0.375rem;+ }++ .quill-menu-item--described > svg {+ margin-block-start: 0.1875rem;+ }++ /* The body fills the row, so a trailing child of the label (`ms-auto`) reaches the row's end. */+ .quill-menu-item__body {+ display: flex;+ flex: 1 1 auto;+ flex-direction: column;+ min-width: 0;+ text-align: start;+ }++ .quill-menu-item__title {+ display: flex;+ gap: 0.5rem;+ align-items: center;+ min-width: 0;+ }++ .quill-menu-item__description {+ max-width: 20rem;+ font-size: var(--text-xs, 0.75rem);+ line-height: 1.4;+ color: var(--muted-foreground);+ white-space: normal;+ }++ /* A leading avatar in a menu row takes the row's icon size, so avatars and icons line up down the menu. */+ :is([data-slot='dropdown-menu-item'], [data-slot='dropdown-menu-sub-trigger'], .quill-menu-item__title)+ > [data-slot='avatar'][data-size] {+ --avatar-size: 0.875rem;++ font-size: 0.5rem;+ }++ /* Line the description up with the label, past the leading icon or avatar (0.875rem + the 0.5rem gap). */+ .quill-menu-item__title:has(> svg:first-child, > [data-slot='avatar']:first-child) + .quill-menu-item__description {+ padding-inline-start: 1.375rem;+ }+/** Checkbox / radio menu items get a stronger "active" background than the* generic fill-selected (which is too subtle on white popover surfaces).diff --git a/packages/quill/packages/primitives/src/switch.tsx b/packages/quill/packages/primitives/src/switch.tsxindex 33339c0b9edd..3b5048c9e9e1 100644--- a/packages/quill/packages/primitives/src/switch.tsx+++ b/packages/quill/packages/primitives/src/switch.tsx@@ -3,24 +3,30 @@ import * as React from 'react'import './switch.css'import { cn } from './lib/utils'+import { hasTooltipContent, withTooltip } from './with-tooltip'const Switch = React.forwardRef<React.ComponentRef<typeof SwitchPrimitive.Root>,SwitchPrimitive.Root.Props & {size?: 'sm' | 'default'+ /** Disables the switch and says why in a tooltip. */+ disabledReason?: React.ReactNode}->(function Switch({ className, size = 'default', ...props }, ref) {- return (+>(function Switch({ className, size = 'default', disabled, disabledReason, ...props }, ref) {+ return withTooltip(<SwitchPrimitive.Rootref={ref}data-quilldata-slot="switch"data-size={size}+ disabled={disabled || hasTooltipContent(disabledReason)}className={cn('quill-switch peer group/switch inline-flex shrink-0 items-center', className)}{...props}><SwitchPrimitive.Thumb data-slot="switch-thumb" className="quill-switch__thumb" />- </SwitchPrimitive.Root>+ </SwitchPrimitive.Root>,+ disabledReason,+ { target: 'inline', focusable: hasTooltipContent(disabledReason) })})diff --git a/packages/quill/packages/primitives/src/with-tooltip.tsx b/packages/quill/packages/primitives/src/with-tooltip.tsxnew file mode 100644index 000000000000..fa1b32b723a0--- /dev/null+++ b/packages/quill/packages/primitives/src/with-tooltip.tsx@@ -0,0 +1,67 @@+import * as React from 'react'++import { Tooltip, TooltipContent, TooltipTrigger } from './tooltip'++/**+ * Where the tooltip listens for the pointer.+ * - `self`: the element is the trigger. Use it only for elements that stay hoverable when disabled,+ * such as `Button`, which keeps `focusableWhenDisabled` on.+ * - `block` / `inline`: a wrapper element is the trigger. Disabled menu items, checkboxes and switches+ * ignore the pointer, so the wrapper has to catch it for them.+ */+export type TooltipTarget = 'self' | 'block' | 'inline'++/** True when a `tooltip` or `disabledReason` prop has something to show. */+export function hasTooltipContent(content: React.ReactNode): boolean {+ return content !== undefined && content !== null && content !== false && content !== ''+}++/**+ * Internal helper behind the `tooltip` and `disabledReason` props of quill primitives.+ * Callers pass it unconditionally. Without content the tooltip is disabled rather than left out,+ * so the control keeps the same ancestors when a reason appears or clears and React does not+ * remount it, which would reset an uncontrolled Checkbox or Switch.+ */+export function withTooltip(+ element: React.ReactElement,+ content: React.ReactNode,+ {+ target,+ delay,+ side,+ focusable = false,+ }: {+ target: TooltipTarget+ delay?: number+ side?: React.ComponentProps<typeof TooltipContent>['side']+ /**+ * Puts a `block` or `inline` wrapper in the tab order. A disabled control leaves the tab+ * order, so the wrapper is the only way a keyboard user can open its reason.+ */+ focusable?: boolean+ }+): React.ReactElement {+ const hasContent = hasTooltipContent(content)+ const tabIndex = focusable && hasContent ? 0 : undefined+ return (+ <Tooltip disabled={!hasContent}>+ {target === 'self' ? (+ <TooltipTrigger render={element} delay={delay} />+ ) : (+ <TooltipTrigger+ delay={delay}+ render={+ target === 'block' ? (+ <div tabIndex={tabIndex} />+ ) : (+ <span className="inline-flex" tabIndex={tabIndex} />+ )+ }+ >+ {element}+ </TooltipTrigger>+ )}+ {hasContent && <TooltipContent side={side}>{content}</TooltipContent>}+ </Tooltip>+ )+}