@plexui/ui 0.58.0 → 0.59.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ import clsx from "clsx";
4
4
  import { useCallback, useEffect, useId, useRef, useState } from "react";
5
5
  import { mergeRefs } from "react-merge-refs";
6
6
  import { toCssVariables } from "../../lib/helpers.js";
7
- import { observeTextareaWidth } from "../../lib/observeTextareaWidth.js";
7
+ import { observeTextareaWidth, sizesByContent } from "../../lib/observeTextareaWidth.js";
8
8
  import {} from "../../types.js";
9
9
  import s from "@plexui/styles/components/Textarea/Textarea.module.css";
10
10
  export const Textarea = (props) => {
@@ -30,14 +30,14 @@ export const Textarea = (props) => {
30
30
  }
31
31
  };
32
32
  const autosizeTextarea = useCallback(() => {
33
- if (!autoResize || !textAreaRef.current || computedMaxRows === undefined)
33
+ if (!autoResize || !textAreaRef.current || computedMaxRows === undefined || sizesByContent())
34
34
  return;
35
35
  textAreaRef.current.style.height = "0px";
36
36
  const scrollHeight = textAreaRef.current.scrollHeight;
37
37
  textAreaRef.current.style.height = scrollHeight + "px";
38
38
  }, [autoResize, computedMaxRows]);
39
39
  useEffect(() => {
40
- if (!autoResize || !textAreaRef.current)
40
+ if (!autoResize || !textAreaRef.current || sizesByContent())
41
41
  return;
42
42
  return observeTextareaWidth(textAreaRef.current, autosizeTextarea);
43
43
  }, [autoResize, autosizeTextarea]);
@@ -1 +1 @@
1
- {"version":3,"file":"Textarea.js","sourceRoot":"","sources":["../../../../src/components/Textarea/Textarea.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAm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P,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { useCallback, useEffect, useId, useRef, useState } from \"react\"\nimport { mergeRefs } from \"react-merge-refs\"\nimport { toCssVariables } from \"../../lib/helpers\"\nimport { observeTextareaWidth } from \"../../lib/observeTextareaWidth\"\nimport { type ControlSize, type Sizes, type Variants } from \"../../types\"\nimport s from \"@plexui/styles/components/Textarea/Textarea.module.css\"\n\nexport type TextareaProps = {\n /**\n * Visual style of the textarea\n * @default outline\n */\n variant?: Variants<\"outline\" | \"soft\" | \"ghost\">\n /**\n * Controls the size of the textarea\n *\n * | 3xs | 2xs | xs | sm | md | lg | xl | 2xl | 3xl |\n * | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- |\n * | `22px` | `24px` | `26px` | `28px` | `32px` | `36px` | `40px` | `44px` | `48px` |\n *\n * @default md\n */\n size?: ControlSize\n /**\n * Applies a negative margin using the current gutter to optically align the text with surrounding content.\n */\n opticallyAlign?: \"start\" | \"end\"\n /**\n * Controls gutter on the edges of the textarea, defaults to value from `size`.\n *\n * | 2xs | xs | sm | md | lg | xl |\n * | ------ | ------ | ------ | ------ | ------ | ------ |\n * | `6px` | `8px` | `10px` | `12px` | `14px` | `16px` |\n */\n gutterSize?: Sizes<\"2xs\" | \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\">\n /**\n * Disables the textarea visually and from interactions\n * @default false\n */\n disabled?: boolean\n /**\n * Mark the textarea as invalid\n * @default false\n */\n invalid?: boolean\n /**\n * Allow autofill extensions to appear in the textarea\n * @default false\n */\n allowAutofillExtensions?: boolean\n /**\n * Select all contents of the textarea when mounted.\n * @default false\n */\n autoSelect?: boolean\n /** Callback invoked when the textarea is autofilled by the browser */\n onAutofill?: () => void\n /**\n * Default number of rows to display\n * @default 3\n */\n rows?: number\n /**\n * Automatically adjust the height of the textarea based on its contents.\n * @default false\n */\n autoResize?: boolean\n /**\n * Maximum number of rows that can be displayed when autoResize is enabled.\n * @default Math.max(rows, 10)\n */\n maxRows?: number\n /** Ref for the textarea */\n ref?: React.Ref<HTMLTextAreaElement | null>\n} & Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, \"disabled\" | \"size\">\n\nexport const Textarea = (props: TextareaProps) => {\n const textAreaRef = useRef<HTMLTextAreaElement | null>(null)\n const inputIdSuffix = useId()\n // Prevent 1Password from appearing: 1Password won't display if it thinks this field is for searching\n // Allow user to override this for connecting to labels.\n const onePasswordPreventionId = `search-ui-input-${inputIdSuffix}`\n const {\n id,\n name,\n variant = \"outline\",\n size = \"md\",\n opticallyAlign,\n gutterSize,\n className,\n autoComplete,\n disabled = false,\n readOnly = false,\n invalid = false,\n // Default to `true` when presence of `name`\n allowAutofillExtensions = !!name,\n onFocus,\n onBlur,\n onAnimationStart,\n onAutofill,\n autoSelect,\n rows = 3,\n maxRows,\n autoResize,\n ref,\n onChange,\n ...restProps\n } = props\n\n const [focused, setFocused] = useState<boolean>(false)\n const computedMaxRows = autoResize ? Math.max(maxRows ?? 10, rows) : rows\n\n useEffect(() => {\n if (autoSelect) {\n textAreaRef.current?.select()\n }\n }, [autoSelect])\n\n const handleAnimationStart = (evt: React.AnimationEvent<HTMLTextAreaElement>) => {\n onAnimationStart?.(evt)\n if (evt.animationName === \"native-autofill-in\") {\n onAutofill?.()\n }\n }\n\n const autosizeTextarea = useCallback(() => {\n if (!autoResize || !textAreaRef.current || computedMaxRows === undefined) return\n textAreaRef.current.style.height = \"0px\"\n const scrollHeight = textAreaRef.current.scrollHeight\n textAreaRef.current.style.height = scrollHeight + \"px\"\n }, [autoResize, computedMaxRows])\n\n useEffect(() => {\n if (!autoResize || !textAreaRef.current) return\n return observeTextareaWidth(textAreaRef.current, autosizeTextarea)\n }, [autoResize, autosizeTextarea])\n\n // Resize if value changes outside of user input - e.g. form reset\n useEffect(() => {\n autosizeTextarea()\n }, [props.value, rows, autosizeTextarea])\n\n return (\n <div\n className={clsx(s.Container, className)}\n data-slot=\"textarea\"\n data-variant={variant}\n data-size={size}\n data-optically-align={opticallyAlign}\n data-gutter-size={gutterSize}\n data-focused={focused}\n data-disabled={disabled ? \"\" : undefined}\n data-readonly={readOnly ? \"\" : undefined}\n data-invalid={invalid ? \"\" : undefined}\n data-auto-resize={autoResize ? \"\" : undefined}\n style={toCssVariables({\n \"textarea-min-rows\": `${rows}`,\n \"textarea-max-rows\": `${computedMaxRows}`,\n })}\n >\n <textarea\n {...restProps}\n onChange={(evt) => {\n onChange?.(evt)\n autosizeTextarea()\n }}\n ref={mergeRefs([textAreaRef, ref])}\n id={id || (allowAutofillExtensions ? undefined : onePasswordPreventionId)}\n className={s.Textarea}\n name={name}\n autoComplete={autoComplete}\n // Expose the visual invalid state to assistive tech; an explicit aria-invalid wins\n aria-invalid={restProps[\"aria-invalid\"] ?? (invalid || undefined)}\n readOnly={readOnly}\n disabled={disabled}\n rows={rows}\n onFocus={(evt) => {\n setFocused(true)\n onFocus?.(evt)\n }}\n onBlur={(evt) => {\n setFocused(false)\n onBlur?.(evt)\n }}\n onAnimationStart={handleAnimationStart}\n // Prevent LastPass and 1Password from appearing\n data-lpignore={allowAutofillExtensions ? undefined : true}\n data-1p-ignore={allowAutofillExtensions ? undefined : true}\n />\n </div>\n )\n}\n"]}
1
+ {"version":3,"file":"Textarea.js","sourceRoot":"","sources":["../../../../src/components/Textarea/Textarea.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AACrF,OAAO,EAA+C,MAAM,aAAa,CAAA;AACzE,OAA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, useEffect, useId, useRef, useState } from \"react\"\nimport { mergeRefs } from \"react-merge-refs\"\nimport { toCssVariables } from \"../../lib/helpers\"\nimport { observeTextareaWidth, sizesByContent } from \"../../lib/observeTextareaWidth\"\nimport { type ControlSize, type Sizes, type Variants } from \"../../types\"\nimport s from \"@plexui/styles/components/Textarea/Textarea.module.css\"\n\nexport type TextareaProps = {\n /**\n * Visual style of the textarea\n * @default outline\n */\n variant?: Variants<\"outline\" | \"soft\" | \"ghost\">\n /**\n * Controls the size of the textarea\n *\n * | 3xs | 2xs | xs | sm | md | lg | xl | 2xl | 3xl |\n * | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- |\n * | `22px` | `24px` | `26px` | `28px` | `32px` | `36px` | `40px` | `44px` | `48px` |\n *\n * @default md\n */\n size?: ControlSize\n /**\n * Applies a negative margin using the current gutter to optically align the text with surrounding content.\n */\n opticallyAlign?: \"start\" | \"end\"\n /**\n * Controls gutter on the edges of the textarea, defaults to value from `size`.\n *\n * | 2xs | xs | sm | md | lg | xl |\n * | ------ | ------ | ------ | ------ | ------ | ------ |\n * | `6px` | `8px` | `10px` | `12px` | `14px` | `16px` |\n */\n gutterSize?: Sizes<\"2xs\" | \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\">\n /**\n * Disables the textarea visually and from interactions\n * @default false\n */\n disabled?: boolean\n /**\n * Mark the textarea as invalid\n * @default false\n */\n invalid?: boolean\n /**\n * Allow autofill extensions to appear in the textarea\n * @default false\n */\n allowAutofillExtensions?: boolean\n /**\n * Select all contents of the textarea when mounted.\n * @default false\n */\n autoSelect?: boolean\n /** Callback invoked when the textarea is autofilled by the browser */\n onAutofill?: () => void\n /**\n * Default number of rows to display\n * @default 3\n */\n rows?: number\n /**\n * Automatically adjust the height of the textarea based on its contents.\n * @default false\n */\n autoResize?: boolean\n /**\n * Maximum number of rows that can be displayed when autoResize is enabled.\n * @default Math.max(rows, 10)\n */\n maxRows?: number\n /** Ref for the textarea */\n ref?: React.Ref<HTMLTextAreaElement | null>\n} & Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, \"disabled\" | \"size\">\n\nexport const Textarea = (props: TextareaProps) => {\n const textAreaRef = useRef<HTMLTextAreaElement | null>(null)\n const inputIdSuffix = useId()\n // Prevent 1Password from appearing: 1Password won't display if it thinks this field is for searching\n // Allow user to override this for connecting to labels.\n const onePasswordPreventionId = `search-ui-input-${inputIdSuffix}`\n const {\n id,\n name,\n variant = \"outline\",\n size = \"md\",\n opticallyAlign,\n gutterSize,\n className,\n autoComplete,\n disabled = false,\n readOnly = false,\n invalid = false,\n // Default to `true` when presence of `name`\n allowAutofillExtensions = !!name,\n onFocus,\n onBlur,\n onAnimationStart,\n onAutofill,\n autoSelect,\n rows = 3,\n maxRows,\n autoResize,\n ref,\n onChange,\n ...restProps\n } = props\n\n const [focused, setFocused] = useState<boolean>(false)\n const computedMaxRows = autoResize ? Math.max(maxRows ?? 10, rows) : rows\n\n useEffect(() => {\n if (autoSelect) {\n textAreaRef.current?.select()\n }\n }, [autoSelect])\n\n const handleAnimationStart = (evt: React.AnimationEvent<HTMLTextAreaElement>) => {\n onAnimationStart?.(evt)\n if (evt.animationName === \"native-autofill-in\") {\n onAutofill?.()\n }\n }\n\n const autosizeTextarea = useCallback(() => {\n if (!autoResize || !textAreaRef.current || computedMaxRows === undefined || sizesByContent()) return\n textAreaRef.current.style.height = \"0px\"\n const scrollHeight = textAreaRef.current.scrollHeight\n textAreaRef.current.style.height = scrollHeight + \"px\"\n }, [autoResize, computedMaxRows])\n\n useEffect(() => {\n if (!autoResize || !textAreaRef.current || sizesByContent()) return\n return observeTextareaWidth(textAreaRef.current, autosizeTextarea)\n }, [autoResize, autosizeTextarea])\n\n // Resize if value changes outside of user input - e.g. form reset\n useEffect(() => {\n autosizeTextarea()\n }, [props.value, rows, autosizeTextarea])\n\n return (\n <div\n className={clsx(s.Container, className)}\n data-slot=\"textarea\"\n data-variant={variant}\n data-size={size}\n data-optically-align={opticallyAlign}\n data-gutter-size={gutterSize}\n data-focused={focused}\n data-disabled={disabled ? \"\" : undefined}\n data-readonly={readOnly ? \"\" : undefined}\n data-invalid={invalid ? \"\" : undefined}\n data-auto-resize={autoResize ? \"\" : undefined}\n style={toCssVariables({\n \"textarea-min-rows\": `${rows}`,\n \"textarea-max-rows\": `${computedMaxRows}`,\n })}\n >\n <textarea\n {...restProps}\n onChange={(evt) => {\n onChange?.(evt)\n autosizeTextarea()\n }}\n ref={mergeRefs([textAreaRef, ref])}\n id={id || (allowAutofillExtensions ? undefined : onePasswordPreventionId)}\n className={s.Textarea}\n name={name}\n autoComplete={autoComplete}\n // Expose the visual invalid state to assistive tech; an explicit aria-invalid wins\n aria-invalid={restProps[\"aria-invalid\"] ?? (invalid || undefined)}\n readOnly={readOnly}\n disabled={disabled}\n rows={rows}\n onFocus={(evt) => {\n setFocused(true)\n onFocus?.(evt)\n }}\n onBlur={(evt) => {\n setFocused(false)\n onBlur?.(evt)\n }}\n onAnimationStart={handleAnimationStart}\n // Prevent LastPass and 1Password from appearing\n data-lpignore={allowAutofillExtensions ? undefined : true}\n data-1p-ignore={allowAutofillExtensions ? undefined : true}\n />\n </div>\n )\n}\n"]}
@@ -6,8 +6,11 @@ import { createContext, useContext, useRef, useState } from "react";
6
6
  import { useTimeout } from "usehooks-ts";
7
7
  import { useEscCloseStack } from "../../hooks/useEscCloseStack.js";
8
8
  import { preventDefaultHandler } from "../../lib/helpers.js";
9
- import { isHoverPointer } from "../../lib/inputMode.js";
9
+ import { isFocusVisible, isHoverPointer, notePointerInput, trackInputModality } from "../../lib/inputMode.js";
10
10
  import s from "@plexui/styles/components/Tooltip/Tooltip.module.css";
11
+ // A tooltip opens on a focus that shows its ring only (isFocusVisible): it follows the last input of the page
12
+ if (typeof document !== "undefined")
13
+ trackInputModality(document);
11
14
  export const Tooltip = (props) => {
12
15
  const { ref: forwardedRef, children, content, forceOpen = content === null ? false : undefined, maxWidth = 300, openDelay = 150, interactive = false, compact = false, preventUnintentionalClickToClose, align, alignOffset = 0, side, sideOffset = 5, gutterSize = "md", contentClassName, onPointerDown, onClick, ...restProps } = props;
13
16
  const [visible, setVisible] = useState(false);
@@ -71,6 +74,8 @@ export const Trigger = ({ children, asChild = true, onPointerMove, onPointerLeav
71
74
  const cancelledPointer = useRef(false);
72
75
  return (_jsx(RadixTooltip.Trigger, { asChild: asChild, ...restProps, ...(focusRecovery?.state && { "data-state": focusRecovery.state }), onPointerDown: (event) => {
73
76
  cancelledPointer.current = false;
77
+ // A trigger in another document (an iframe) tracks that document's input
78
+ notePointerInput(event.currentTarget.ownerDocument);
74
79
  onPointerDown?.(event);
75
80
  }, onPointerCancel: (event) => {
76
81
  // Radix only clears its pointer-down flag on pointerup. A cancelled
@@ -78,12 +83,18 @@ export const Trigger = ({ children, asChild = true, onPointerMove, onPointerLeav
78
83
  cancelledPointer.current = true;
79
84
  onPointerCancel?.(event);
80
85
  }, onFocus: (event) => {
86
+ trackInputModality(event.currentTarget.ownerDocument);
81
87
  onFocus?.(event);
82
88
  if (event.defaultPrevented)
83
89
  return;
84
90
  if (event.currentTarget.hasAttribute("data-menu-pointer-focus")) {
85
91
  event.preventDefault();
86
92
  }
93
+ else if (!isFocusVisible(event.currentTarget)) {
94
+ // A focus after a mouse press that a script moved here (a dialog closed with the mouse returns focus to its
95
+ // trigger) shows no ring, so no tooltip: it stayed open until the focus left
96
+ event.preventDefault();
97
+ }
87
98
  else if (cancelledPointer.current) {
88
99
  event.preventDefault();
89
100
  focusRecovery?.recover();
@@ -95,6 +106,7 @@ export const Trigger = ({ children, asChild = true, onPointerMove, onPointerLeav
95
106
  event.preventDefault();
96
107
  }
97
108
  }, onPointerMove: (event) => {
109
+ trackInputModality(event.currentTarget.ownerDocument);
98
110
  onPointerMove?.(event);
99
111
  if (!isHoverPointer(event))
100
112
  event.preventDefault();
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":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;gBAAE,KAAK,CAAC,cAAc,EAAE,CAAA;QACpD,CAAC,YAEA,QAAQ,GACY,CACxB,CAAA;AACH,CAAC,CAAA;AAED,2HAA2H;AAC3H,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAA0B,EAAE,EAAE;IAC7D,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAA;IAC1E,MAAM,WAAW,GAAG,OAAO,QAAQ,KAAK,QAAQ,CAAA;IAEhD,OAAO,CACL,KAAC,IAAI,CAAC,IAAI,IACR,GAAG,EAAE,GAAG,KACJ,SAAS,EACb,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,gBAAgB,EAAE,SAAS,CAAC,EAC9C,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,YAElC,WAAW,CAAC,CAAC,CAAC,yBAAO,QAAQ,GAAQ,CAAC,CAAC,CAAC,QAAQ,GACvC,CACb,CAAA;AACH,CAAC,CAAA;AAED,mEAAmE;AACnE,wDAAwD;AACxD,OAAO,CAAC,IAAI,GAAG,IAAI,CAAA;AACnB,OAAO,CAAC,OAAO,GAAG,OAAO,CAAA;AACzB,OAAO,CAAC,OAAO,GAAG,OAAO,CAAA;AACzB,iEAAiE;AACjE,sDAAsD;AACtD,mGAAmG;AACnG,OAAO,CAAC,gBAAgB,GAAG,gBAAgB,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { Tooltip as RadixTooltip, Slot } from \"radix-ui\"\nimport { createContext, useContext, useRef, useState, type MouseEventHandler, type PointerEventHandler } from \"react\"\nimport { useTimeout } from \"usehooks-ts\"\nimport { useEscCloseStack } from \"../../hooks/useEscCloseStack\"\nimport { preventDefaultHandler } from \"../../lib/helpers\"\nimport { isHoverPointer } from \"../../lib/inputMode\"\nimport s from \"@plexui/styles/components/Tooltip/Tooltip.module.css\"\n\nexport type TooltipProps = {\n children: React.ReactNode\n /**\n * The content of the tooltip. If `null`, the tooltip will not render.\n */\n content: React.ReactNode\n /**\n * Defines the `max-width` of the tooltip content. `\"none\"` creates a single-line, naturally sized tooltip.\n * @default 300\n */\n maxWidth?: number | \"none\"\n /**\n * Forces the tooltip to remain open or closed\n */\n forceOpen?: boolean\n /**\n * Delay of when the tooltip is shown from first interaction, in milliseconds.\n * @default 150\n */\n openDelay?: number\n /** Indicates that the tooltip has interactive content, and should remain open when hovered. */\n interactive?: boolean\n /**\n * Short, 1-3 word tooltips, stylized inversely from normal tooltips\n */\n compact?: boolean\n /**\n * Prevents the tooltip from closing when the trigger is clicked right after opening\n * @default false\n */\n preventUnintentionalClickToClose?: true\n /**\n * The preferred alignment against the trigger. May change when collisions occur.\n * @default center\n */\n align?: RadixTooltip.TooltipContentProps[\"align\"]\n /**\n * An offset in pixels from the \"start\" or \"end\" alignment options.\n * @default 0\n */\n alignOffset?: RadixTooltip.TooltipContentProps[\"alignOffset\"]\n /**\n * The preferred side of the trigger to render against when open. Will be reversed when collisions occur.\n * @default top\n */\n side?: RadixTooltip.TooltipContentProps[\"side\"]\n /**\n * The distance in pixels from the trigger.\n * @default 5\n */\n sideOffset?: RadixTooltip.TooltipContentProps[\"sideOffset\"]\n /**\n * Gutter sizing inside the tooltip content\n * @default md\n */\n gutterSize?: \"sm\" | \"md\" | \"lg\"\n /** Ref for the tooltip */\n ref?: React.Ref<HTMLDivElement | null>\n onPointerDown?: PointerEventHandler\n onClick?: MouseEventHandler\n /** Optional class name to apply to the tooltip content */\n contentClassName?: string\n}\n\nexport const Tooltip = (props: TooltipProps) => {\n const {\n ref: forwardedRef,\n children,\n content,\n forceOpen = content === null ? false : undefined,\n maxWidth = 300,\n openDelay = 150,\n interactive = false,\n compact = false,\n preventUnintentionalClickToClose,\n align,\n alignOffset = 0,\n side,\n sideOffset = 5,\n gutterSize = \"md\",\n contentClassName,\n onPointerDown,\n onClick,\n ...restProps\n } = props\n const [visible, setVisible] = useState<boolean>(false)\n const [temporarilyPreventClickToClose, setTemporarilyPreventClickToClose] =\n useState<boolean>(false)\n useTimeout(\n () => setTemporarilyPreventClickToClose(false),\n temporarilyPreventClickToClose ? 400 : null,\n )\n const open = forceOpen ?? visible\n\n const handleOpenChange = (nextState: boolean) => {\n // When forceOpen is passed, don't manage internal state\n if (typeof forceOpen === \"boolean\") return\n\n setVisible(nextState)\n\n if (preventUnintentionalClickToClose) {\n setTemporarilyPreventClickToClose(nextState)\n }\n }\n\n const maybePreventClickClose = (evt: React.MouseEvent) => {\n if (preventUnintentionalClickToClose && temporarilyPreventClickToClose) {\n // Prevents tooltip listeners from closing\n evt.preventDefault()\n evt.stopPropagation()\n }\n }\n\n return (\n <Root\n open={open}\n delayDuration={openDelay}\n onOpenChange={handleOpenChange}\n disableHoverableContent={!interactive}\n >\n <Trigger asChild>\n <Slot.Root\n {...restProps}\n ref={forwardedRef}\n onPointerDown={(evt) => {\n maybePreventClickClose(evt)\n onPointerDown?.(evt)\n }}\n onClick={(evt) => {\n maybePreventClickClose(evt)\n onClick?.(evt)\n }}\n >\n {children}\n </Slot.Root>\n </Trigger>\n <Content\n maxWidth={maxWidth}\n compact={compact}\n align={align}\n alignOffset={alignOffset}\n side={side}\n sideOffset={sideOffset}\n gutterSize={gutterSize}\n className={contentClassName}\n >\n {content}\n </Content>\n </Root>\n )\n}\n\nconst RecoverFocusContext = createContext<{\n recover: () => void\n state: \"instant-open\" | undefined\n} | undefined>(undefined)\n\nconst Root = ({\n children,\n open,\n onOpenChange,\n ...restProps\n}: RadixTooltip.TooltipProps & {\n open: boolean\n onOpenChange: (nextState: boolean) => void\n}) => {\n const [recoveredFocus, setRecoveredFocus] = useState(false)\n const handleOpenChange = (nextState: boolean) => {\n setRecoveredFocus(false)\n onOpenChange(nextState)\n }\n useEscCloseStack(open, () => handleOpenChange(false))\n\n return (\n <RadixTooltip.Provider>\n <RadixTooltip.Root open={open} onOpenChange={handleOpenChange} {...restProps}>\n <RecoverFocusContext.Provider value={{\n recover: () => {\n if (open) return\n // Match a keyboard open even if Radix retained its cancelled\n // pointer flag and a previous hover's delayed-open state.\n document.dispatchEvent(new CustomEvent(\"tooltip.open\"))\n setRecoveredFocus(true)\n onOpenChange(true)\n },\n state: open && recoveredFocus ? \"instant-open\" : undefined,\n }}>\n {children}\n </RecoverFocusContext.Provider>\n </RadixTooltip.Root>\n </RadixTooltip.Provider>\n )\n}\n\ntype TooltipContentProps = RadixTooltip.TooltipContentProps & {\n children: React.ReactNode\n /**\n * Defines the `max-width` of the tooltip content. `\"none\"` creates a single-line, naturally sized tooltip.\n * @default 300\n */\n maxWidth?: number | \"none\"\n /**\n * Short, 1-3 word tooltips, stylized inversely from normal tooltips\n */\n compact?: boolean\n /**\n * Gutter sizing inside the tooltip content\n * @default md\n */\n gutterSize?: \"sm\" | \"md\" | \"lg\"\n /** Determines if the tooltip content should respond to click events */\n clickable?: boolean\n}\n\nexport const Content = ({\n children,\n maxWidth = 300,\n compact = false,\n clickable = undefined,\n alignOffset = 0,\n sideOffset = 5,\n gutterSize = \"md\",\n className,\n style,\n ...restProps\n}: TooltipContentProps) => {\n const focusRecovery = useContext(RecoverFocusContext)\n return (\n <RadixTooltip.Portal>\n <RadixTooltip.Content\n {...restProps}\n {...(focusRecovery?.state && { \"data-state\": focusRecovery.state })}\n className={clsx(s.Tooltip, className)}\n data-compact={compact}\n data-clickable={clickable}\n data-gutter-size={gutterSize}\n alignOffset={alignOffset}\n sideOffset={sideOffset}\n collisionPadding={15}\n hideWhenDetached\n style={{\n ...style,\n maxWidth,\n }}\n onEscapeKeyDown={preventDefaultHandler}\n >\n {children}\n </RadixTooltip.Content>\n </RadixTooltip.Portal>\n )\n}\n\ntype TooltipTriggerProps = RadixTooltip.TooltipTriggerProps & {\n /**\n * Determines if `tabindex=0` is applied to the trigger\n * @default true\n */\n focusable?: boolean\n /**\n * Optional class name to apply to the trigger\n */\n className?: string\n /** Ref for the trigger */\n ref?: React.Ref<HTMLSpanElement | null>\n}\n\nexport const Trigger = ({\n children,\n asChild = true,\n onPointerMove,\n onPointerLeave,\n onPointerDown,\n onPointerCancel,\n onFocus,\n onBlur,\n ...restProps\n}: RadixTooltip.TooltipTriggerProps) => {\n const focusRecovery = useContext(RecoverFocusContext)\n const cancelledPointer = useRef(false)\n\n return (\n <RadixTooltip.Trigger\n asChild={asChild}\n {...restProps}\n {...(focusRecovery?.state && { \"data-state\": focusRecovery.state })}\n onPointerDown={(event) => {\n cancelledPointer.current = false\n onPointerDown?.(event)\n }}\n onPointerCancel={(event) => {\n // Radix only clears its pointer-down flag on pointerup. A cancelled\n // touch gesture has no pointerup, so recover the next keyboard focus.\n cancelledPointer.current = true\n onPointerCancel?.(event)\n }}\n onFocus={(event) => {\n onFocus?.(event)\n if (event.defaultPrevented) return\n if (event.currentTarget.hasAttribute(\"data-menu-pointer-focus\")) {\n event.preventDefault()\n } else if (cancelledPointer.current) {\n event.preventDefault()\n focusRecovery?.recover()\n }\n }}\n onBlur={(event) => {\n onBlur?.(event)\n // Clipboard fallback borrows focus synchronously, then restores it.\n if (event.relatedTarget instanceof Element && event.relatedTarget.hasAttribute(\"data-plex-clipboard-fallback\")) {\n event.preventDefault()\n }\n }}\n onPointerMove={(event) => {\n onPointerMove?.(event)\n if (!isHoverPointer(event)) event.preventDefault()\n }}\n onPointerLeave={(event) => {\n onPointerLeave?.(event)\n if (!isHoverPointer(event)) event.preventDefault()\n }}\n >\n {children}\n </RadixTooltip.Trigger>\n )\n}\n\n// Optional wrapper for tooltip trigger, if the visual content isn't already accessible or with built-in visual indications\nexport const TriggerDecorator = (props: TooltipTriggerProps) => {\n const { children, className, focusable = true, ref, ...restProps } = props\n const isPlainText = typeof children === \"string\"\n\n return (\n <Slot.Root\n ref={ref}\n {...restProps}\n className={clsx(s.TriggerDecorator, className)}\n tabIndex={focusable ? 0 : undefined}\n >\n {isPlainText ? <span>{children}</span> : children}\n </Slot.Root>\n )\n}\n\n// Building advanced tooltip behaviors can be achieved by using the\n// composed components, and wiring up bespoke behaviors.\nTooltip.Root = Root\nTooltip.Content = Content\nTooltip.Trigger = Trigger\n// Basic <Tooltip> usage can be done with the component directly,\n// without requiring controlled component composition.\n// <TriggerDecorator> is a helper component that creates an accessible trigger with a visual effect\nTooltip.TriggerDecorator = TriggerDecorator\n"]}
1
+ {"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAoD,MAAM,OAAO,CAAA;AACrH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC1G,OAAO,CAAC,MAAM,sDAAsD,CAAA;AAEpE,8GAA8G;AAC9G,IAAI,OAAO,QAAQ,KAAK,WAAW;IAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAA;AAkEjE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAmB,EAAE,EAAE;IAC7C,MAAM,EACJ,GAAG,EAAE,YAAY,EACjB,QAAQ,EACR,OAAO,EACP,SAAS,GAAG,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,EAChD,QAAQ,GAAG,GAAG,EACd,SAAS,GAAG,GAAG,EACf,WAAW,GAAG,KAAK,EACnB,OAAO,GAAG,KAAK,EACf,gCAAgC,EAChC,KAAK,EACL,WAAW,GAAG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AC,CAAC,CAAC,gBAAgB,EAAE,SAAS,CAAC,EAC9C,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,YAElC,WAAW,CAAC,CAAC,CAAC,yBAAO,QAAQ,GAAQ,CAAC,CAAC,CAAC,QAAQ,GACvC,CACb,CAAA;AACH,CAAC,CAAA;AAED,mEAAmE;AACnE,wDAAwD;AACxD,OAAO,CAAC,IAAI,GAAG,IAAI,CAAA;AACnB,OAAO,CAAC,OAAO,GAAG,OAAO,CAAA;AACzB,OAAO,CAAC,OAAO,GAAG,OAAO,CAAA;AACzB,iEAAiE;AACjE,sDAAsD;AACtD,mGAAmG;AACnG,OAAO,CAAC,gBAAgB,GAAG,gBAAgB,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { Tooltip as RadixTooltip, Slot } from \"radix-ui\"\nimport { createContext, useContext, useRef, useState, type MouseEventHandler, type PointerEventHandler } from \"react\"\nimport { useTimeout } from \"usehooks-ts\"\nimport { useEscCloseStack } from \"../../hooks/useEscCloseStack\"\nimport { preventDefaultHandler } from \"../../lib/helpers\"\nimport { isFocusVisible, isHoverPointer, notePointerInput, trackInputModality } from \"../../lib/inputMode\"\nimport s from \"@plexui/styles/components/Tooltip/Tooltip.module.css\"\n\n// A tooltip opens on a focus that shows its ring only (isFocusVisible): it follows the last input of the page\nif (typeof document !== \"undefined\") trackInputModality(document)\n\nexport type TooltipProps = {\n children: React.ReactNode\n /**\n * The content of the tooltip. If `null`, the tooltip will not render.\n */\n content: React.ReactNode\n /**\n * Defines the `max-width` of the tooltip content. `\"none\"` creates a single-line, naturally sized tooltip.\n * @default 300\n */\n maxWidth?: number | \"none\"\n /**\n * Forces the tooltip to remain open or closed\n */\n forceOpen?: boolean\n /**\n * Delay of when the tooltip is shown from first interaction, in milliseconds.\n * @default 150\n */\n openDelay?: number\n /** Indicates that the tooltip has interactive content, and should remain open when hovered. */\n interactive?: boolean\n /**\n * Short, 1-3 word tooltips, stylized inversely from normal tooltips\n */\n compact?: boolean\n /**\n * Prevents the tooltip from closing when the trigger is clicked right after opening\n * @default false\n */\n preventUnintentionalClickToClose?: true\n /**\n * The preferred alignment against the trigger. May change when collisions occur.\n * @default center\n */\n align?: RadixTooltip.TooltipContentProps[\"align\"]\n /**\n * An offset in pixels from the \"start\" or \"end\" alignment options.\n * @default 0\n */\n alignOffset?: RadixTooltip.TooltipContentProps[\"alignOffset\"]\n /**\n * The preferred side of the trigger to render against when open. Will be reversed when collisions occur.\n * @default top\n */\n side?: RadixTooltip.TooltipContentProps[\"side\"]\n /**\n * The distance in pixels from the trigger.\n * @default 5\n */\n sideOffset?: RadixTooltip.TooltipContentProps[\"sideOffset\"]\n /**\n * Gutter sizing inside the tooltip content\n * @default md\n */\n gutterSize?: \"sm\" | \"md\" | \"lg\"\n /** Ref for the tooltip */\n ref?: React.Ref<HTMLDivElement | null>\n onPointerDown?: PointerEventHandler\n onClick?: MouseEventHandler\n /** Optional class name to apply to the tooltip content */\n contentClassName?: string\n}\n\nexport const Tooltip = (props: TooltipProps) => {\n const {\n ref: forwardedRef,\n children,\n content,\n forceOpen = content === null ? false : undefined,\n maxWidth = 300,\n openDelay = 150,\n interactive = false,\n compact = false,\n preventUnintentionalClickToClose,\n align,\n alignOffset = 0,\n side,\n sideOffset = 5,\n gutterSize = \"md\",\n contentClassName,\n onPointerDown,\n onClick,\n ...restProps\n } = props\n const [visible, setVisible] = useState<boolean>(false)\n const [temporarilyPreventClickToClose, setTemporarilyPreventClickToClose] =\n useState<boolean>(false)\n useTimeout(\n () => setTemporarilyPreventClickToClose(false),\n temporarilyPreventClickToClose ? 400 : null,\n )\n const open = forceOpen ?? visible\n\n const handleOpenChange = (nextState: boolean) => {\n // When forceOpen is passed, don't manage internal state\n if (typeof forceOpen === \"boolean\") return\n\n setVisible(nextState)\n\n if (preventUnintentionalClickToClose) {\n setTemporarilyPreventClickToClose(nextState)\n }\n }\n\n const maybePreventClickClose = (evt: React.MouseEvent) => {\n if (preventUnintentionalClickToClose && temporarilyPreventClickToClose) {\n // Prevents tooltip listeners from closing\n evt.preventDefault()\n evt.stopPropagation()\n }\n }\n\n return (\n <Root\n open={open}\n delayDuration={openDelay}\n onOpenChange={handleOpenChange}\n disableHoverableContent={!interactive}\n >\n <Trigger asChild>\n <Slot.Root\n {...restProps}\n ref={forwardedRef}\n onPointerDown={(evt) => {\n maybePreventClickClose(evt)\n onPointerDown?.(evt)\n }}\n onClick={(evt) => {\n maybePreventClickClose(evt)\n onClick?.(evt)\n }}\n >\n {children}\n </Slot.Root>\n </Trigger>\n <Content\n maxWidth={maxWidth}\n compact={compact}\n align={align}\n alignOffset={alignOffset}\n side={side}\n sideOffset={sideOffset}\n gutterSize={gutterSize}\n className={contentClassName}\n >\n {content}\n </Content>\n </Root>\n )\n}\n\nconst RecoverFocusContext = createContext<{\n recover: () => void\n state: \"instant-open\" | undefined\n} | undefined>(undefined)\n\nconst Root = ({\n children,\n open,\n onOpenChange,\n ...restProps\n}: RadixTooltip.TooltipProps & {\n open: boolean\n onOpenChange: (nextState: boolean) => void\n}) => {\n const [recoveredFocus, setRecoveredFocus] = useState(false)\n const handleOpenChange = (nextState: boolean) => {\n setRecoveredFocus(false)\n onOpenChange(nextState)\n }\n useEscCloseStack(open, () => handleOpenChange(false))\n\n return (\n <RadixTooltip.Provider>\n <RadixTooltip.Root open={open} onOpenChange={handleOpenChange} {...restProps}>\n <RecoverFocusContext.Provider value={{\n recover: () => {\n if (open) return\n // Match a keyboard open even if Radix retained its cancelled\n // pointer flag and a previous hover's delayed-open state.\n document.dispatchEvent(new CustomEvent(\"tooltip.open\"))\n setRecoveredFocus(true)\n onOpenChange(true)\n },\n state: open && recoveredFocus ? \"instant-open\" : undefined,\n }}>\n {children}\n </RecoverFocusContext.Provider>\n </RadixTooltip.Root>\n </RadixTooltip.Provider>\n )\n}\n\ntype TooltipContentProps = RadixTooltip.TooltipContentProps & {\n children: React.ReactNode\n /**\n * Defines the `max-width` of the tooltip content. `\"none\"` creates a single-line, naturally sized tooltip.\n * @default 300\n */\n maxWidth?: number | \"none\"\n /**\n * Short, 1-3 word tooltips, stylized inversely from normal tooltips\n */\n compact?: boolean\n /**\n * Gutter sizing inside the tooltip content\n * @default md\n */\n gutterSize?: \"sm\" | \"md\" | \"lg\"\n /** Determines if the tooltip content should respond to click events */\n clickable?: boolean\n}\n\nexport const Content = ({\n children,\n maxWidth = 300,\n compact = false,\n clickable = undefined,\n alignOffset = 0,\n sideOffset = 5,\n gutterSize = \"md\",\n className,\n style,\n ...restProps\n}: TooltipContentProps) => {\n const focusRecovery = useContext(RecoverFocusContext)\n return (\n <RadixTooltip.Portal>\n <RadixTooltip.Content\n {...restProps}\n {...(focusRecovery?.state && { \"data-state\": focusRecovery.state })}\n className={clsx(s.Tooltip, className)}\n data-compact={compact}\n data-clickable={clickable}\n data-gutter-size={gutterSize}\n alignOffset={alignOffset}\n sideOffset={sideOffset}\n collisionPadding={15}\n hideWhenDetached\n style={{\n ...style,\n maxWidth,\n }}\n onEscapeKeyDown={preventDefaultHandler}\n >\n {children}\n </RadixTooltip.Content>\n </RadixTooltip.Portal>\n )\n}\n\ntype TooltipTriggerProps = RadixTooltip.TooltipTriggerProps & {\n /**\n * Determines if `tabindex=0` is applied to the trigger\n * @default true\n */\n focusable?: boolean\n /**\n * Optional class name to apply to the trigger\n */\n className?: string\n /** Ref for the trigger */\n ref?: React.Ref<HTMLSpanElement | null>\n}\n\nexport const Trigger = ({\n children,\n asChild = true,\n onPointerMove,\n onPointerLeave,\n onPointerDown,\n onPointerCancel,\n onFocus,\n onBlur,\n ...restProps\n}: RadixTooltip.TooltipTriggerProps) => {\n const focusRecovery = useContext(RecoverFocusContext)\n const cancelledPointer = useRef(false)\n\n return (\n <RadixTooltip.Trigger\n asChild={asChild}\n {...restProps}\n {...(focusRecovery?.state && { \"data-state\": focusRecovery.state })}\n onPointerDown={(event) => {\n cancelledPointer.current = false\n // A trigger in another document (an iframe) tracks that document's input\n notePointerInput(event.currentTarget.ownerDocument)\n onPointerDown?.(event)\n }}\n onPointerCancel={(event) => {\n // Radix only clears its pointer-down flag on pointerup. A cancelled\n // touch gesture has no pointerup, so recover the next keyboard focus.\n cancelledPointer.current = true\n onPointerCancel?.(event)\n }}\n onFocus={(event) => {\n trackInputModality(event.currentTarget.ownerDocument)\n onFocus?.(event)\n if (event.defaultPrevented) return\n if (event.currentTarget.hasAttribute(\"data-menu-pointer-focus\")) {\n event.preventDefault()\n } else if (!isFocusVisible(event.currentTarget)) {\n // A focus after a mouse press that a script moved here (a dialog closed with the mouse returns focus to its\n // trigger) shows no ring, so no tooltip: it stayed open until the focus left\n event.preventDefault()\n } else if (cancelledPointer.current) {\n event.preventDefault()\n focusRecovery?.recover()\n }\n }}\n onBlur={(event) => {\n onBlur?.(event)\n // Clipboard fallback borrows focus synchronously, then restores it.\n if (event.relatedTarget instanceof Element && event.relatedTarget.hasAttribute(\"data-plex-clipboard-fallback\")) {\n event.preventDefault()\n }\n }}\n onPointerMove={(event) => {\n trackInputModality(event.currentTarget.ownerDocument)\n onPointerMove?.(event)\n if (!isHoverPointer(event)) event.preventDefault()\n }}\n onPointerLeave={(event) => {\n onPointerLeave?.(event)\n if (!isHoverPointer(event)) event.preventDefault()\n }}\n >\n {children}\n </RadixTooltip.Trigger>\n )\n}\n\n// Optional wrapper for tooltip trigger, if the visual content isn't already accessible or with built-in visual indications\nexport const TriggerDecorator = (props: TooltipTriggerProps) => {\n const { children, className, focusable = true, ref, ...restProps } = props\n const isPlainText = typeof children === \"string\"\n\n return (\n <Slot.Root\n ref={ref}\n {...restProps}\n className={clsx(s.TriggerDecorator, className)}\n tabIndex={focusable ? 0 : undefined}\n >\n {isPlainText ? <span>{children}</span> : children}\n </Slot.Root>\n )\n}\n\n// Building advanced tooltip behaviors can be achieved by using the\n// composed components, and wiring up bespoke behaviors.\nTooltip.Root = Root\nTooltip.Content = Content\nTooltip.Trigger = Trigger\n// Basic <Tooltip> usage can be done with the component directly,\n// without requiring controlled component composition.\n// <TriggerDecorator> is a helper component that creates an accessible trigger with a visual effect\nTooltip.TriggerDecorator = TriggerDecorator\n"]}
@@ -6,4 +6,44 @@ export const isHoverPointer = (event) => {
6
6
  const doc = target instanceof Document ? target : target instanceof Node ? target.ownerDocument : null;
7
7
  return doc?.documentElement.dataset.input !== "touch";
8
8
  };
9
+ // The last input of each document: a pointer press or a key. A focus that follows a pointer press is one the press
10
+ // gave or a script moved after it (a dialog closed with the mouse returns focus to its trigger), and no focus ring
11
+ // shows for it; a key, Tab or an arrow, shows one.
12
+ const lastInput = new WeakMap();
13
+ const tracked = new WeakSet();
14
+ /** Starts tracking the last input of a document (once per document). */
15
+ export const trackInputModality = (doc) => {
16
+ if (!doc || tracked.has(doc))
17
+ return;
18
+ tracked.add(doc);
19
+ doc.addEventListener("pointerdown", () => lastInput.set(doc, "pointer"), { capture: true, passive: true });
20
+ doc.addEventListener("mousedown", () => lastInput.set(doc, "pointer"), { capture: true, passive: true });
21
+ // Any key counts, with a modifier too: a screen reader moves focus with its own keys (Control-Option-arrows), and
22
+ // a tooltip it misses is worse than one more after a shortcut
23
+ doc.addEventListener("keydown", () => lastInput.set(doc, "keyboard"), { capture: true, passive: true });
24
+ };
25
+ /**
26
+ * Notes a pointer press from the element's own handler: a document that starts being tracked during that press (the
27
+ * first touch on a trigger in an iframe) has already let it pass its capture phase.
28
+ */
29
+ export const notePointerInput = (doc) => {
30
+ if (!doc)
31
+ return;
32
+ trackInputModality(doc);
33
+ lastInput.set(doc, "pointer");
34
+ };
35
+ /**
36
+ * Whether a focus shows its ring, as the browser's :focus-visible: a focus after a key or with no input yet does, one
37
+ * a pointer press gave or a script moved after it does not. A tooltip opens on the first only.
38
+ */
39
+ export const isFocusVisible = (element) => {
40
+ try {
41
+ if (element.matches(":focus-visible"))
42
+ return true;
43
+ }
44
+ catch {
45
+ // A browser without the selector leaves it to the last input
46
+ }
47
+ return lastInput.get(element.ownerDocument) !== "pointer";
48
+ };
9
49
  //# sourceMappingURL=inputMode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"inputMode.js","sourceRoot":"","sources":["../../../src/lib/inputMode.ts"],"names":[],"mappings":"AAKA,0FAA0F;AAC1F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAwB,EAAW,EAAE;IAClE,IAAI,KAAK,CAAC,WAAW,KAAK,OAAO;QAAE,OAAO,KAAK,CAAA;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,aAAa,CAAA;IAClC,MAAM,GAAG,GAAG,MAAM,YAAY,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,YAAY,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAA;IACtG,OAAO,GAAG,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,KAAK,OAAO,CAAA;AACvD,CAAC,CAAA","sourcesContent":["type HoverPointerEvent = {\n pointerType: string\n currentTarget: EventTarget | null\n}\n\n/** Pointer hover is unavailable to touch input and explicitly touch-rendered surfaces. */\nexport const isHoverPointer = (event: HoverPointerEvent): boolean => {\n if (event.pointerType === \"touch\") return false\n const target = event.currentTarget\n const doc = target instanceof Document ? target : target instanceof Node ? target.ownerDocument : null\n return doc?.documentElement.dataset.input !== \"touch\"\n}\n"]}
1
+ {"version":3,"file":"inputMode.js","sourceRoot":"","sources":["../../../src/lib/inputMode.ts"],"names":[],"mappings":"AAKA,0FAA0F;AAC1F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAwB,EAAW,EAAE;IAClE,IAAI,KAAK,CAAC,WAAW,KAAK,OAAO;QAAE,OAAO,KAAK,CAAA;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,aAAa,CAAA;IAClC,MAAM,GAAG,GAAG,MAAM,YAAY,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,YAAY,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,aAA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CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;AAC/B,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAgB,EAAW,EAAE;IAC1D,IAAI,CAAC;QACH,IAAI,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC;YAAE,OAAO,IAAI,CAAA;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,6DAA6D;IAC/D,CAAC;IACD,OAAO,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,SAAS,CAAA;AAC3D,CAAC,CAAA","sourcesContent":["type HoverPointerEvent = {\n pointerType: string\n currentTarget: EventTarget | null\n}\n\n/** Pointer hover is unavailable to touch input and explicitly touch-rendered surfaces. */\nexport const isHoverPointer = (event: HoverPointerEvent): boolean => {\n if (event.pointerType === \"touch\") return false\n const target = event.currentTarget\n const doc = target instanceof Document ? target : target instanceof Node ? target.ownerDocument : null\n return doc?.documentElement.dataset.input !== \"touch\"\n}\n\n// The last input of each document: a pointer press or a key. A focus that follows a pointer press is one the press\n// gave or a script moved after it (a dialog closed with the mouse returns focus to its trigger), and no focus ring\n// shows for it; a key, Tab or an arrow, shows one.\nconst lastInput = new WeakMap<Document, \"pointer\" | \"keyboard\">()\nconst tracked = new WeakSet<Document>()\n\n/** Starts tracking the last input of a document (once per document). */\nexport const trackInputModality = (doc: Document | null | undefined): void => {\n if (!doc || tracked.has(doc)) return\n tracked.add(doc)\n doc.addEventListener(\"pointerdown\", () => lastInput.set(doc, \"pointer\"), { capture: true, passive: true })\n doc.addEventListener(\"mousedown\", () => lastInput.set(doc, \"pointer\"), { capture: true, passive: true })\n // Any key counts, with a modifier too: a screen reader moves focus with its own keys (Control-Option-arrows), and\n // a tooltip it misses is worse than one more after a shortcut\n doc.addEventListener(\"keydown\", () => lastInput.set(doc, \"keyboard\"), { capture: true, passive: true })\n}\n\n/**\n * Notes a pointer press from the element's own handler: a document that starts being tracked during that press (the\n * first touch on a trigger in an iframe) has already let it pass its capture phase.\n */\nexport const notePointerInput = (doc: Document | null | undefined): void => {\n if (!doc) return\n trackInputModality(doc)\n lastInput.set(doc, \"pointer\")\n}\n\n/**\n * Whether a focus shows its ring, as the browser's :focus-visible: a focus after a key or with no input yet does, one\n * a pointer press gave or a script moved after it does not. A tooltip opens on the first only.\n */\nexport const isFocusVisible = (element: Element): boolean => {\n try {\n if (element.matches(\":focus-visible\")) return true\n } catch {\n // A browser without the selector leaves it to the last input\n }\n return lastInput.get(element.ownerDocument) !== \"pointer\"\n}\n"]}
@@ -46,4 +46,10 @@ export const observeTextareaWidth = (element, resize) => {
46
46
  view?.removeEventListener("resize", onResize);
47
47
  };
48
48
  };
49
+ /**
50
+ * Whether the browser sizes an auto-resizing textarea itself (`field-sizing: content`, Safari 26+, Chrome 123+): then
51
+ * the style sheet holds it between its rows and maximum rows, and no script measures it. Measuring set the height to
52
+ * 0 and read scrollHeight, a forced layout on mount of every such textarea.
53
+ */
54
+ export const sizesByContent = () => typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("field-sizing", "content");
49
55
  //# sourceMappingURL=observeTextareaWidth.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"observeTextareaWidth.js","sourceRoot":"","sources":["../../../src/lib/observeTextareaWidth.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,OAAoB,EAAE,MAAkB,EAAgB,EAAE;IAC7F,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,WAAW,CAAA;IAC9C,IAAI,MAAM,GAAG,IAAI,CAAA;IACjB,IAAI,KAAyB,CAAA;IAC7B,IAAI,aAAiC,CAAA;IAErC,IAAI,OAAO,cAAc,KAAK,WAAW,EAAE,CAAC;QAC1C,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,C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;QACd,IAAI,EAAE,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAC/C,CAAC,CAAA;AACH,CAAC,CAAA","sourcesContent":["/** Observe width only; autosizing height must not feed back into the observer. */\nexport const observeTextareaWidth = (element: HTMLElement, resize: () => void): (() => void) => {\n const view = element.ownerDocument.defaultView\n let active = true\n let frame: number | undefined\n let previousWidth: number | undefined\n\n if (typeof ResizeObserver !== \"undefined\") {\n const observer = new ResizeObserver((entries) => {\n const entry = entries.find(({ target }) => target === element)\n if (!active || !entry || entry.contentRect.width === previousWidth) return\n previousWidth = entry.contentRect.width\n if (frame !== undefined) return\n // Write height outside ResizeObserver delivery to avoid a resize loop.\n if (view) {\n frame = view.requestAnimationFrame(() => {\n frame = undefined\n if (active) resize()\n })\n } else {\n resize()\n }\n })\n observer.observe(element)\n return () => {\n active = false\n observer.disconnect()\n if (frame !== undefined) view?.cancelAnimationFrame(frame)\n }\n }\n\n previousWidth = element.getBoundingClientRect().width\n const onResize = () => {\n const width = element.getBoundingClientRect().width\n if (!active || width === previousWidth) return\n previousWidth = width\n resize()\n }\n view?.addEventListener(\"resize\", onResize)\n return () => {\n active = false\n view?.removeEventListener(\"resize\", onResize)\n }\n}\n"]}
1
+ {"version":3,"file":"observeTextareaWidth.js","sourceRoot":"","sources":["../../../src/lib/observeTextareaWidth.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,OAAoB,EAAE,MAAkB,EAAgB,EAAE;IAC7F,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,WAAW,CAAA;IAC9C,IAAI,MAAM,GAAG,IAAI,CAAA;IACjB,IAAI,KAAyB,CAAA;IAC7B,IAAI,aAAiC,CAAA;IAErC,IAAI,OAAO,cAAc,KAAK,WAAW,EAAE,CAAC;QAC1C,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9C,MAAM,KAAK,G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,MAAM,GAAG,KAAK,CAAA;QACd,IAAI,EAAE,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAC/C,CAAC,CAAA;AACH,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAY,EAAE,CAC1C,OAAO,GAAG,KAAK,WAAW,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,UAAU,IAAI,GAAG,CAAC,QAAQ,CAAC,cAAc,EAAE,SAAS,CAAC,CAAA","sourcesContent":["/** Observe width only; autosizing height must not feed back into the observer. */\nexport const observeTextareaWidth = (element: HTMLElement, resize: () => void): (() => void) => {\n const view = element.ownerDocument.defaultView\n let active = true\n let frame: number | undefined\n let previousWidth: number | undefined\n\n if (typeof ResizeObserver !== \"undefined\") {\n const observer = new ResizeObserver((entries) => {\n const entry = entries.find(({ target }) => target === element)\n if (!active || !entry || entry.contentRect.width === previousWidth) return\n previousWidth = entry.contentRect.width\n if (frame !== undefined) return\n // Write height outside ResizeObserver delivery to avoid a resize loop.\n if (view) {\n frame = view.requestAnimationFrame(() => {\n frame = undefined\n if (active) resize()\n })\n } else {\n resize()\n }\n })\n observer.observe(element)\n return () => {\n active = false\n observer.disconnect()\n if (frame !== undefined) view?.cancelAnimationFrame(frame)\n }\n }\n\n previousWidth = element.getBoundingClientRect().width\n const onResize = () => {\n const width = element.getBoundingClientRect().width\n if (!active || width === previousWidth) return\n previousWidth = width\n resize()\n }\n view?.addEventListener(\"resize\", onResize)\n return () => {\n active = false\n view?.removeEventListener(\"resize\", onResize)\n }\n}\n\n/**\n * Whether the browser sizes an auto-resizing textarea itself (`field-sizing: content`, Safari 26+, Chrome 123+): then\n * the style sheet holds it between its rows and maximum rows, and no script measures it. Measuring set the height to\n * 0 and read scrollHeight, a forced layout on mount of every such textarea.\n */\nexport const sizesByContent = (): boolean =>\n typeof CSS !== \"undefined\" && typeof CSS.supports === \"function\" && CSS.supports(\"field-sizing\", \"content\")\n"]}
@@ -118,6 +118,12 @@ export type SelectProps<T extends Option> = (SingleSelectProps<T> | MultiSelectP
118
118
  * @default false, or true at the end of a `Field row`
119
119
  */
120
120
  pill?: boolean;
121
+ /**
122
+ * The list in the rounder shape of a pill menu (as `Menu.Content pill`), whatever the trigger: a custom `trigger` or a
123
+ * rounded field can open the same list as a pill one
124
+ * @default the trigger's `pill`
125
+ */
126
+ listPill?: boolean;
121
127
  /**
122
128
  * Text of a `multiple` trigger when every option is selected
123
129
  * @default All selected
@@ -4,4 +4,16 @@ type HoverPointerEvent = {
4
4
  };
5
5
  /** Pointer hover is unavailable to touch input and explicitly touch-rendered surfaces. */
6
6
  export declare const isHoverPointer: (event: HoverPointerEvent) => boolean;
7
+ /** Starts tracking the last input of a document (once per document). */
8
+ export declare const trackInputModality: (doc: Document | null | undefined) => void;
9
+ /**
10
+ * Notes a pointer press from the element's own handler: a document that starts being tracked during that press (the
11
+ * first touch on a trigger in an iframe) has already let it pass its capture phase.
12
+ */
13
+ export declare const notePointerInput: (doc: Document | null | undefined) => void;
14
+ /**
15
+ * Whether a focus shows its ring, as the browser's :focus-visible: a focus after a key or with no input yet does, one
16
+ * a pointer press gave or a script moved after it does not. A tooltip opens on the first only.
17
+ */
18
+ export declare const isFocusVisible: (element: Element) => boolean;
7
19
  export {};
@@ -1,2 +1,8 @@
1
1
  /** Observe width only; autosizing height must not feed back into the observer. */
2
2
  export declare const observeTextareaWidth: (element: HTMLElement, resize: () => void) => (() => void);
3
+ /**
4
+ * Whether the browser sizes an auto-resizing textarea itself (`field-sizing: content`, Safari 26+, Chrome 123+): then
5
+ * the style sheet holds it between its rows and maximum rows, and no script measures it. Measuring set the height to
6
+ * 0 and read scrollHeight, a forced layout on mount of every such textarea.
7
+ */
8
+ export declare const sizesByContent: () => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexui/ui",
3
- "version": "0.58.0",
3
+ "version": "0.59.1",
4
4
  "description": "Modern design system for building high-quality applications",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -99,7 +99,7 @@
99
99
  "@maskito/core": "^5.2.2",
100
100
  "@maskito/kit": "^5.2.2",
101
101
  "@maskito/react": "^5.2.2",
102
- "@plexui/styles": "^0.16.0",
102
+ "@plexui/styles": "^0.16.1",
103
103
  "@radix-ui/react-dismissable-layer": "1.2.1",
104
104
  "@radix-ui/react-focus-guards": "1.2.0",
105
105
  "@radix-ui/react-focus-scope": "1.3.1",