@lumx/react 4.30.0-next.3 → 4.30.0-next.5
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.
- package/_internal/{CcLi-Wuu.js → Dx4QtHFB.js} +52 -3
- package/_internal/Dx4QtHFB.js.map +1 -0
- package/index.d.ts +12 -5
- package/index.js +139 -143
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/utils/index.d.ts +14 -1
- package/utils/index.js +1 -1
- package/_internal/CcLi-Wuu.js.map +0 -1
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import React__default, { useContext, useEffect, useMemo, useRef, createContext } from 'react';
|
|
1
|
+
import React__default, { useContext, useEffect, useMemo, useRef, createContext, useCallback } from 'react';
|
|
2
2
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
|
+
import { VISUALLY_HIDDEN } from '@lumx/core/js/constants';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Visually hidden class name.
|
|
8
|
+
* Used to hide elements from view but keep them readable from screen readers
|
|
9
|
+
*/
|
|
10
|
+
const visuallyHidden = () => VISUALLY_HIDDEN;
|
|
4
11
|
|
|
5
12
|
const DisabledStateContext = /*#__PURE__*/React__default.createContext({
|
|
6
13
|
state: null
|
|
@@ -26,6 +33,31 @@ function useDisabledStateContext() {
|
|
|
26
33
|
return useContext(DisabledStateContext);
|
|
27
34
|
}
|
|
28
35
|
|
|
36
|
+
const DEFAULT_VALUE = {};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Tooltip react context simply used as a marker to know when parent react node have a tooltip
|
|
40
|
+
*/
|
|
41
|
+
const TooltipContext = /*#__PURE__*/React__default.createContext(undefined);
|
|
42
|
+
const TooltipContextProvider = ({
|
|
43
|
+
children
|
|
44
|
+
}) => /*#__PURE__*/jsx(TooltipContext.Provider, {
|
|
45
|
+
value: DEFAULT_VALUE,
|
|
46
|
+
children: children
|
|
47
|
+
});
|
|
48
|
+
const useTooltipContext = () => React__default.useContext(TooltipContext);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the text of an element when it overflows, else `undefined`.
|
|
52
|
+
*/
|
|
53
|
+
const getOverflowingText = element => {
|
|
54
|
+
// A visually hidden element measures 1px, so it would count as overflowing.
|
|
55
|
+
if (!element || element.closest(`.${visuallyHidden()}`)) return undefined;
|
|
56
|
+
// A hidden element measures 0, so it would count as overflowing.
|
|
57
|
+
if (element.offsetWidth === 0 || element.offsetWidth >= element.scrollWidth) return undefined;
|
|
58
|
+
return element.innerText;
|
|
59
|
+
};
|
|
60
|
+
|
|
29
61
|
/**
|
|
30
62
|
* Shared types and logic for ClickAway detection.
|
|
31
63
|
*
|
|
@@ -261,5 +293,22 @@ const Portal = ({
|
|
|
261
293
|
return /*#__PURE__*/createPortal(children, container);
|
|
262
294
|
};
|
|
263
295
|
|
|
264
|
-
|
|
265
|
-
|
|
296
|
+
/**
|
|
297
|
+
* Get a function tooltip label that gives the text of the label element only when it overflows.
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* const { labelRef, tooltipLabel } = useOverflowTooltipLabel();
|
|
301
|
+
* <Tooltip label={tooltipLabel}><Text ref={labelRef} truncate>{text}</Text></Tooltip>
|
|
302
|
+
*/
|
|
303
|
+
const useOverflowTooltipLabel = () => {
|
|
304
|
+
const parentTooltip = useTooltipContext();
|
|
305
|
+
const labelRef = useRef(null);
|
|
306
|
+
const tooltipLabel = useCallback(() => parentTooltip ? undefined : getOverflowingText(labelRef.current), [parentTooltip]);
|
|
307
|
+
return {
|
|
308
|
+
labelRef,
|
|
309
|
+
tooltipLabel
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
export { ClickAwayProvider as C, DisabledStateProvider as D, InfiniteScroll as I, Portal as P, TooltipContextProvider as T, useTooltipContext as a, useOverflowTooltipLabel as b, PortalProvider as c, getOverflowingText as g, useDisabledStateContext as u, visuallyHidden as v };
|
|
314
|
+
//# sourceMappingURL=Dx4QtHFB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dx4QtHFB.js","sources":["../../../lumx-core/src/js/utils/classNames/visually-hidden/index.ts","../../src/utils/disabled/DisabledStateContext.tsx","../../src/components/tooltip/context.tsx","../../../lumx-core/src/js/utils/browser/getOverflowingText.ts","../../../lumx-core/src/js/utils/ClickAway/index.ts","../../src/hooks/useClickAway.tsx","../../src/utils/ClickAwayProvider/ClickAwayProvider.tsx","../../../lumx-core/src/js/utils/InfiniteScroll/setupInfiniteScrollObserver.ts","../../../lumx-core/src/js/utils/InfiniteScroll/index.tsx","../../src/utils/InfiniteScroll/InfiniteScroll.tsx","../../src/utils/Portal/PortalProvider.tsx","../../src/utils/Portal/Portal.tsx","../../src/hooks/useOverflowTooltipLabel.tsx"],"sourcesContent":["import { VISUALLY_HIDDEN } from '@lumx/core/js/constants';\n\n/**\n * Visually hidden class name.\n * Used to hide elements from view but keep them readable from screen readers\n */\nexport const visuallyHidden = () => VISUALLY_HIDDEN;\n","import React, { useContext } from 'react';\n\nimport { DisabledStateContextValue } from '@lumx/core/js/utils/disabledState';\n\nexport const DisabledStateContext = React.createContext<DisabledStateContextValue>({ state: null });\n\nexport type DisabledStateProviderProps = DisabledStateContextValue & {\n children: React.ReactNode;\n};\n\n/**\n * Disabled state provider.\n * All nested LumX Design System components inherit this disabled state.\n */\nexport function DisabledStateProvider({ children, ...value }: DisabledStateProviderProps) {\n return <DisabledStateContext.Provider value={value}>{children}</DisabledStateContext.Provider>;\n}\n\n/**\n * Get DisabledState context value\n */\nexport function useDisabledStateContext(): DisabledStateContextValue {\n return useContext(DisabledStateContext);\n}\n","import React from 'react';\n\n/** Empty object */\ntype TooltipContextValue = NonNullable<unknown>;\n\nconst DEFAULT_VALUE = {};\n\n/**\n * Tooltip react context simply used as a marker to know when parent react node have a tooltip\n */\nconst TooltipContext = React.createContext<TooltipContextValue | undefined>(undefined);\n\nexport const TooltipContextProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) => (\n <TooltipContext.Provider value={DEFAULT_VALUE}>{children}</TooltipContext.Provider>\n);\n\nexport const useTooltipContext = () => React.useContext(TooltipContext);\n","import { visuallyHidden } from '../classNames/visually-hidden';\n\n/**\n * Get the text of an element when it overflows, else `undefined`.\n */\nexport const getOverflowingText = (element?: HTMLElement | null): string | undefined => {\n // A visually hidden element measures 1px, so it would count as overflowing.\n if (!element || element.closest(`.${visuallyHidden()}`)) return undefined;\n // A hidden element measures 0, so it would count as overflowing.\n if (element.offsetWidth === 0 || element.offsetWidth >= element.scrollWidth) return undefined;\n return element.innerText;\n};\n","/**\n * Shared types and logic for ClickAway detection.\n *\n * ClickAway detects clicks outside a set of elements and triggers a callback.\n * The core logic (event listening + target checking) is framework-agnostic.\n * Framework-specific wrappers (React hook, Vue composable) and context providers\n * (React context, Vue provide/inject) are implemented in each framework package.\n */\n\nimport type { Falsy } from '@lumx/core/js/types';\n\n/** Event types that trigger click away detection. */\nexport const CLICK_AWAY_EVENT_TYPES = ['mousedown', 'touchstart'] as const;\n\n/** Callback triggered when a click away is detected. */\nexport type ClickAwayCallback = EventListener | Falsy;\n\n/**\n * Check if the click event targets are outside all the given elements.\n *\n * @param targets - The event target elements (from `event.target` and `event.composedPath()`).\n * @param elements - The elements considered \"inside\" the click away context.\n * @returns `true` if the click is outside all elements (i.e. a click away).\n */\nexport function isClickAway(targets: HTMLElement[], elements: HTMLElement[]): boolean {\n return !elements.some((element) => element instanceof Node && targets.some((target) => element.contains(target)));\n}\n\n/**\n * Imperative setup for click away detection.\n * Adds mousedown/touchstart listeners on `document` and calls the callback when a click\n * occurs outside the elements returned by `getElements`.\n *\n * Note: when `getElements` returns an empty array, any click is considered a click away.\n * Callers should guard against calling `setupClickAway` when no refs are registered.\n *\n * @param getElements - Getter returning the current list of elements considered \"inside\".\n * @param callback - Callback to invoke on click away.\n * @returns A teardown function that removes the event listeners.\n */\nexport function setupClickAway(\n getElements: () => HTMLElement[],\n callback: ClickAwayCallback,\n): (() => void) | undefined {\n if (!callback) {\n return undefined;\n }\n\n const listener: EventListener = (evt) => {\n const targets = [evt.composedPath?.()[0], evt.target].filter((t): t is HTMLElement => t instanceof Node);\n const elements = getElements();\n if (isClickAway(targets, elements)) {\n callback(evt);\n }\n };\n\n CLICK_AWAY_EVENT_TYPES.forEach((evtType) => document.addEventListener(evtType, listener));\n return () => {\n CLICK_AWAY_EVENT_TYPES.forEach((evtType) => document.removeEventListener(evtType, listener));\n };\n}\n","import { RefObject, useEffect } from 'react';\n\nimport type { Falsy } from '@lumx/core/js/types';\nimport { setupClickAway } from '@lumx/core/js/utils/ClickAway';\n\nexport interface ClickAwayParameters {\n /**\n * A callback function to call when the user clicks away from the elements.\n */\n callback: EventListener | Falsy;\n /**\n * Elements considered within the click away context (clicking outside them will trigger the click away callback).\n */\n childrenRefs: RefObject<Array<RefObject<HTMLElement>>>;\n}\n\n/**\n * Listen to clicks away from the given elements and callback the passed in function.\n *\n * Warning: If you need to detect click away on nested React portals, please use the `ClickAwayProvider` component.\n */\nexport function useClickAway({ callback, childrenRefs }: ClickAwayParameters): void {\n useEffect(() => {\n const getElements = () => {\n const refs = childrenRefs.current;\n if (!refs) return [];\n return refs.map((ref) => ref?.current).filter(Boolean) as HTMLElement[];\n };\n return setupClickAway(getElements, callback);\n }, [callback, childrenRefs]);\n}\n","import { createContext, RefObject, useContext, useEffect, useMemo, useRef } from 'react';\nimport { ClickAwayParameters, useClickAway } from '@lumx/react/hooks/useClickAway';\n\ninterface ContextValue {\n childrenRefs: Array<RefObject<HTMLElement>>;\n addRefs(...newChildrenRefs: Array<RefObject<HTMLElement>>): void;\n}\n\nconst ClickAwayAncestorContext = createContext<ContextValue | null>(null);\n\ninterface ClickAwayProviderProps extends ClickAwayParameters {\n /**\n * (Optional) Element that should be considered as part of the parent\n */\n parentRef?: RefObject<HTMLElement>;\n /**\n * Children\n */\n children?: React.ReactNode;\n}\n\n/**\n * Component combining the `useClickAway` hook with a React context to hook into the React component tree and make sure\n * we take into account both the DOM tree and the React tree to detect click away.\n *\n * @return the react component.\n */\nexport const ClickAwayProvider: React.FC<ClickAwayProviderProps> = ({\n children,\n callback,\n childrenRefs,\n parentRef,\n}) => {\n const parentContext = useContext(ClickAwayAncestorContext);\n const currentContext = useMemo(() => {\n const context: ContextValue = {\n childrenRefs: [],\n /**\n * Add element refs to the current context and propagate to the parent context.\n */\n addRefs(...newChildrenRefs) {\n // Add element refs that should be considered as inside the click away context.\n context.childrenRefs.push(...newChildrenRefs);\n\n if (parentContext) {\n // Also add then to the parent context\n parentContext.addRefs(...newChildrenRefs);\n if (parentRef) {\n // The parent element is also considered as inside the parent click away context but not inside the current context\n parentContext.addRefs(parentRef);\n }\n }\n },\n };\n return context;\n }, [parentContext, parentRef]);\n\n useEffect(() => {\n const { current: currentRefs } = childrenRefs;\n if (!currentRefs) {\n return;\n }\n currentContext.addRefs(...currentRefs);\n }, [currentContext, childrenRefs]);\n\n useClickAway({ callback, childrenRefs: useRef(currentContext.childrenRefs) });\n return <ClickAwayAncestorContext.Provider value={currentContext}>{children}</ClickAwayAncestorContext.Provider>;\n};\nClickAwayProvider.displayName = 'ClickAwayProvider';\n","type EventCallback = (evt?: Event) => void;\n\n/**\n * Sets up an IntersectionObserver on the given element.\n * Calls `callback` when at least one observed entry is intersecting.\n * Returns a cleanup function that unobserves the element.\n */\nexport function setupInfiniteScrollObserver(\n element: Element,\n callback: EventCallback,\n options?: IntersectionObserverInit,\n): () => void {\n const observer = new IntersectionObserver((entries = []) => {\n const hasIntersection = entries.some((entry) => entry.isIntersecting);\n\n if (!hasIntersection) {\n return;\n }\n\n callback();\n }, options);\n\n observer.observe(element);\n\n return () => {\n observer.unobserve(element);\n };\n}\n","import type { CommonRef } from '../../types';\n\nexport { setupInfiniteScrollObserver } from './setupInfiniteScrollObserver';\n\nexport const INFINITE_SCROLL_CLASSNAME = 'lumx-infinite-scroll-anchor';\n\nexport interface InfiniteScrollProps {\n /**\n * Callback when infinite scroll component is in view.\n * Omit (e.g. while loading) to temporarily disable without changing the callback's\n * identity when re-enabled — keeps the underlying observer stable.\n */\n // eslint-disable-next-line react/no-unused-prop-types\n callback?(evt?: Event): void;\n /** Customize intersection observer option */\n // eslint-disable-next-line react/no-unused-prop-types\n options?: IntersectionObserverInit;\n}\n\n/**\n * Framework-agnostic InfiniteScroll sentinel component.\n *\n * Renders a tiny invisible div that triggers a callback when it enters the viewport\n * (or intersects its root element) via IntersectionObserver.\n *\n * The div has a small height (4px) to avoid issues when a browser zoom is applied,\n * where a zero-height element might not trigger IntersectionObserver reliably.\n */\nexport const InfiniteScroll = ({ ref }: { ref?: CommonRef }) => (\n // In order to avoid issues when a zoom is added to the browser, we add a small height to the div so that\n // the intersection has a higher chance of working correctly.\n <div ref={ref} aria-hidden=\"true\" className={INFINITE_SCROLL_CLASSNAME} style={{ height: '4px' }} />\n);\n","import React, { useEffect } from 'react';\nimport {\n InfiniteScroll as UI,\n type InfiniteScrollProps,\n setupInfiniteScrollObserver,\n} from '@lumx/core/js/utils/InfiniteScroll';\n\nexport type { InfiniteScrollProps };\n\n/**\n * Handles basic callback pattern by using intersection observers.\n */\nexport const InfiniteScroll: React.FC<InfiniteScrollProps> = ({ callback, options }) => {\n const elementRef = React.useRef<HTMLDivElement | null>(null);\n\n useEffect(() => {\n const { current: element } = elementRef;\n if (!element || !callback) {\n return undefined;\n }\n\n return setupInfiniteScrollObserver(element, callback, options);\n // `options?.root` starts as `null` (before the scrollable list's ref attaches) and is\n // then set to the real element — must be a dep, or the observer gets stuck watching\n // the wrong root (falling back to the viewport) for the component's whole lifetime.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [elementRef.current, callback, options?.root]);\n\n return UI({ ref: elementRef });\n};\n","import React from 'react';\nimport type { PortalInit } from '@lumx/core/js/utils/Portal';\n\nexport type { PortalInit, PortalProviderProps } from '@lumx/core/js/utils/Portal';\n\nexport const PortalContext = React.createContext<PortalInit>(() => ({ container: document.body }));\n\nexport interface ReactPortalProviderProps {\n children?: React.ReactNode;\n value: PortalInit;\n}\n\n/**\n * Customize where <Portal> wrapped elements render (tooltip, popover, dialog, etc.)\n */\nexport const PortalProvider: React.FC<ReactPortalProviderProps> = PortalContext.Provider;\n","import React from 'react';\nimport { createPortal } from 'react-dom';\nimport { PortalContext } from './PortalProvider';\n\nexport type { PortalProps } from '@lumx/core/js/utils/Portal';\n\nexport interface ReactPortalProps {\n enabled?: boolean;\n children: React.ReactNode;\n}\n\n/**\n * Render children in a portal outside the current DOM position\n * (defaults to `document.body` but can be customized with the PortalContextProvider)\n */\nexport const Portal: React.FC<ReactPortalProps> = ({ children, enabled = true }) => {\n const init = React.useContext(PortalContext);\n const context = React.useMemo(\n () => {\n return enabled ? init() : null;\n },\n // Only update on 'enabled'\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [enabled],\n );\n\n React.useLayoutEffect(() => {\n return context?.teardown;\n }, [context?.teardown, enabled]);\n\n const { container } = context ?? {};\n if (!container || typeof container === 'string') {\n return <>{children}</>;\n }\n return createPortal(children, container);\n};\n","import { useCallback, useRef } from 'react';\nimport { useTooltipContext } from '@lumx/react/components/tooltip/context';\nimport { getOverflowingText } from '@lumx/core/js/utils/browser/getOverflowingText';\n\n/**\n * Get a function tooltip label that gives the text of the label element only when it overflows.\n *\n * @example\n * const { labelRef, tooltipLabel } = useOverflowTooltipLabel();\n * <Tooltip label={tooltipLabel}><Text ref={labelRef} truncate>{text}</Text></Tooltip>\n */\nexport const useOverflowTooltipLabel = () => {\n const parentTooltip = useTooltipContext();\n const labelRef = useRef<HTMLElement | null>(null);\n\n const tooltipLabel = useCallback(\n () => (parentTooltip ? undefined : getOverflowingText(labelRef.current)),\n [parentTooltip],\n );\n\n return { labelRef, tooltipLabel };\n};\n"],"names":["visuallyHidden","VISUALLY_HIDDEN","DisabledStateContext","React","createContext","state","DisabledStateProvider","children","value","_jsx","Provider","useDisabledStateContext","useContext","DEFAULT_VALUE","TooltipContext","undefined","TooltipContextProvider","useTooltipContext","getOverflowingText","element","closest","offsetWidth","scrollWidth","innerText","CLICK_AWAY_EVENT_TYPES","isClickAway","targets","elements","some","Node","target","contains","setupClickAway","getElements","callback","listener","evt","composedPath","filter","t","forEach","evtType","document","addEventListener","removeEventListener","useClickAway","childrenRefs","useEffect","refs","current","map","ref","Boolean","ClickAwayAncestorContext","ClickAwayProvider","parentRef","parentContext","currentContext","useMemo","context","addRefs","newChildrenRefs","push","currentRefs","useRef","displayName","setupInfiniteScrollObserver","options","observer","IntersectionObserver","entries","hasIntersection","entry","isIntersecting","observe","unobserve","INFINITE_SCROLL_CLASSNAME","InfiniteScroll","className","style","height","elementRef","root","UI","PortalContext","container","body","PortalProvider","Portal","enabled","init","useLayoutEffect","teardown","_Fragment","createPortal","useOverflowTooltipLabel","parentTooltip","labelRef","tooltipLabel","useCallback"],"mappings":";;;;;AAEA;AACA;AACA;AACA;AACO,MAAMA,cAAc,GAAGA,MAAMC;;ACF7B,MAAMC,oBAAoB,gBAAGC,cAAK,CAACC,aAAa,CAA4B;AAAEC,EAAAA,KAAK,EAAE;AAAK,CAAC,CAAC;AAMnG;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CAAC;EAAEC,QAAQ;EAAE,GAAGC;AAAkC,CAAC,EAAE;AACtF,EAAA,oBAAOC,GAAA,CAACP,oBAAoB,CAACQ,QAAQ,EAAA;AAACF,IAAAA,KAAK,EAAEA,KAAM;AAAAD,IAAAA,QAAA,EAAEA;AAAQ,GAAgC,CAAC;AAClG;;AAEA;AACA;AACA;AACO,SAASI,uBAAuBA,GAA8B;EACjE,OAAOC,UAAU,CAACV,oBAAoB,CAAC;AAC3C;;AClBA,MAAMW,aAAa,GAAG,EAAE;;AAExB;AACA;AACA;AACA,MAAMC,cAAc,gBAAGX,cAAK,CAACC,aAAa,CAAkCW,SAAS,CAAC;AAE/E,MAAMC,sBAAgE,GAAGA,CAAC;AAAET,EAAAA;AAAS,CAAC,kBACzFE,GAAA,CAAC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;AACA,EAAA,oBAAOuF,YAAY,CAACvF,QAAQ,EAAE8E,SAAS,CAAC;AAC5C;;AC/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMU,uBAAuB,GAAGA,MAAM;AACzC,EAAA,MAAMC,aAAa,GAAG/E,iBAAiB,EAAE;AACzC,EAAA,MAAMgF,QAAQ,GAAGjC,MAAM,CAAqB,IAAI,CAAC;AAEjD,EAAA,MAAMkC,YAAY,GAAGC,WAAW,CAC5B,MAAOH,aAAa,GAAGjF,SAAS,GAAGG,kBAAkB,CAAC+E,QAAQ,CAAChD,OAAO,CAAE,EACxE,CAAC+C,aAAa,CAClB,CAAC;EAED,OAAO;IAAEC,QAAQ;AAAEC,IAAAA;GAAc;AACrC;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -2173,8 +2173,11 @@ interface TooltipProps$1 extends HasCloseMode {
|
|
|
2173
2173
|
delay?: number;
|
|
2174
2174
|
/** Whether the tooltip is displayed even without the mouse hovering the anchor. */
|
|
2175
2175
|
forceOpen?: boolean;
|
|
2176
|
-
/**
|
|
2177
|
-
|
|
2176
|
+
/**
|
|
2177
|
+
* Label text, or a cheap function that returns it, called on open and on each render while open.
|
|
2178
|
+
* A function label needs `closeMode="unmount"`. See `useOverflowTooltipLabel`.
|
|
2179
|
+
*/
|
|
2180
|
+
label?: string | null | false | (() => string | null | false | undefined);
|
|
2178
2181
|
/** Placement of the tooltip relative to the anchor. */
|
|
2179
2182
|
placement?: TooltipPlacement;
|
|
2180
2183
|
/** Choose how the tooltip text should link to the anchor */
|
|
@@ -4620,12 +4623,16 @@ interface BaseSelectTextFieldWrapperProps<O> extends Pick<BaseSelectProps<O>, 'o
|
|
|
4620
4623
|
filter: 'auto' | 'manual' | 'off';
|
|
4621
4624
|
/**
|
|
4622
4625
|
* Controlled search input value.
|
|
4623
|
-
* When provided, this value seeds
|
|
4624
|
-
*
|
|
4626
|
+
* When provided, this value seeds the visible search text in the input. In multiple selection,
|
|
4627
|
+
* `''` resets it.
|
|
4628
|
+
* In single selection, `''` (empty string) keeps the input empty while the option stays selected:
|
|
4629
|
+
* the input shows only the text the user types. When you copy `onSearch` into this prop, pass
|
|
4630
|
+
* `search || undefined` so that the input shows the name of the selected option when idle.
|
|
4625
4631
|
*/
|
|
4626
4632
|
searchInputValue?: string;
|
|
4627
4633
|
/**
|
|
4628
|
-
* Whether
|
|
4634
|
+
* Whether the selection can be cleared (single selection): with a clear button, when the user
|
|
4635
|
+
* erases the input text, and with Escape. When `false`, the selection stays.
|
|
4629
4636
|
* @default true
|
|
4630
4637
|
*/
|
|
4631
4638
|
hasClearButton?: boolean;
|
package/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ColorVariant as ColorVariant$1, Size as Size$1,
|
|
1
|
+
import { ColorVariant as ColorVariant$1, Size as Size$1, Theme as Theme$1, AspectRatio as AspectRatio$1, DOCUMENT, IS_BROWSER as IS_BROWSER$1, Emphasis as Emphasis$1, WINDOW, DIALOG_TRANSITION_DURATION, Typography as Typography$1, Orientation as Orientation$1, NOTIFICATION_TRANSITION_DURATION, Kind as Kind$1, Alignment as Alignment$1, ColorPalette as ColorPalette$1 } from '@lumx/core/js/constants';
|
|
2
2
|
export * from '@lumx/core/js/constants';
|
|
3
3
|
export * from '@lumx/core/js/types';
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import React__default, { useState, useEffect, useMemo, useRef, useCallback, Children, useLayoutEffect, cloneElement, createContext, useContext, useReducer } from 'react';
|
|
7
|
+
import { u as useDisabledStateContext, a as useTooltipContext, g as getOverflowingText, v as visuallyHidden, T as TooltipContextProvider, P as Portal, C as ClickAwayProvider, b as useOverflowTooltipLabel, I as InfiniteScroll } from './_internal/Dx4QtHFB.js';
|
|
7
8
|
import * as ReactDOM from 'react-dom';
|
|
8
9
|
import ReactDOM__default from 'react-dom';
|
|
9
10
|
import { classNames, onEscapePressed, onEnterPressed as onEnterPressed$1, detectHorizontalSwipe } from '@lumx/core/js/utils';
|
|
10
11
|
import last from 'lodash/last.js';
|
|
11
12
|
import pull from 'lodash/pull.js';
|
|
12
|
-
import { u as useDisabledStateContext, P as Portal, C as ClickAwayProvider, I as InfiniteScroll } from './_internal/CcLi-Wuu.js';
|
|
13
13
|
import { getDisabledState as getDisabledState$1 } from '@lumx/core/js/utils/disabledState';
|
|
14
14
|
import { mdiInformationOutline } from '@lumx/icons/esm/information-outline.js';
|
|
15
15
|
import { mdiAlertCircle } from '@lumx/icons/esm/alert-circle.js';
|
|
@@ -448,12 +448,6 @@ function padding(directionOrSize, size) {
|
|
|
448
448
|
return spacing('padding', directionOrSize, size);
|
|
449
449
|
}
|
|
450
450
|
|
|
451
|
-
/**
|
|
452
|
-
* Visually hidden class name.
|
|
453
|
-
* Used to hide elements from view but keep them readable from screen readers
|
|
454
|
-
*/
|
|
455
|
-
const visuallyHidden = () => VISUALLY_HIDDEN;
|
|
456
|
-
|
|
457
451
|
/**
|
|
458
452
|
* Creates a BEM element class generator function for the given base class.
|
|
459
453
|
* Returns a function that generates BEM element class names with optional modifiers.
|
|
@@ -2715,45 +2709,20 @@ Icon.displayName = Icon$1.displayName;
|
|
|
2715
2709
|
Icon.className = Icon$1.className;
|
|
2716
2710
|
Icon.defaultProps = Icon$1.defaultProps;
|
|
2717
2711
|
|
|
2718
|
-
const DEFAULT_VALUE = {};
|
|
2719
|
-
|
|
2720
|
-
/**
|
|
2721
|
-
* Tooltip react context simply used as a marker to know when parent react node have a tooltip
|
|
2722
|
-
*/
|
|
2723
|
-
const TooltipContext = /*#__PURE__*/React__default.createContext(undefined);
|
|
2724
|
-
const TooltipContextProvider = ({
|
|
2725
|
-
children
|
|
2726
|
-
}) => /*#__PURE__*/jsx(TooltipContext.Provider, {
|
|
2727
|
-
value: DEFAULT_VALUE,
|
|
2728
|
-
children: children
|
|
2729
|
-
});
|
|
2730
|
-
const useTooltipContext = () => React__default.useContext(TooltipContext);
|
|
2731
|
-
|
|
2732
2712
|
/**
|
|
2733
|
-
* Compute a
|
|
2713
|
+
* Compute a native `title` from the `innerText` of a label element when its text overflows.
|
|
2734
2714
|
* Updates dynamically on content changes (but not on resize!)
|
|
2735
2715
|
*/
|
|
2736
|
-
const
|
|
2716
|
+
const useOverflowTitle = content => {
|
|
2737
2717
|
const parentTooltip = useTooltipContext();
|
|
2738
|
-
const [
|
|
2718
|
+
const [title, setTitle] = React__default.useState(undefined);
|
|
2739
2719
|
const [labelElement, setLabelElement] = React__default.useState(null);
|
|
2740
2720
|
React__default.useLayoutEffect(() => {
|
|
2741
|
-
|
|
2742
|
-
// Not inside a tooltip
|
|
2743
|
-
!parentTooltip && labelElement &&
|
|
2744
|
-
// Not inside a visually hidden
|
|
2745
|
-
!labelElement?.closest(`.${classNames.visuallyHidden()}`) &&
|
|
2746
|
-
// Text overflows
|
|
2747
|
-
labelElement.offsetWidth < labelElement.scrollWidth) {
|
|
2748
|
-
// Set tooltip label
|
|
2749
|
-
setTooltipLabel(labelElement.innerText);
|
|
2750
|
-
} else {
|
|
2751
|
-
setTooltipLabel(undefined);
|
|
2752
|
-
}
|
|
2721
|
+
setTitle(parentTooltip ? undefined : getOverflowingText(labelElement));
|
|
2753
2722
|
}, [labelElement, parentTooltip, content]);
|
|
2754
2723
|
return {
|
|
2755
2724
|
labelRef: setLabelElement,
|
|
2756
|
-
|
|
2725
|
+
title
|
|
2757
2726
|
};
|
|
2758
2727
|
};
|
|
2759
2728
|
|
|
@@ -2892,16 +2861,16 @@ const Text = forwardRef((props, ref) => {
|
|
|
2892
2861
|
...forwardedProps
|
|
2893
2862
|
} = props;
|
|
2894
2863
|
const {
|
|
2895
|
-
|
|
2864
|
+
title,
|
|
2896
2865
|
labelRef
|
|
2897
|
-
} =
|
|
2866
|
+
} = useOverflowTitle(children);
|
|
2898
2867
|
const {
|
|
2899
2868
|
className,
|
|
2900
2869
|
style
|
|
2901
2870
|
} = React__default.useMemo(() => getTextProps(props), [props]);
|
|
2902
2871
|
return /*#__PURE__*/jsx(Component, {
|
|
2903
2872
|
ref: useMergeRefs(ref, labelRef),
|
|
2904
|
-
title:
|
|
2873
|
+
title: title,
|
|
2905
2874
|
...forwardedProps,
|
|
2906
2875
|
className: className,
|
|
2907
2876
|
style: style,
|
|
@@ -4978,6 +4947,60 @@ const offset = (options, deps) => ({
|
|
|
4978
4947
|
options: [options, deps]
|
|
4979
4948
|
});
|
|
4980
4949
|
|
|
4950
|
+
/**
|
|
4951
|
+
* Keep track of listeners, only the last registered listener gets activated at any point (previously registered
|
|
4952
|
+
* listener are disabled).
|
|
4953
|
+
* When a listener gets unregistered, the previously registered listener gets enabled again.
|
|
4954
|
+
*/
|
|
4955
|
+
function makeListenerTowerContext() {
|
|
4956
|
+
const LISTENERS = [];
|
|
4957
|
+
return {
|
|
4958
|
+
register(listener) {
|
|
4959
|
+
// Disable previous listener.
|
|
4960
|
+
last(LISTENERS)?.disable();
|
|
4961
|
+
// Keep track of current listener.
|
|
4962
|
+
LISTENERS.push(listener);
|
|
4963
|
+
// Enable current listener.
|
|
4964
|
+
listener.enable();
|
|
4965
|
+
},
|
|
4966
|
+
unregister(listener) {
|
|
4967
|
+
// Disable current listener.
|
|
4968
|
+
listener.disable();
|
|
4969
|
+
// Remove current listener.
|
|
4970
|
+
pull(LISTENERS, listener);
|
|
4971
|
+
// Enable previous listener.
|
|
4972
|
+
last(LISTENERS)?.enable();
|
|
4973
|
+
}
|
|
4974
|
+
};
|
|
4975
|
+
}
|
|
4976
|
+
|
|
4977
|
+
const LISTENERS = makeListenerTowerContext();
|
|
4978
|
+
|
|
4979
|
+
/**
|
|
4980
|
+
* Register a global listener on 'Escape' key pressed.
|
|
4981
|
+
*
|
|
4982
|
+
* If multiple listener are registered, only the last one is maintained. When a listener is unregistered, the previous
|
|
4983
|
+
* one gets activated again.
|
|
4984
|
+
*
|
|
4985
|
+
* @param callback Callback
|
|
4986
|
+
* @param closeOnEscape Disables the hook when false
|
|
4987
|
+
*/
|
|
4988
|
+
function useCallbackOnEscape(callback, closeOnEscape = true) {
|
|
4989
|
+
useEffect(() => {
|
|
4990
|
+
const rootElement = DOCUMENT?.body;
|
|
4991
|
+
if (!closeOnEscape || !callback || !rootElement) {
|
|
4992
|
+
return undefined;
|
|
4993
|
+
}
|
|
4994
|
+
const onKeyDown = onEscapePressed(callback);
|
|
4995
|
+
const listener = {
|
|
4996
|
+
enable: () => rootElement.addEventListener('keydown', onKeyDown),
|
|
4997
|
+
disable: () => rootElement.removeEventListener('keydown', onKeyDown)
|
|
4998
|
+
};
|
|
4999
|
+
LISTENERS.register(listener);
|
|
5000
|
+
return () => LISTENERS.unregister(listener);
|
|
5001
|
+
}, [callback, closeOnEscape]);
|
|
5002
|
+
}
|
|
5003
|
+
|
|
4981
5004
|
/**
|
|
4982
5005
|
* Arrow size (in pixel).
|
|
4983
5006
|
*/
|
|
@@ -5075,12 +5098,13 @@ const useInjectTooltipRef = options => {
|
|
|
5075
5098
|
isMounted,
|
|
5076
5099
|
id,
|
|
5077
5100
|
label,
|
|
5101
|
+
hasLabel,
|
|
5078
5102
|
ariaLinkMode
|
|
5079
5103
|
} = options;
|
|
5080
5104
|
// Only add link when mounted
|
|
5081
5105
|
const linkId = isMounted ? id : undefined;
|
|
5082
5106
|
return useMemo(() => {
|
|
5083
|
-
if (!
|
|
5107
|
+
if (!hasLabel) return children;
|
|
5084
5108
|
|
|
5085
5109
|
// Non-disabled element
|
|
5086
5110
|
if (/*#__PURE__*/React__default.isValidElement(children) && children.props.disabled !== true && children.props.isDisabled !== true) {
|
|
@@ -5106,63 +5130,9 @@ const useInjectTooltipRef = options => {
|
|
|
5106
5130
|
...aria,
|
|
5107
5131
|
children: children
|
|
5108
5132
|
});
|
|
5109
|
-
}, [label, children, setAnchorElement, linkId, ariaLinkMode]);
|
|
5133
|
+
}, [hasLabel, label, children, setAnchorElement, linkId, ariaLinkMode]);
|
|
5110
5134
|
};
|
|
5111
5135
|
|
|
5112
|
-
/**
|
|
5113
|
-
* Keep track of listeners, only the last registered listener gets activated at any point (previously registered
|
|
5114
|
-
* listener are disabled).
|
|
5115
|
-
* When a listener gets unregistered, the previously registered listener gets enabled again.
|
|
5116
|
-
*/
|
|
5117
|
-
function makeListenerTowerContext() {
|
|
5118
|
-
const LISTENERS = [];
|
|
5119
|
-
return {
|
|
5120
|
-
register(listener) {
|
|
5121
|
-
// Disable previous listener.
|
|
5122
|
-
last(LISTENERS)?.disable();
|
|
5123
|
-
// Keep track of current listener.
|
|
5124
|
-
LISTENERS.push(listener);
|
|
5125
|
-
// Enable current listener.
|
|
5126
|
-
listener.enable();
|
|
5127
|
-
},
|
|
5128
|
-
unregister(listener) {
|
|
5129
|
-
// Disable current listener.
|
|
5130
|
-
listener.disable();
|
|
5131
|
-
// Remove current listener.
|
|
5132
|
-
pull(LISTENERS, listener);
|
|
5133
|
-
// Enable previous listener.
|
|
5134
|
-
last(LISTENERS)?.enable();
|
|
5135
|
-
}
|
|
5136
|
-
};
|
|
5137
|
-
}
|
|
5138
|
-
|
|
5139
|
-
const LISTENERS = makeListenerTowerContext();
|
|
5140
|
-
|
|
5141
|
-
/**
|
|
5142
|
-
* Register a global listener on 'Escape' key pressed.
|
|
5143
|
-
*
|
|
5144
|
-
* If multiple listener are registered, only the last one is maintained. When a listener is unregistered, the previous
|
|
5145
|
-
* one gets activated again.
|
|
5146
|
-
*
|
|
5147
|
-
* @param callback Callback
|
|
5148
|
-
* @param closeOnEscape Disables the hook when false
|
|
5149
|
-
*/
|
|
5150
|
-
function useCallbackOnEscape(callback, closeOnEscape = true) {
|
|
5151
|
-
useEffect(() => {
|
|
5152
|
-
const rootElement = DOCUMENT?.body;
|
|
5153
|
-
if (!closeOnEscape || !callback || !rootElement) {
|
|
5154
|
-
return undefined;
|
|
5155
|
-
}
|
|
5156
|
-
const onKeyDown = onEscapePressed(callback);
|
|
5157
|
-
const listener = {
|
|
5158
|
-
enable: () => rootElement.addEventListener('keydown', onKeyDown),
|
|
5159
|
-
disable: () => rootElement.removeEventListener('keydown', onKeyDown)
|
|
5160
|
-
};
|
|
5161
|
-
LISTENERS.register(listener);
|
|
5162
|
-
return () => LISTENERS.unregister(listener);
|
|
5163
|
-
}, [callback, closeOnEscape]);
|
|
5164
|
-
}
|
|
5165
|
-
|
|
5166
5136
|
/** Check if the focus is visible on the given element */
|
|
5167
5137
|
const isFocusVisible = element => {
|
|
5168
5138
|
try {
|
|
@@ -5307,38 +5277,68 @@ function createTooltipOpenManager(options) {
|
|
|
5307
5277
|
};
|
|
5308
5278
|
}
|
|
5309
5279
|
|
|
5280
|
+
/**
|
|
5281
|
+
* SSR-safe version of `useLayoutEffect`.
|
|
5282
|
+
* Uses `useLayoutEffect` on the client and `useEffect` on the server to avoid React SSR warnings.
|
|
5283
|
+
*/
|
|
5284
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
5285
|
+
|
|
5286
|
+
/**
|
|
5287
|
+
* Returns a stable callback that always calls the latest version of `fn`.
|
|
5288
|
+
* Useful to avoid re-running effects when a callback prop changes reference.
|
|
5289
|
+
*
|
|
5290
|
+
* https://github.com/facebook/react/issues/14099#issuecomment-440013892
|
|
5291
|
+
*
|
|
5292
|
+
* @param fn A function to stabilize.
|
|
5293
|
+
* @return A stable function with the same signature.
|
|
5294
|
+
*/
|
|
5295
|
+
function useEventCallback(fn) {
|
|
5296
|
+
const ref = React__default.useRef(fn);
|
|
5297
|
+
useIsomorphicLayoutEffect(() => {
|
|
5298
|
+
ref.current = fn;
|
|
5299
|
+
});
|
|
5300
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5301
|
+
return React__default.useCallback((...args) => ref.current?.(...args), []);
|
|
5302
|
+
}
|
|
5303
|
+
|
|
5310
5304
|
/**
|
|
5311
5305
|
* Hook controlling tooltip visibility using mouse hover the anchor and delay.
|
|
5312
5306
|
*
|
|
5313
5307
|
* @param delay Delay in millisecond to display the tooltip.
|
|
5314
5308
|
* @param anchorElement Tooltip anchor element.
|
|
5315
|
-
* @
|
|
5309
|
+
* @param onOpen Called each time the open delay ends, before the state changes.
|
|
5310
|
+
* @return whether the anchor activates the tooltip, the popper mount callback and a close callback.
|
|
5316
5311
|
*/
|
|
5317
|
-
function useTooltipOpen(delay, anchorElement) {
|
|
5312
|
+
function useTooltipOpen(delay, anchorElement, onOpen) {
|
|
5318
5313
|
const [isOpen, setIsOpen] = useState(false);
|
|
5319
5314
|
const onPopperMount = useRef(null);
|
|
5320
5315
|
const managerRef = useRef(null);
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
useCallbackOnEscape(isOpen ? () => managerRef.current?.close() : undefined);
|
|
5316
|
+
const handleOpen = useEventCallback(onOpen);
|
|
5317
|
+
const close = useCallback(() => managerRef.current?.close(), []);
|
|
5324
5318
|
useEffect(() => {
|
|
5325
5319
|
if (!anchorElement) {
|
|
5326
5320
|
return undefined;
|
|
5327
5321
|
}
|
|
5328
5322
|
const manager = createTooltipOpenManager({
|
|
5329
5323
|
delay,
|
|
5330
|
-
onStateChange:
|
|
5324
|
+
onStateChange: value => {
|
|
5325
|
+
if (value) handleOpen();
|
|
5326
|
+
setIsOpen(value);
|
|
5327
|
+
}
|
|
5331
5328
|
});
|
|
5332
5329
|
managerRef.current = manager;
|
|
5333
5330
|
onPopperMount.current = el => manager.attachPopper(el);
|
|
5334
5331
|
manager.attachAnchor(anchorElement);
|
|
5335
5332
|
return () => {
|
|
5336
5333
|
manager.destroy();
|
|
5334
|
+
// The manager dies with the anchor, so the open state must die with it.
|
|
5335
|
+
setIsOpen(false);
|
|
5337
5336
|
};
|
|
5338
|
-
}, [anchorElement, delay]);
|
|
5337
|
+
}, [anchorElement, delay, handleOpen]);
|
|
5339
5338
|
return {
|
|
5340
5339
|
isOpen,
|
|
5341
|
-
onPopperMount: onPopperMount.current
|
|
5340
|
+
onPopperMount: onPopperMount.current,
|
|
5341
|
+
close
|
|
5342
5342
|
};
|
|
5343
5343
|
}
|
|
5344
5344
|
|
|
@@ -5388,20 +5388,36 @@ const Tooltip = forwardRef((props, ref) => {
|
|
|
5388
5388
|
} : {}),
|
|
5389
5389
|
middleware: [offset(ARROW_SIZE$1)]
|
|
5390
5390
|
});
|
|
5391
|
+
const [resolvedFunctionLabel, setResolvedFunctionLabel] = useState(undefined);
|
|
5392
|
+
const resolveLabel = () => {
|
|
5393
|
+
if (typeof label === 'function') setResolvedFunctionLabel(label());
|
|
5394
|
+
};
|
|
5391
5395
|
const position = resolvedPlacement ?? placement;
|
|
5392
5396
|
const {
|
|
5393
5397
|
isOpen: isActivated,
|
|
5394
|
-
onPopperMount
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
const
|
|
5398
|
+
onPopperMount,
|
|
5399
|
+
close
|
|
5400
|
+
} = useTooltipOpen(delay, anchorElement, resolveLabel);
|
|
5401
|
+
const resolvedLabel = typeof label === 'function' ? resolvedFunctionLabel : label;
|
|
5402
|
+
const hasLabel = typeof label === 'function' || !!label;
|
|
5403
|
+
const isOpen = (isActivated || forceOpen) && !!resolvedLabel;
|
|
5404
|
+
const isMounted = !!resolvedLabel && (isOpen || closeMode === 'hide');
|
|
5398
5405
|
const isHidden = !isOpen && closeMode === 'hide';
|
|
5406
|
+
|
|
5407
|
+
// No dependency list: the text of a function label can change on any render (ex: a toggle by keyboard).
|
|
5408
|
+
useLayoutEffect(() => {
|
|
5409
|
+
if (isActivated || forceOpen) resolveLabel();
|
|
5410
|
+
});
|
|
5411
|
+
|
|
5412
|
+
// A forced-open tooltip does not take Escape from its container (ex: the highlighted option of a combobox).
|
|
5413
|
+
useCallbackOnEscape(isActivated && resolvedLabel ? close : undefined);
|
|
5399
5414
|
const wrappedChildren = useInjectTooltipRef({
|
|
5400
5415
|
children,
|
|
5401
5416
|
setAnchorElement,
|
|
5402
5417
|
isMounted,
|
|
5403
5418
|
id,
|
|
5404
|
-
label,
|
|
5419
|
+
label: resolvedLabel,
|
|
5420
|
+
hasLabel,
|
|
5405
5421
|
ariaLinkMode: ariaLinkMode
|
|
5406
5422
|
});
|
|
5407
5423
|
const tooltipRef = useMergeRefs(ref, setPopperElement, onPopperMount);
|
|
@@ -5413,7 +5429,7 @@ const Tooltip = forwardRef((props, ref) => {
|
|
|
5413
5429
|
ref: tooltipRef,
|
|
5414
5430
|
...forwardedProps,
|
|
5415
5431
|
id,
|
|
5416
|
-
label:
|
|
5432
|
+
label: resolvedLabel,
|
|
5417
5433
|
position: position,
|
|
5418
5434
|
isHidden,
|
|
5419
5435
|
style: isHidden ? undefined : floatingStyles,
|
|
@@ -6193,30 +6209,6 @@ function setupRovingTabIndex(options, signal) {
|
|
|
6193
6209
|
return nav;
|
|
6194
6210
|
}
|
|
6195
6211
|
|
|
6196
|
-
/**
|
|
6197
|
-
* SSR-safe version of `useLayoutEffect`.
|
|
6198
|
-
* Uses `useLayoutEffect` on the client and `useEffect` on the server to avoid React SSR warnings.
|
|
6199
|
-
*/
|
|
6200
|
-
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
6201
|
-
|
|
6202
|
-
/**
|
|
6203
|
-
* Returns a stable callback that always calls the latest version of `fn`.
|
|
6204
|
-
* Useful to avoid re-running effects when a callback prop changes reference.
|
|
6205
|
-
*
|
|
6206
|
-
* https://github.com/facebook/react/issues/14099#issuecomment-440013892
|
|
6207
|
-
*
|
|
6208
|
-
* @param fn A function to stabilize.
|
|
6209
|
-
* @return A stable function with the same signature.
|
|
6210
|
-
*/
|
|
6211
|
-
function useEventCallback(fn) {
|
|
6212
|
-
const ref = React__default.useRef(fn);
|
|
6213
|
-
useIsomorphicLayoutEffect(() => {
|
|
6214
|
-
ref.current = fn;
|
|
6215
|
-
});
|
|
6216
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6217
|
-
return React__default.useCallback((...args) => ref.current?.(...args), []);
|
|
6218
|
-
}
|
|
6219
|
-
|
|
6220
6212
|
/** Unref a react ref or element */
|
|
6221
6213
|
function unref(maybeElement) {
|
|
6222
6214
|
if (maybeElement instanceof HTMLElement) return maybeElement;
|
|
@@ -17540,9 +17532,9 @@ const NavigationItem = Object.assign(forwardRefPolymorphic((props, ref) => {
|
|
|
17540
17532
|
} = props;
|
|
17541
17533
|
const theme = useTheme();
|
|
17542
17534
|
const {
|
|
17543
|
-
|
|
17544
|
-
|
|
17545
|
-
} = useOverflowTooltipLabel(
|
|
17535
|
+
labelRef,
|
|
17536
|
+
tooltipLabel
|
|
17537
|
+
} = useOverflowTooltipLabel();
|
|
17546
17538
|
return /*#__PURE__*/jsx("li", {
|
|
17547
17539
|
className: classNames.join(className, block$w({
|
|
17548
17540
|
[`theme-${theme}`]: Boolean(theme)
|
|
@@ -19987,7 +19979,9 @@ const SelectTextField$1 = props => {
|
|
|
19987
19979
|
let displayValue;
|
|
19988
19980
|
if (isMultiple || isSearching) {
|
|
19989
19981
|
displayValue = searchText;
|
|
19990
|
-
} else if (
|
|
19982
|
+
} else if (externalSearchValue === '') {
|
|
19983
|
+
displayValue = '';
|
|
19984
|
+
} else {
|
|
19991
19985
|
displayValue = getOptionDisplayName(value, getOptionName, getOptionId);
|
|
19992
19986
|
}
|
|
19993
19987
|
|
|
@@ -19996,13 +19990,15 @@ const SelectTextField$1 = props => {
|
|
|
19996
19990
|
const next = toggleSelection(options, getOptionId, value, selectedOption.value, isMultiple);
|
|
19997
19991
|
// In multi mode, `toggleSelection` skips when no option matches and returns the
|
|
19998
19992
|
// unchanged current array — the onChange call is a no-op for the consumer.
|
|
19999
|
-
|
|
19993
|
+
// Escape on a closed combobox sends a clear request with an empty option id.
|
|
19994
|
+
const isBlockedClear = !isMultiple && !hasClearButton && selectedOption.value === '';
|
|
19995
|
+
if (!isBlockedClear) onChange?.(next);
|
|
20000
19996
|
|
|
20001
19997
|
// Reset search state after selection.
|
|
20002
19998
|
setIsSearching(false);
|
|
20003
19999
|
setSearchText('');
|
|
20004
20000
|
onSearch?.('');
|
|
20005
|
-
}, [getOptionId, isMultiple, onChange, onSearch, options, value]);
|
|
20001
|
+
}, [getOptionId, hasClearButton, isMultiple, onChange, onSearch, options, value]);
|
|
20006
20002
|
|
|
20007
20003
|
// Handle text input changes (search).
|
|
20008
20004
|
const handleInputChange = useCallback(inputValue => {
|
|
@@ -20011,10 +20007,10 @@ const SelectTextField$1 = props => {
|
|
|
20011
20007
|
onSearch?.(inputValue);
|
|
20012
20008
|
|
|
20013
20009
|
// When the user clears the input (single mode only), clear the selection too.
|
|
20014
|
-
if (!isMultiple && inputValue === '' && value !== undefined && value !== null) {
|
|
20010
|
+
if (!isMultiple && hasClearButton && inputValue === '' && value !== undefined && value !== null) {
|
|
20015
20011
|
onChange?.(undefined);
|
|
20016
20012
|
}
|
|
20017
|
-
}, [isMultiple, onChange, onSearch, value]);
|
|
20013
|
+
}, [hasClearButton, isMultiple, onChange, onSearch, value]);
|
|
20018
20014
|
|
|
20019
20015
|
// Handle clear button click (single mode only).
|
|
20020
20016
|
const handleClear = useCallback(event => {
|