react-aria-components 1.15.1 → 1.16.0
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/dist/Button.main.js +3 -2
- package/dist/Button.main.js.map +1 -1
- package/dist/Button.mjs +3 -2
- package/dist/Button.module.js +3 -2
- package/dist/Button.module.js.map +1 -1
- package/dist/Collection.main.js +3 -0
- package/dist/Collection.main.js.map +1 -1
- package/dist/Collection.mjs +3 -0
- package/dist/Collection.module.js +3 -0
- package/dist/Collection.module.js.map +1 -1
- package/dist/ComboBox.main.js +59 -8
- package/dist/ComboBox.main.js.map +1 -1
- package/dist/ComboBox.mjs +61 -12
- package/dist/ComboBox.module.js +61 -12
- package/dist/ComboBox.module.js.map +1 -1
- package/dist/DateField.main.js +8 -4
- package/dist/DateField.main.js.map +1 -1
- package/dist/DateField.mjs +8 -4
- package/dist/DateField.module.js +8 -4
- package/dist/DateField.module.js.map +1 -1
- package/dist/DatePicker.main.js +6 -2
- package/dist/DatePicker.main.js.map +1 -1
- package/dist/DatePicker.mjs +6 -2
- package/dist/DatePicker.module.js +6 -2
- package/dist/DatePicker.module.js.map +1 -1
- package/dist/DropZone.main.js +1 -1
- package/dist/DropZone.main.js.map +1 -1
- package/dist/DropZone.mjs +2 -2
- package/dist/DropZone.module.js +2 -2
- package/dist/DropZone.module.js.map +1 -1
- package/dist/FileTrigger.main.js +1 -1
- package/dist/FileTrigger.main.js.map +1 -1
- package/dist/FileTrigger.mjs +2 -2
- package/dist/FileTrigger.module.js +2 -2
- package/dist/FileTrigger.module.js.map +1 -1
- package/dist/GridList.main.js +7 -4
- package/dist/GridList.main.js.map +1 -1
- package/dist/GridList.mjs +7 -5
- package/dist/GridList.module.js +7 -5
- package/dist/GridList.module.js.map +1 -1
- package/dist/HiddenDateInput.main.js +3 -1
- package/dist/HiddenDateInput.main.js.map +1 -1
- package/dist/HiddenDateInput.mjs +3 -1
- package/dist/HiddenDateInput.module.js +3 -1
- package/dist/HiddenDateInput.module.js.map +1 -1
- package/dist/Keyboard.main.js.map +1 -1
- package/dist/Keyboard.module.js.map +1 -1
- package/dist/ListBox.main.js +2 -1
- package/dist/ListBox.main.js.map +1 -1
- package/dist/ListBox.mjs +3 -2
- package/dist/ListBox.module.js +3 -2
- package/dist/ListBox.module.js.map +1 -1
- package/dist/Menu.main.js +3 -1
- package/dist/Menu.main.js.map +1 -1
- package/dist/Menu.mjs +3 -1
- package/dist/Menu.module.js +3 -1
- package/dist/Menu.module.js.map +1 -1
- package/dist/Popover.main.js +1 -1
- package/dist/Popover.main.js.map +1 -1
- package/dist/Popover.mjs +3 -3
- package/dist/Popover.module.js +3 -3
- package/dist/Popover.module.js.map +1 -1
- package/dist/Tree.main.js +151 -102
- package/dist/Tree.main.js.map +1 -1
- package/dist/Tree.mjs +153 -106
- package/dist/Tree.module.js +153 -106
- package/dist/Tree.module.js.map +1 -1
- package/dist/import.mjs +3 -3
- package/dist/main.js +4 -0
- package/dist/main.js.map +1 -1
- package/dist/module.js +3 -3
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +76 -22
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.main.js.map +1 -1
- package/dist/utils.module.js.map +1 -1
- package/package.json +23 -23
- package/src/Button.tsx +4 -2
- package/src/Collection.tsx +6 -0
- package/src/ComboBox.tsx +89 -12
- package/src/DateField.tsx +14 -5
- package/src/DatePicker.tsx +11 -2
- package/src/DropZone.tsx +2 -2
- package/src/FileTrigger.tsx +2 -2
- package/src/GridList.tsx +12 -3
- package/src/HiddenDateInput.tsx +2 -1
- package/src/Keyboard.tsx +2 -2
- package/src/ListBox.tsx +5 -4
- package/src/Menu.tsx +3 -2
- package/src/Popover.tsx +3 -3
- package/src/Tree.tsx +209 -146
- package/src/index.ts +4 -3
- package/src/utils.tsx +6 -5
package/dist/utils.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAMM,MAAM,4CAAe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AC;QAAc;KAAW;IAEvF,CAAA,GAAA,sBAAc,EAAE;QACd,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,gBAAgB,QAAQ;YACnD,IAAI,CAAC,WAAW,OAAO,EACrB,QAAQ,IAAI,CAAC;iBACR,IAAI,WAAW,OAAO,CAAC,SAAS,KAAK,aAC1C,QAAQ,IAAI,CAAC,CAAC,yEAAyE,EAAE,YAAY,QAAQ,EAAE,WAAW,OAAO,CAAC,SAAS,CAAC,2DAA2D,CAAC;QAE5M;IACF,GAAG;QAAC;QAAa;KAAO;IAExB,IAAI,WAAgB;QAAC,GAAG,UAAU;aAAE;IAAG;IACvC,IAAI,QACF,OAAO,OAAO,UAAU;IAG1B,qBAAO,gCAAC,aAAgB;AAC1B;AAMA,MAAM,0CAAoB,CAAC;AAGpB,MAAM,4CAAM,IAAI,MAAM,CAAC,GAAG;IAC/B,KAAI,MAAM,EAAE,WAAW;QACrB,IAAI,OAAO,gBAAgB,UACzB,OAAO;QAGT,IAAI,MAAM,uCAAiB,CAAC,YAAY;QACxC,IAAI,CAAC,KAAK;YACR,oBAAM,CAAA,GAAA,iBAAS,EAAE,iCAAW,IAAI,CAAC,MAAM;YACvC,uCAAiB,CAAC,YAAY,GAAG;QACnC;QAEA,OAAO;IACT;AACF","sources":["packages/react-aria-components/src/utils.tsx"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, RefObject, DOMProps as SharedDOMProps} from '@react-types/shared';\nimport {mergeProps, mergeRefs, useLayoutEffect, useObjectRef} from '@react-aria/utils';\nimport React, {AllHTMLAttributes, AnchorHTMLAttributes, Context, CSSProperties, DetailedHTMLProps, ForwardedRef, forwardRef, JSX, ReactElement, ReactNode, RefCallback, useCallback, useContext, useMemo, useRef, useState} from 'react';\n\nexport const DEFAULT_SLOT = Symbol('default');\n\ninterface SlottedValue<T> {\n slots?: Record<string | symbol, T>\n}\n\nexport type SlottedContextValue<T> = SlottedValue<T> | T | null | undefined;\nexport type ContextValue<T, E> = SlottedContextValue<WithRef<T, E>>;\n\ntype ProviderValue<T> = [Context<T>, T];\ntype ProviderValues<A, B, C, D, E, F, G, H, I, J, K> =\n | [ProviderValue<A>]\n | [ProviderValue<A>, ProviderValue<B>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>, ProviderValue<G>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>, ProviderValue<G>, ProviderValue<H>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>, ProviderValue<G>, ProviderValue<H>, ProviderValue<I>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>, ProviderValue<G>, ProviderValue<H>, ProviderValue<I>, ProviderValue<J>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>, ProviderValue<G>, ProviderValue<H>, ProviderValue<I>, ProviderValue<J>, ProviderValue<K>];\n\ninterface ProviderProps<A, B, C, D, E, F, G, H, I, J, K> {\n values: ProviderValues<A, B, C, D, E, F, G, H, I, J, K>,\n children: ReactNode\n}\n\nexport function Provider<A, B, C, D, E, F, G, H, I, J, K>({values, children}: ProviderProps<A, B, C, D, E, F, G, H, I, J, K>): JSX.Element {\n for (let [Context, value] of values) {\n // @ts-ignore\n children = <Context.Provider value={value}>{children}</Context.Provider>;\n }\n\n return children as JSX.Element;\n}\n\nexport interface StyleProps {\n /** The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. */\n className?: string,\n /** The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. */\n style?: CSSProperties\n}\n\nexport interface DOMProps extends StyleProps, SharedDOMProps {\n /** The children of the component. */\n children?: ReactNode\n}\n\nexport type ClassNameOrFunction<T> = string | ((values: T & {defaultClassName: string | undefined}) => string);\ntype StyleOrFunction<T> = CSSProperties | ((values: T & {defaultStyle: CSSProperties}) => CSSProperties | undefined);\n\nexport interface StyleRenderProps<T, E extends keyof React.JSX.IntrinsicElements = 'div'> extends DOMRenderProps<E, T> {\n /** The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. */\n className?: ClassNameOrFunction<T>,\n /** The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. */\n style?: StyleOrFunction<T>\n}\n\nexport type ChildrenOrFunction<T> = ReactNode | ((values: T & {defaultChildren: ReactNode | undefined}) => ReactNode);\n\nexport interface RenderProps<T, E extends keyof React.JSX.IntrinsicElements = 'div'> extends StyleRenderProps<T, E> {\n /** The children of the component. A function may be provided to alter the children based on component state. */\n children?: ChildrenOrFunction<T>\n}\n\ninterface RenderPropsHookOptions<T, E extends keyof React.JSX.IntrinsicElements> extends RenderProps<T, E>, SharedDOMProps, AriaLabelingProps {\n values: T,\n defaultChildren?: ReactNode,\n defaultClassName?: string,\n defaultStyle?: CSSProperties\n}\n\ninterface RenderPropsHookRetVal<T, E extends keyof React.JSX.IntrinsicElements> {\n className?: string,\n style?: CSSProperties,\n children?: ReactNode,\n 'data-rac': string,\n render?: DOMRenderFunction<E, T>\n}\n\nexport function useRenderProps<T, E extends keyof React.JSX.IntrinsicElements>(props: RenderPropsHookOptions<T, E>): RenderPropsHookRetVal<T, E> {\n let {\n className,\n style,\n children,\n defaultClassName = undefined,\n defaultChildren = undefined,\n defaultStyle,\n values,\n render\n } = props;\n\n return useMemo(() => {\n let computedClassName: string | undefined;\n let computedStyle: React.CSSProperties | undefined;\n let computedChildren: React.ReactNode | undefined;\n\n if (typeof className === 'function') {\n computedClassName = className({...values, defaultClassName});\n } else {\n computedClassName = className;\n }\n\n if (typeof style === 'function') {\n computedStyle = style({...values, defaultStyle: defaultStyle || {}});\n } else {\n computedStyle = style;\n }\n\n if (typeof children === 'function') {\n computedChildren = children({...values, defaultChildren});\n } else if (children == null) {\n computedChildren = defaultChildren;\n } else {\n computedChildren = children;\n }\n\n return {\n className: computedClassName ?? defaultClassName,\n style: (computedStyle || defaultStyle) ? {...defaultStyle, ...computedStyle} : undefined,\n children: computedChildren ?? defaultChildren,\n 'data-rac': '',\n render: render ? (props => render(props, values)) : undefined\n };\n }, [className, style, children, defaultClassName, defaultChildren, defaultStyle, values, render]);\n}\n\n/**\n * A helper function that accepts a user-provided render prop value (either a static value or a function),\n * and combines it with another value to create a final result.\n */\nexport function composeRenderProps<T, U, V extends T>(\n // https://stackoverflow.com/questions/60898079/typescript-type-t-or-function-t-usage\n value: T extends any ? (T | ((renderProps: U) => V)) : never,\n wrap: (prevValue: T, renderProps: U) => V\n): (renderProps: U) => V {\n return (renderProps) => wrap(typeof value === 'function' ? value(renderProps) : value, renderProps);\n}\n\nexport type WithRef<T, E> = T & {ref?: ForwardedRef<E>};\nexport interface SlotProps {\n /**\n * A slot name for the component. Slots allow the component to receive props from a parent component.\n * An explicit `null` value indicates that the local props completely override all props received from a parent.\n */\n slot?: string | null\n}\n\nexport function useSlottedContext<T>(context: Context<SlottedContextValue<T>>, slot?: string | null): T | null | undefined {\n let ctx = useContext(context);\n if (slot === null) {\n // An explicit `null` slot means don't use context.\n return null;\n }\n if (ctx && typeof ctx === 'object' && 'slots' in ctx && ctx.slots) {\n let slotKey = slot || DEFAULT_SLOT;\n if (!ctx.slots[slotKey]) {\n let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map(p => `\"${p}\"`));\n let errorMessage = slot ? `Invalid slot \"${slot}\".` : 'A slot prop is required.';\n\n throw new Error(`${errorMessage} Valid slot names are ${availableSlots}.`);\n }\n return ctx.slots[slotKey];\n }\n // @ts-ignore\n return ctx;\n}\n\nexport function useContextProps<T, U extends SlotProps, E extends Element>(props: T & SlotProps, ref: ForwardedRef<E> | undefined, context: Context<ContextValue<U, E>>): [T, RefObject<E | null>] {\n let ctx = useSlottedContext(context, props.slot) || {};\n let {ref: contextRef, ...contextProps} = ctx as any;\n let mergedRef = useObjectRef(useMemo(() => mergeRefs(ref, contextRef), [ref, contextRef]));\n let mergedProps = mergeProps(contextProps, props) as unknown as T;\n\n // mergeProps does not merge `style`. Adding this there might be a breaking change.\n if (\n 'style' in contextProps &&\n contextProps.style &&\n 'style' in props &&\n props.style\n ) {\n if (typeof contextProps.style === 'function' || typeof props.style === 'function') {\n // @ts-ignore\n mergedProps.style = (renderProps) => {\n let contextStyle = typeof contextProps.style === 'function' ? contextProps.style(renderProps) : contextProps.style;\n let defaultStyle = {...renderProps.defaultStyle, ...contextStyle};\n let style = typeof props.style === 'function'\n ? props.style({...renderProps, defaultStyle})\n : props.style;\n return {...defaultStyle, ...style};\n };\n } else {\n // @ts-ignore\n mergedProps.style = {...contextProps.style, ...props.style};\n }\n }\n\n return [mergedProps, mergedRef];\n}\n\nexport function useSlot(initialState: boolean | (() => boolean) = true): [RefCallback<Element>, boolean] {\n // Initial state is typically based on the parent having an aria-label or aria-labelledby.\n // If it does, this value should be false so that we don't update the state and cause a rerender when we go through the layoutEffect\n let [hasSlot, setHasSlot] = useState(initialState);\n let hasRun = useRef(false);\n\n // A callback ref which will run when the slotted element mounts.\n // This should happen before the useLayoutEffect below.\n let ref = useCallback(el => {\n hasRun.current = true;\n setHasSlot(!!el);\n }, []);\n\n // If the callback hasn't been called, then reset to false.\n useLayoutEffect(() => {\n if (!hasRun.current) {\n setHasSlot(false);\n }\n }, []);\n\n return [ref, hasSlot];\n}\n\n/**\n * Filters out `data-*` attributes to keep them from being passed down and duplicated.\n * @param props\n */\nexport function removeDataAttributes<T>(props: T): T {\n const prefix = /^(data-.*)$/;\n let filteredProps = {} as T;\n\n for (const prop in props) {\n if (!prefix.test(prop)) {\n filteredProps[prop] = props[prop];\n }\n }\n\n return filteredProps;\n}\n\n// Override base type to change the default.\nexport interface RACValidation {\n /**\n * Whether to use native HTML form validation to prevent form submission\n * when the value is missing or invalid, or mark the field as required\n * or invalid via ARIA.\n * @default 'native'\n */\n validationBehavior?: 'native' | 'aria'\n}\n\nexport type DOMRenderFunction<E extends keyof React.JSX.IntrinsicElements, T> = (props: React.JSX.IntrinsicElements[E], renderProps: T) => ReactElement;\nexport interface DOMRenderProps<E extends keyof React.JSX.IntrinsicElements, T> {\n /**\n * Overrides the default DOM element with a custom render function.\n * This allows rendering existing components with built-in styles and behaviors\n * such as router links, animation libraries, and pre-styled components.\n * \n * Requirements:\n * \n * * You must render the expected element type (e.g. if `<button>` is expected, you cannot render an `<a>`).\n * * Only a single root DOM element can be rendered (no fragments).\n * * You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.\n */\n render?: DOMRenderFunction<E, T>\n}\n\n// Makes `href` required in AnchorHTMLAttributes\ntype LinkWithRequiredHref = Required<Pick<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>> & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>; \n\n// Same as DOMRenderProps but specific for the case where the element could be a 'a' or 'div' element.\nexport interface PossibleLinkDOMRenderProps<Fallback extends keyof React.JSX.IntrinsicElements, T> {\n /**\n * Overrides the default DOM element with a custom render function.\n * This allows rendering existing components with built-in styles and behaviors\n * such as router links, animation libraries, and pre-styled components.\n * \n * Note: You can check if `'href' in props` in order to tell whether to render an `<a>` element.\n * \n * Requirements:\n * \n * * You must render the expected element type (e.g. if `<a>` is expected, you cannot render a `<button>`).\n * * Only a single root DOM element can be rendered (no fragments).\n * * You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.\n */\n render?: (props: DetailedHTMLProps<LinkWithRequiredHref, HTMLAnchorElement> | React.JSX.IntrinsicElements[Fallback], renderProps: T) => ReactElement\n}\n\nfunction DOMElement(ElementType: string, props: DOMRenderProps<any, any> & AllHTMLAttributes<HTMLElement>, forwardedRef: ForwardedRef<HTMLElement>) {\n let {render, ...otherProps} = props;\n let elementRef = useRef<HTMLElement | null>(null);\n let ref = useMemo(() => mergeRefs(forwardedRef, elementRef), [forwardedRef, elementRef]);\n\n useLayoutEffect(() => {\n if (process.env.NODE_ENV !== 'production' && render) {\n if (!elementRef.current) {\n console.warn('Ref was not connected to DOM element returned by custom `render` function. Did you forget to pass through or merge the `ref`?');\n } else if (elementRef.current.localName !== ElementType) {\n console.warn(`Unexpected DOM element returned by custom \\`render\\` function. Expected <${ElementType}>, got <${elementRef.current.localName}>. This may break the component behavior and accessibility.`);\n }\n }\n }, [ElementType, render]);\n\n let domProps: any = {...otherProps, ref};\n if (render) {\n return render(domProps, undefined);\n }\n\n return <ElementType {...domProps} />;\n}\n\ntype DOMComponents = {\n [E in keyof React.JSX.IntrinsicElements]: (props: DOMRenderProps<E, any> & React.JSX.IntrinsicElements[E]) => ReactElement\n};\n\nconst domComponentCache = {};\n\n// Dynamically generates and caches components for each DOM element (e.g. `dom.button`).\nexport const dom = new Proxy({}, {\n get(target, elementType) {\n if (typeof elementType !== 'string') {\n return undefined;\n }\n\n let res = domComponentCache[elementType];\n if (!res) {\n res = forwardRef(DOMElement.bind(null, elementType));\n domComponentCache[elementType] = res;\n }\n\n return res;\n }\n}) as DOMComponents;\n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AAsB;IAC5C,IAAI,MAAM,CAAA,GAAA,cAAM,EAAE,IAAM,CAAA,GAAA,gBAAQ,EAAE,cAAc,aAAa;QAAC;QAAc;KAAW;IAEvF,CAAA,GAAA,sBAAc,EAAE;QACd,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,gBAAgB,QAAQ;YACnD,IAAI,CAAC,WAAW,OAAO,EACrB,QAAQ,IAAI,CAAC;iBACR,IAAI,WAAW,OAAO,CAAC,SAAS,KAAK,aAC1C,QAAQ,IAAI,CAAC,CAAC,yEAAyE,EAAE,YAAY,QAAQ,EAAE,WAAW,OAAO,CAAC,SAAS,CAAC,2DAA2D,CAAC;QAE5M;IACF,GAAG;QAAC;QAAa;KAAO;IAExB,IAAI,WAAgB;QAAC,GAAG,UAAU;aAAE;IAAG;IACvC,IAAI,QACF,OAAO,OAAO,UAAU;IAG1B,qBAAO,gCAAC,aAAgB;AAC1B;AAMA,MAAM,0CAAoB,CAAC;AAGpB,MAAM,4CAAM,IAAI,MAAM,CAAC,GAAG;IAC/B,KAAI,MAAM,EAAE,WAAW;QACrB,IAAI,OAAO,gBAAgB,UACzB,OAAO;QAGT,IAAI,MAAM,uCAAiB,CAAC,YAAY;QACxC,IAAI,CAAC,KAAK;YACR,oBAAM,CAAA,GAAA,iBAAS,EAAE,iCAAW,IAAI,CAAC,MAAM;YACvC,uCAAiB,CAAC,YAAY,GAAG;QACnC;QAEA,OAAO;IACT;AACF","sources":["packages/react-aria-components/src/utils.tsx"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, RefObject, DOMProps as SharedDOMProps} from '@react-types/shared';\nimport {mergeProps, mergeRefs, useLayoutEffect, useObjectRef} from '@react-aria/utils';\nimport React, {AllHTMLAttributes, AnchorHTMLAttributes, Context, CSSProperties, DetailedHTMLProps, ForwardedRef, forwardRef, JSX, ReactElement, ReactNode, RefCallback, useCallback, useContext, useMemo, useRef, useState} from 'react';\n\nexport const DEFAULT_SLOT = Symbol('default');\n\ninterface SlottedValue<T> {\n slots?: Record<string | symbol, T>\n}\n\nexport type SlottedContextValue<T> = SlottedValue<T> | T | null | undefined;\nexport type ContextValue<T, E> = SlottedContextValue<WithRef<T, E>>;\n\ntype ProviderValue<T> = [Context<T>, T];\ntype ProviderValues<A, B, C, D, E, F, G, H, I, J, K, L> =\n | [ProviderValue<A>]\n | [ProviderValue<A>, ProviderValue<B>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>, ProviderValue<G>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>, ProviderValue<G>, ProviderValue<H>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>, ProviderValue<G>, ProviderValue<H>, ProviderValue<I>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>, ProviderValue<G>, ProviderValue<H>, ProviderValue<I>, ProviderValue<J>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>, ProviderValue<G>, ProviderValue<H>, ProviderValue<I>, ProviderValue<J>, ProviderValue<K>]\n | [ProviderValue<A>, ProviderValue<B>, ProviderValue<C>, ProviderValue<D>, ProviderValue<E>, ProviderValue<F>, ProviderValue<G>, ProviderValue<H>, ProviderValue<I>, ProviderValue<J>, ProviderValue<K>, ProviderValue<L>];\n\ninterface ProviderProps<A, B, C, D, E, F, G, H, I, J, K, L> {\n values: ProviderValues<A, B, C, D, E, F, G, H, I, J, K, L>,\n children: ReactNode\n}\n\nexport function Provider<A, B, C, D, E, F, G, H, I, J, K, L>({values, children}: ProviderProps<A, B, C, D, E, F, G, H, I, J, K, L>): JSX.Element {\n for (let [Context, value] of values) {\n // @ts-ignore\n children = <Context.Provider value={value}>{children}</Context.Provider>;\n }\n\n return children as JSX.Element;\n}\n\nexport interface StyleProps {\n /** The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. */\n className?: string,\n /** The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. */\n style?: CSSProperties\n}\n\nexport interface DOMProps extends StyleProps, SharedDOMProps {\n /** The children of the component. */\n children?: ReactNode\n}\n\nexport type ClassNameOrFunction<T> = string | ((values: T & {defaultClassName: string | undefined}) => string);\ntype StyleOrFunction<T> = CSSProperties | ((values: T & {defaultStyle: CSSProperties}) => CSSProperties | undefined);\n\nexport interface StyleRenderProps<T, E extends keyof React.JSX.IntrinsicElements = 'div'> extends DOMRenderProps<E, T> {\n /** The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. */\n className?: ClassNameOrFunction<T>,\n /** The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. */\n style?: StyleOrFunction<T>\n}\n\nexport type ChildrenOrFunction<T> = ReactNode | ((values: T & {defaultChildren: ReactNode | undefined}) => ReactNode);\n\nexport interface RenderProps<T, E extends keyof React.JSX.IntrinsicElements = 'div'> extends StyleRenderProps<T, E> {\n /** The children of the component. A function may be provided to alter the children based on component state. */\n children?: ChildrenOrFunction<T>\n}\n\ninterface RenderPropsHookOptions<T, E extends keyof React.JSX.IntrinsicElements> extends RenderProps<T, E>, SharedDOMProps, AriaLabelingProps {\n values: T,\n defaultChildren?: ReactNode,\n defaultClassName?: string,\n defaultStyle?: CSSProperties\n}\n\ninterface RenderPropsHookRetVal<T, E extends keyof React.JSX.IntrinsicElements> {\n className?: string,\n style?: CSSProperties,\n children?: ReactNode,\n 'data-rac': string,\n render?: DOMRenderFunction<E, T>\n}\n\nexport function useRenderProps<T, E extends keyof React.JSX.IntrinsicElements>(props: RenderPropsHookOptions<T, E>): RenderPropsHookRetVal<T, E> {\n let {\n className,\n style,\n children,\n defaultClassName = undefined,\n defaultChildren = undefined,\n defaultStyle,\n values,\n render\n } = props;\n\n return useMemo(() => {\n let computedClassName: string | undefined;\n let computedStyle: React.CSSProperties | undefined;\n let computedChildren: React.ReactNode | undefined;\n\n if (typeof className === 'function') {\n computedClassName = className({...values, defaultClassName});\n } else {\n computedClassName = className;\n }\n\n if (typeof style === 'function') {\n computedStyle = style({...values, defaultStyle: defaultStyle || {}});\n } else {\n computedStyle = style;\n }\n\n if (typeof children === 'function') {\n computedChildren = children({...values, defaultChildren});\n } else if (children == null) {\n computedChildren = defaultChildren;\n } else {\n computedChildren = children;\n }\n\n return {\n className: computedClassName ?? defaultClassName,\n style: (computedStyle || defaultStyle) ? {...defaultStyle, ...computedStyle} : undefined,\n children: computedChildren ?? defaultChildren,\n 'data-rac': '',\n render: render ? (props => render(props, values)) : undefined\n };\n }, [className, style, children, defaultClassName, defaultChildren, defaultStyle, values, render]);\n}\n\n/**\n * A helper function that accepts a user-provided render prop value (either a static value or a function),\n * and combines it with another value to create a final result.\n */\nexport function composeRenderProps<T, U, V extends T>(\n // https://stackoverflow.com/questions/60898079/typescript-type-t-or-function-t-usage\n value: T extends any ? (T | ((renderProps: U) => V)) : never,\n wrap: (prevValue: T, renderProps: U) => V\n): (renderProps: U) => V {\n return (renderProps) => wrap(typeof value === 'function' ? value(renderProps) : value, renderProps);\n}\n\nexport type WithRef<T, E> = T & {ref?: ForwardedRef<E>};\nexport interface SlotProps {\n /**\n * A slot name for the component. Slots allow the component to receive props from a parent component.\n * An explicit `null` value indicates that the local props completely override all props received from a parent.\n */\n slot?: string | null\n}\n\nexport function useSlottedContext<T>(context: Context<SlottedContextValue<T>>, slot?: string | null): T | null | undefined {\n let ctx = useContext(context);\n if (slot === null) {\n // An explicit `null` slot means don't use context.\n return null;\n }\n if (ctx && typeof ctx === 'object' && 'slots' in ctx && ctx.slots) {\n let slotKey = slot || DEFAULT_SLOT;\n if (!ctx.slots[slotKey]) {\n let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map(p => `\"${p}\"`));\n let errorMessage = slot ? `Invalid slot \"${slot}\".` : 'A slot prop is required.';\n\n throw new Error(`${errorMessage} Valid slot names are ${availableSlots}.`);\n }\n return ctx.slots[slotKey];\n }\n // @ts-ignore\n return ctx;\n}\n\nexport function useContextProps<T, U extends SlotProps, E extends Element>(props: T & SlotProps, ref: ForwardedRef<E> | undefined, context: Context<ContextValue<U, E>>): [T, RefObject<E | null>] {\n let ctx = useSlottedContext(context, props.slot) || {};\n let {ref: contextRef, ...contextProps} = ctx as any;\n let mergedRef = useObjectRef(useMemo(() => mergeRefs(ref, contextRef), [ref, contextRef]));\n let mergedProps = mergeProps(contextProps, props) as unknown as T;\n\n // mergeProps does not merge `style`. Adding this there might be a breaking change.\n if (\n 'style' in contextProps &&\n contextProps.style &&\n 'style' in props &&\n props.style\n ) {\n if (typeof contextProps.style === 'function' || typeof props.style === 'function') {\n // @ts-ignore\n mergedProps.style = (renderProps) => {\n let contextStyle = typeof contextProps.style === 'function' ? contextProps.style(renderProps) : contextProps.style;\n let defaultStyle = {...renderProps.defaultStyle, ...contextStyle};\n let style = typeof props.style === 'function'\n ? props.style({...renderProps, defaultStyle})\n : props.style;\n return {...defaultStyle, ...style};\n };\n } else {\n // @ts-ignore\n mergedProps.style = {...contextProps.style, ...props.style};\n }\n }\n\n return [mergedProps, mergedRef];\n}\n\nexport function useSlot(initialState: boolean | (() => boolean) = true): [RefCallback<Element>, boolean] {\n // Initial state is typically based on the parent having an aria-label or aria-labelledby.\n // If it does, this value should be false so that we don't update the state and cause a rerender when we go through the layoutEffect\n let [hasSlot, setHasSlot] = useState(initialState);\n let hasRun = useRef(false);\n\n // A callback ref which will run when the slotted element mounts.\n // This should happen before the useLayoutEffect below.\n let ref = useCallback(el => {\n hasRun.current = true;\n setHasSlot(!!el);\n }, []);\n\n // If the callback hasn't been called, then reset to false.\n useLayoutEffect(() => {\n if (!hasRun.current) {\n setHasSlot(false);\n }\n }, []);\n\n return [ref, hasSlot];\n}\n\n/**\n * Filters out `data-*` attributes to keep them from being passed down and duplicated.\n * @param props\n */\nexport function removeDataAttributes<T>(props: T): T {\n const prefix = /^(data-.*)$/;\n let filteredProps = {} as T;\n\n for (const prop in props) {\n if (!prefix.test(prop)) {\n filteredProps[prop] = props[prop];\n }\n }\n\n return filteredProps;\n}\n\n// Override base type to change the default.\nexport interface RACValidation {\n /**\n * Whether to use native HTML form validation to prevent form submission\n * when the value is missing or invalid, or mark the field as required\n * or invalid via ARIA.\n * @default 'native'\n */\n validationBehavior?: 'native' | 'aria'\n}\n\nexport type DOMRenderFunction<E extends keyof React.JSX.IntrinsicElements, T> = (props: React.JSX.IntrinsicElements[E], renderProps: T) => ReactElement;\nexport interface DOMRenderProps<E extends keyof React.JSX.IntrinsicElements, T> {\n /**\n * Overrides the default DOM element with a custom render function.\n * This allows rendering existing components with built-in styles and behaviors\n * such as router links, animation libraries, and pre-styled components.\n * \n * Requirements:\n * \n * * You must render the expected element type (e.g. if `<button>` is expected, you cannot render an `<a>`).\n * * Only a single root DOM element can be rendered (no fragments).\n * * You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.\n */\n render?: DOMRenderFunction<E, T>\n}\n\n// Makes `href` required in AnchorHTMLAttributes\ntype LinkWithRequiredHref = Required<Pick<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>> & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>; \n\n// Same as DOMRenderProps but specific for the case where the element could be a 'a' or 'div' element.\nexport interface PossibleLinkDOMRenderProps<Fallback extends keyof React.JSX.IntrinsicElements, T> {\n /**\n * Overrides the default DOM element with a custom render function.\n * This allows rendering existing components with built-in styles and behaviors\n * such as router links, animation libraries, and pre-styled components.\n * \n * Note: You can check if `'href' in props` in order to tell whether to render an `<a>` element.\n * \n * Requirements:\n * \n * * You must render the expected element type (e.g. if `<a>` is expected, you cannot render a `<button>`).\n * * Only a single root DOM element can be rendered (no fragments).\n * * You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.\n */\n render?: (props: DetailedHTMLProps<LinkWithRequiredHref, HTMLAnchorElement> | React.JSX.IntrinsicElements[Fallback], renderProps: T) => ReactElement\n}\n\nfunction DOMElement(ElementType: string, props: DOMRenderProps<any, any> & AllHTMLAttributes<HTMLElement>, forwardedRef: ForwardedRef<HTMLElement>) {\n let {render, ...otherProps} = props;\n let elementRef = useRef<HTMLElement | null>(null);\n let ref = useMemo(() => mergeRefs(forwardedRef, elementRef), [forwardedRef, elementRef]);\n\n useLayoutEffect(() => {\n if (process.env.NODE_ENV !== 'production' && render) {\n if (!elementRef.current) {\n console.warn('Ref was not connected to DOM element returned by custom `render` function. Did you forget to pass through or merge the `ref`?');\n } else if (elementRef.current.localName !== ElementType) {\n console.warn(`Unexpected DOM element returned by custom \\`render\\` function. Expected <${ElementType}>, got <${elementRef.current.localName}>. This may break the component behavior and accessibility.`);\n }\n }\n }, [ElementType, render]);\n\n let domProps: any = {...otherProps, ref};\n if (render) {\n return render(domProps, undefined);\n }\n\n return <ElementType {...domProps} />;\n}\n\ntype DOMComponents = {\n [E in keyof React.JSX.IntrinsicElements]: (props: DOMRenderProps<E, any> & React.JSX.IntrinsicElements[E]) => ReactElement\n};\n\nconst domComponentCache = {};\n\n// Dynamically generates and caches components for each DOM element (e.g. `dom.button`).\nexport const dom = new Proxy({}, {\n get(target, elementType) {\n if (typeof elementType !== 'string') {\n return undefined;\n }\n\n let res = domComponentCache[elementType];\n if (!res) {\n res = forwardRef(DOMElement.bind(null, elementType));\n domComponentCache[elementType] = res;\n }\n\n return res;\n }\n}) as DOMComponents;\n"],"names":[],"version":3,"file":"utils.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-aria-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "A library of styleable components built using React Aria",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -41,34 +41,34 @@
|
|
|
41
41
|
"url": "https://github.com/adobe/react-spectrum"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@internationalized/date": "^3.
|
|
44
|
+
"@internationalized/date": "^3.12.0",
|
|
45
45
|
"@internationalized/string": "^3.2.7",
|
|
46
|
-
"@react-aria/autocomplete": "3.0.0-rc.
|
|
47
|
-
"@react-aria/collections": "^3.0.
|
|
48
|
-
"@react-aria/dnd": "^3.11.
|
|
49
|
-
"@react-aria/focus": "^3.21.
|
|
50
|
-
"@react-aria/interactions": "^3.27.
|
|
46
|
+
"@react-aria/autocomplete": "3.0.0-rc.6",
|
|
47
|
+
"@react-aria/collections": "^3.0.3",
|
|
48
|
+
"@react-aria/dnd": "^3.11.6",
|
|
49
|
+
"@react-aria/focus": "^3.21.5",
|
|
50
|
+
"@react-aria/interactions": "^3.27.1",
|
|
51
51
|
"@react-aria/live-announcer": "^3.4.4",
|
|
52
|
-
"@react-aria/overlays": "^3.31.
|
|
52
|
+
"@react-aria/overlays": "^3.31.2",
|
|
53
53
|
"@react-aria/ssr": "^3.9.10",
|
|
54
|
-
"@react-aria/textfield": "^3.18.
|
|
55
|
-
"@react-aria/toolbar": "3.0.0-beta.
|
|
56
|
-
"@react-aria/utils": "^3.33.
|
|
57
|
-
"@react-aria/virtualizer": "^4.1.
|
|
54
|
+
"@react-aria/textfield": "^3.18.5",
|
|
55
|
+
"@react-aria/toolbar": "3.0.0-beta.24",
|
|
56
|
+
"@react-aria/utils": "^3.33.1",
|
|
57
|
+
"@react-aria/virtualizer": "^4.1.13",
|
|
58
58
|
"@react-stately/autocomplete": "3.0.0-beta.4",
|
|
59
|
-
"@react-stately/layout": "^4.
|
|
60
|
-
"@react-stately/selection": "^3.20.
|
|
61
|
-
"@react-stately/table": "^3.15.
|
|
59
|
+
"@react-stately/layout": "^4.6.0",
|
|
60
|
+
"@react-stately/selection": "^3.20.9",
|
|
61
|
+
"@react-stately/table": "^3.15.4",
|
|
62
62
|
"@react-stately/utils": "^3.11.0",
|
|
63
|
-
"@react-stately/virtualizer": "^4.4.
|
|
64
|
-
"@react-types/form": "^3.7.
|
|
65
|
-
"@react-types/grid": "^3.3.
|
|
66
|
-
"@react-types/shared": "^3.33.
|
|
67
|
-
"@react-types/table": "^3.13.
|
|
63
|
+
"@react-stately/virtualizer": "^4.4.6",
|
|
64
|
+
"@react-types/form": "^3.7.18",
|
|
65
|
+
"@react-types/grid": "^3.3.8",
|
|
66
|
+
"@react-types/shared": "^3.33.1",
|
|
67
|
+
"@react-types/table": "^3.13.6",
|
|
68
68
|
"@swc/helpers": "^0.5.0",
|
|
69
69
|
"client-only": "^0.0.1",
|
|
70
|
-
"react-aria": "^3.
|
|
71
|
-
"react-stately": "^3.
|
|
70
|
+
"react-aria": "^3.47.0",
|
|
71
|
+
"react-stately": "^3.45.0",
|
|
72
72
|
"use-sync-external-store": "^1.6.0"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@tailwindcss/postcss": "^4.0.0"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "8df187370053aa35f553cb388ad670f65e1ab371"
|
|
85
85
|
}
|
package/src/Button.tsx
CHANGED
|
@@ -168,11 +168,13 @@ export const Button = /*#__PURE__*/ createHideableComponent(function Button(prop
|
|
|
168
168
|
);
|
|
169
169
|
});
|
|
170
170
|
|
|
171
|
+
// Events to preserve when isPending is true (for tooltips and other overlays)
|
|
172
|
+
const PRESERVED_EVENT_PATTERN = /Focus|Blur|Hover|Pointer(Enter|Leave|Over|Out)|Mouse(Enter|Leave|Over|Out)/;
|
|
173
|
+
|
|
171
174
|
function useDisableInteractions(props, isPending) {
|
|
172
|
-
// Don't allow interaction while isPending is true
|
|
173
175
|
if (isPending) {
|
|
174
176
|
for (const key in props) {
|
|
175
|
-
if (key.startsWith('on') && !
|
|
177
|
+
if (key.startsWith('on') && !PRESERVED_EVENT_PATTERN.test(key)) {
|
|
176
178
|
props[key] = undefined;
|
|
177
179
|
}
|
|
178
180
|
}
|
package/src/Collection.tsx
CHANGED
|
@@ -159,6 +159,12 @@ function useCollectionRender(
|
|
|
159
159
|
items: parent ? collection.getChildren!(parent.key) : collection,
|
|
160
160
|
dependencies: [renderDropIndicator],
|
|
161
161
|
children(node) {
|
|
162
|
+
// Return a empty fragment since we don't want to render the content twice
|
|
163
|
+
// If we don't skip the content node here, we end up rendering them twice in a Tree since we also render the content node in TreeItem
|
|
164
|
+
if (node.type === 'content') {
|
|
165
|
+
return <></>;
|
|
166
|
+
}
|
|
167
|
+
|
|
162
168
|
let rendered = node.render!(node);
|
|
163
169
|
if (!renderDropIndicator || node.type !== 'item') {
|
|
164
170
|
return rendered;
|
package/src/ComboBox.tsx
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import {AriaComboBoxProps, useComboBox, useFilter} from 'react-aria';
|
|
12
|
+
import {AriaComboBoxProps, useComboBox, useFilter, useListFormatter} from 'react-aria';
|
|
13
13
|
import {ButtonContext} from './Button';
|
|
14
14
|
import {
|
|
15
15
|
ClassNameOrFunction,
|
|
@@ -26,20 +26,22 @@ import {
|
|
|
26
26
|
useSlottedContext
|
|
27
27
|
} from './utils';
|
|
28
28
|
import {Collection, ComboBoxState, Node, useComboBoxState} from 'react-stately';
|
|
29
|
-
import {CollectionBuilder} from '@react-aria/collections';
|
|
29
|
+
import {CollectionBuilder, createHideableComponent} from '@react-aria/collections';
|
|
30
30
|
import {FieldErrorContext} from './FieldError';
|
|
31
31
|
import {filterDOMProps, useResizeObserver} from '@react-aria/utils';
|
|
32
32
|
import {FormContext} from './Form';
|
|
33
|
-
import {forwardRefType, GlobalDOMAttributes, RefObject} from '@react-types/shared';
|
|
33
|
+
import {forwardRefType, GlobalDOMAttributes, Key, RefObject} from '@react-types/shared';
|
|
34
34
|
import {GroupContext} from './Group';
|
|
35
35
|
import {InputContext} from './Input';
|
|
36
36
|
import {LabelContext} from './Label';
|
|
37
37
|
import {ListBoxContext, ListStateContext} from './ListBox';
|
|
38
38
|
import {OverlayTriggerStateContext} from './Dialog';
|
|
39
39
|
import {PopoverContext} from './Popover';
|
|
40
|
-
import React, {createContext, ForwardedRef, forwardRef, useCallback, useMemo, useRef, useState} from 'react';
|
|
40
|
+
import React, {createContext, ForwardedRef, forwardRef, HTMLAttributes, ReactElement, ReactNode, useCallback, useContext, useMemo, useRef, useState} from 'react';
|
|
41
41
|
import {TextContext} from './Text';
|
|
42
42
|
|
|
43
|
+
type SelectionMode = 'single' | 'multiple';
|
|
44
|
+
|
|
43
45
|
export interface ComboBoxRenderProps {
|
|
44
46
|
/**
|
|
45
47
|
* Whether the combobox is currently open.
|
|
@@ -63,7 +65,7 @@ export interface ComboBoxRenderProps {
|
|
|
63
65
|
isRequired: boolean
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
export interface ComboBoxProps<T extends object> extends Omit<AriaComboBoxProps<T>, 'children' | 'placeholder' | 'label' | 'description' | 'errorMessage' | 'validationState' | 'validationBehavior'>, RACValidation, RenderProps<ComboBoxRenderProps>, SlotProps, GlobalDOMAttributes<HTMLDivElement> {
|
|
68
|
+
export interface ComboBoxProps<T extends object, M extends SelectionMode = 'single'> extends Omit<AriaComboBoxProps<T, M>, 'children' | 'placeholder' | 'label' | 'description' | 'errorMessage' | 'validationState' | 'validationBehavior'>, RACValidation, RenderProps<ComboBoxRenderProps>, SlotProps, GlobalDOMAttributes<HTMLDivElement> {
|
|
67
69
|
/**
|
|
68
70
|
* The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state.
|
|
69
71
|
* @default 'react-aria-ComboBox'
|
|
@@ -81,13 +83,13 @@ export interface ComboBoxProps<T extends object> extends Omit<AriaComboBoxProps<
|
|
|
81
83
|
allowsEmptyCollection?: boolean
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
export const ComboBoxContext = createContext<ContextValue<ComboBoxProps<any>, HTMLDivElement>>(null);
|
|
85
|
-
export const ComboBoxStateContext = createContext<ComboBoxState<any> | null>(null);
|
|
86
|
+
export const ComboBoxContext = createContext<ContextValue<ComboBoxProps<any, SelectionMode>, HTMLDivElement>>(null);
|
|
87
|
+
export const ComboBoxStateContext = createContext<ComboBoxState<any, SelectionMode> | null>(null);
|
|
86
88
|
|
|
87
89
|
/**
|
|
88
90
|
* A combo box combines a text input with a listbox, allowing users to filter a list of options to items matching a query.
|
|
89
91
|
*/
|
|
90
|
-
export const ComboBox = /*#__PURE__*/ (forwardRef as forwardRefType)(function ComboBox<T extends object>(props: ComboBoxProps<T>, ref: ForwardedRef<HTMLDivElement>) {
|
|
92
|
+
export const ComboBox = /*#__PURE__*/ (forwardRef as forwardRefType)(function ComboBox<T extends object, M extends SelectionMode = 'single'>(props: ComboBoxProps<T, M>, ref: ForwardedRef<HTMLDivElement>) {
|
|
91
93
|
[props, ref] = useContextProps(props, ref, ComboBoxContext);
|
|
92
94
|
let {children, isDisabled = false, isInvalid = false, isRequired = false} = props;
|
|
93
95
|
let content = useMemo(() => (
|
|
@@ -115,7 +117,7 @@ export const ComboBox = /*#__PURE__*/ (forwardRef as forwardRefType)(function Co
|
|
|
115
117
|
const CLEAR_CONTEXTS = [LabelContext, ButtonContext, InputContext, GroupContext, TextContext];
|
|
116
118
|
|
|
117
119
|
interface ComboBoxInnerProps<T extends object> {
|
|
118
|
-
props: ComboBoxProps<T>,
|
|
120
|
+
props: ComboBoxProps<T, SelectionMode>,
|
|
119
121
|
collection: Collection<Node<T>>,
|
|
120
122
|
comboBoxRef: RefObject<HTMLDivElement | null>
|
|
121
123
|
}
|
|
@@ -157,6 +159,7 @@ function ComboBoxInner<T extends object>({props, collection, comboBoxRef: ref}:
|
|
|
157
159
|
labelProps,
|
|
158
160
|
descriptionProps,
|
|
159
161
|
errorMessageProps,
|
|
162
|
+
valueProps,
|
|
160
163
|
...validation
|
|
161
164
|
} = useComboBox({
|
|
162
165
|
...removeDataAttributes(props),
|
|
@@ -203,6 +206,18 @@ function ComboBoxInner<T extends object>({props, collection, comboBoxRef: ref}:
|
|
|
203
206
|
let DOMProps = filterDOMProps(props, {global: true});
|
|
204
207
|
delete DOMProps.id;
|
|
205
208
|
|
|
209
|
+
let inputs: ReactElement[] = [];
|
|
210
|
+
if (name && formValue === 'key') {
|
|
211
|
+
let values: (Key | null)[] = Array.isArray(state.value) ? state.value : [state.value];
|
|
212
|
+
if (values.length === 0) {
|
|
213
|
+
values = [null];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
inputs = values.map((value, i) => (
|
|
217
|
+
<input key={i} type="hidden" name={name} form={props.form} value={value ?? ''} />
|
|
218
|
+
));
|
|
219
|
+
}
|
|
220
|
+
|
|
206
221
|
return (
|
|
207
222
|
<Provider
|
|
208
223
|
values={[
|
|
@@ -230,7 +245,8 @@ function ComboBoxInner<T extends object>({props, collection, comboBoxRef: ref}:
|
|
|
230
245
|
}
|
|
231
246
|
}],
|
|
232
247
|
[GroupContext, {isInvalid: validation.isInvalid, isDisabled: props.isDisabled || false}],
|
|
233
|
-
[FieldErrorContext, validation]
|
|
248
|
+
[FieldErrorContext, validation],
|
|
249
|
+
[ComboBoxValueContext, valueProps]
|
|
234
250
|
]}>
|
|
235
251
|
<dom.div
|
|
236
252
|
{...DOMProps}
|
|
@@ -241,8 +257,69 @@ function ComboBoxInner<T extends object>({props, collection, comboBoxRef: ref}:
|
|
|
241
257
|
data-open={state.isOpen || undefined}
|
|
242
258
|
data-disabled={props.isDisabled || undefined}
|
|
243
259
|
data-invalid={validation.isInvalid || undefined}
|
|
244
|
-
data-required={props.isRequired || undefined}
|
|
245
|
-
|
|
260
|
+
data-required={props.isRequired || undefined}>
|
|
261
|
+
{renderProps.children}
|
|
262
|
+
{inputs}
|
|
263
|
+
</dom.div>
|
|
246
264
|
</Provider>
|
|
247
265
|
);
|
|
248
266
|
}
|
|
267
|
+
|
|
268
|
+
export interface ComboBoxValueRenderProps<T> {
|
|
269
|
+
/**
|
|
270
|
+
* Whether the value is a placeholder.
|
|
271
|
+
* @selector [data-placeholder]
|
|
272
|
+
*/
|
|
273
|
+
isPlaceholder: boolean,
|
|
274
|
+
/** The object values of the currently selected items. */
|
|
275
|
+
selectedItems: (T | null)[],
|
|
276
|
+
/** The textValue of the currently selected items. */
|
|
277
|
+
selectedText: string,
|
|
278
|
+
/** The state of the ComboBox. */
|
|
279
|
+
state: ComboBoxState<T, 'single' | 'multiple'>
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export interface ComboBoxValueProps<T extends object> extends Omit<HTMLAttributes<HTMLElement>, keyof RenderProps<unknown>>, RenderProps<ComboBoxValueRenderProps<T>, 'div'> {
|
|
283
|
+
/**
|
|
284
|
+
* The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state.
|
|
285
|
+
* @default 'react-aria-ComboBoxValue'
|
|
286
|
+
*/
|
|
287
|
+
className?: ClassNameOrFunction<ComboBoxValueRenderProps<T>>,
|
|
288
|
+
/** A value to display when no items are selected. */
|
|
289
|
+
placeholder?: ReactNode
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export const ComboBoxValueContext = createContext<ContextValue<ComboBoxValueProps<any>, HTMLDivElement>>(null);
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* ComboBoxValue renders the selected values of a ComboBox, or a placeholder if no value is selected.
|
|
296
|
+
* By default, the items are rendered as a comma separated list. Use the render function to customize this.
|
|
297
|
+
*/
|
|
298
|
+
export const ComboBoxValue = /*#__PURE__*/ createHideableComponent(function ComboBoxValue<T extends object>(props: ComboBoxValueProps<T>, ref: ForwardedRef<HTMLDivElement>) {
|
|
299
|
+
[props, ref] = useContextProps(props, ref, ComboBoxValueContext);
|
|
300
|
+
let state = useContext(ComboBoxStateContext)!;
|
|
301
|
+
let formatter = useListFormatter();
|
|
302
|
+
let selectedText = useMemo(() => formatter.format(state.selectedItems.map(item => item?.textValue || '').filter(v => v !== '')), [formatter, state.selectedItems]);
|
|
303
|
+
|
|
304
|
+
let renderProps = useRenderProps({
|
|
305
|
+
...props,
|
|
306
|
+
defaultChildren: selectedText || props.placeholder,
|
|
307
|
+
defaultClassName: 'react-aria-ComboBoxValue',
|
|
308
|
+
values: {
|
|
309
|
+
selectedItems: useMemo(() => state.selectedItems.map(item => item.value as T ?? null), [state.selectedItems]),
|
|
310
|
+
selectedText,
|
|
311
|
+
isPlaceholder: state.selectedItems.length === 0,
|
|
312
|
+
state
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
let DOMProps = filterDOMProps(props, {global: true});
|
|
317
|
+
|
|
318
|
+
return (
|
|
319
|
+
<dom.div
|
|
320
|
+
ref={ref}
|
|
321
|
+
{...DOMProps}
|
|
322
|
+
{...renderProps}
|
|
323
|
+
data-placeholder={state.selectedItems.length === 0 || undefined} />
|
|
324
|
+
);
|
|
325
|
+
});
|
package/src/DateField.tsx
CHANGED
|
@@ -57,7 +57,12 @@ export interface DateFieldRenderProps {
|
|
|
57
57
|
* Whether the date field is read only.
|
|
58
58
|
* @selector [data-readonly]
|
|
59
59
|
*/
|
|
60
|
-
isReadOnly: boolean
|
|
60
|
+
isReadOnly: boolean,
|
|
61
|
+
/**
|
|
62
|
+
* Whether the date field is required.
|
|
63
|
+
* @selector [data-required]
|
|
64
|
+
*/
|
|
65
|
+
isRequired: boolean
|
|
61
66
|
}
|
|
62
67
|
export interface DateFieldProps<T extends DateValue> extends Omit<AriaDateFieldProps<T>, 'label' | 'description' | 'errorMessage' | 'validationState' | 'validationBehavior'>, RACValidation, RenderProps<DateFieldRenderProps>, SlotProps, GlobalDOMAttributes<HTMLDivElement> {
|
|
63
68
|
/**
|
|
@@ -113,7 +118,8 @@ export const DateField = /*#__PURE__*/ (forwardRef as forwardRefType)(function D
|
|
|
113
118
|
state,
|
|
114
119
|
isInvalid: state.isInvalid,
|
|
115
120
|
isDisabled: state.isDisabled,
|
|
116
|
-
isReadOnly: state.isReadOnly
|
|
121
|
+
isReadOnly: state.isReadOnly,
|
|
122
|
+
isRequired: props.isRequired || false
|
|
117
123
|
},
|
|
118
124
|
defaultClassName: 'react-aria-DateField'
|
|
119
125
|
});
|
|
@@ -143,7 +149,8 @@ export const DateField = /*#__PURE__*/ (forwardRef as forwardRefType)(function D
|
|
|
143
149
|
slot={props.slot || undefined}
|
|
144
150
|
data-invalid={state.isInvalid || undefined}
|
|
145
151
|
data-disabled={state.isDisabled || undefined}
|
|
146
|
-
data-readonly={state.isReadOnly || undefined}
|
|
152
|
+
data-readonly={state.isReadOnly || undefined}
|
|
153
|
+
data-required={props.isRequired || undefined} />
|
|
147
154
|
<HiddenDateInput
|
|
148
155
|
autoComplete={props.autoComplete}
|
|
149
156
|
name={props.name}
|
|
@@ -186,7 +193,8 @@ export const TimeField = /*#__PURE__*/ (forwardRef as forwardRefType)(function T
|
|
|
186
193
|
state,
|
|
187
194
|
isInvalid: state.isInvalid,
|
|
188
195
|
isDisabled: state.isDisabled,
|
|
189
|
-
isReadOnly: state.isReadOnly
|
|
196
|
+
isReadOnly: state.isReadOnly,
|
|
197
|
+
isRequired: props.isRequired || false
|
|
190
198
|
},
|
|
191
199
|
defaultClassName: 'react-aria-TimeField'
|
|
192
200
|
});
|
|
@@ -216,7 +224,8 @@ export const TimeField = /*#__PURE__*/ (forwardRef as forwardRefType)(function T
|
|
|
216
224
|
slot={props.slot || undefined}
|
|
217
225
|
data-invalid={state.isInvalid || undefined}
|
|
218
226
|
data-disabled={state.isDisabled || undefined}
|
|
219
|
-
data-readonly={state.isReadOnly || undefined}
|
|
227
|
+
data-readonly={state.isReadOnly || undefined}
|
|
228
|
+
data-required={props.isRequired || undefined} />
|
|
220
229
|
</Provider>
|
|
221
230
|
);
|
|
222
231
|
});
|
package/src/DatePicker.tsx
CHANGED
|
@@ -66,6 +66,11 @@ export interface DatePickerRenderProps {
|
|
|
66
66
|
* @selector [data-invalid]
|
|
67
67
|
*/
|
|
68
68
|
isInvalid: boolean,
|
|
69
|
+
/**
|
|
70
|
+
* Whether the date picker is required.
|
|
71
|
+
* @selector [data-required]
|
|
72
|
+
*/
|
|
73
|
+
isRequired: boolean,
|
|
69
74
|
/**
|
|
70
75
|
* Whether the date picker's popover is currently open.
|
|
71
76
|
* @selector [data-open]
|
|
@@ -161,7 +166,8 @@ export const DatePicker = /*#__PURE__*/ (forwardRef as forwardRefType)(function
|
|
|
161
166
|
isDisabled: props.isDisabled || false,
|
|
162
167
|
isInvalid: state.isInvalid,
|
|
163
168
|
isOpen: state.isOpen,
|
|
164
|
-
isReadOnly: props.isReadOnly || false
|
|
169
|
+
isReadOnly: props.isReadOnly || false,
|
|
170
|
+
isRequired: props.isRequired || false
|
|
165
171
|
},
|
|
166
172
|
defaultClassName: 'react-aria-DatePicker'
|
|
167
173
|
});
|
|
@@ -204,6 +210,7 @@ export const DatePicker = /*#__PURE__*/ (forwardRef as forwardRefType)(function
|
|
|
204
210
|
data-focus-visible={isFocusVisible || undefined}
|
|
205
211
|
data-disabled={props.isDisabled || undefined}
|
|
206
212
|
data-readonly={props.isReadOnly || undefined}
|
|
213
|
+
data-required={props.isRequired || undefined}
|
|
207
214
|
data-open={state.isOpen || undefined} />
|
|
208
215
|
<HiddenDateInput
|
|
209
216
|
autoComplete={props.autoComplete}
|
|
@@ -271,7 +278,8 @@ export const DateRangePicker = /*#__PURE__*/ (forwardRef as forwardRefType)(func
|
|
|
271
278
|
isDisabled: props.isDisabled || false,
|
|
272
279
|
isInvalid: state.isInvalid,
|
|
273
280
|
isOpen: state.isOpen,
|
|
274
|
-
isReadOnly: props.isReadOnly || false
|
|
281
|
+
isReadOnly: props.isReadOnly || false,
|
|
282
|
+
isRequired: props.isRequired || false
|
|
275
283
|
},
|
|
276
284
|
defaultClassName: 'react-aria-DateRangePicker'
|
|
277
285
|
});
|
|
@@ -319,6 +327,7 @@ export const DateRangePicker = /*#__PURE__*/ (forwardRef as forwardRefType)(func
|
|
|
319
327
|
data-focus-visible={isFocusVisible || undefined}
|
|
320
328
|
data-disabled={props.isDisabled || undefined}
|
|
321
329
|
data-readonly={props.isReadOnly || undefined}
|
|
330
|
+
data-required={props.isRequired || undefined}
|
|
322
331
|
data-open={state.isOpen || undefined} />
|
|
323
332
|
</Provider>
|
|
324
333
|
);
|
package/src/DropZone.tsx
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
useRenderProps
|
|
23
23
|
} from './utils';
|
|
24
24
|
import {DropOptions, mergeProps, useButton, useClipboard, useDrop, useFocusRing, useHover, useLocalizedStringFormatter, VisuallyHidden} from 'react-aria';
|
|
25
|
-
import {filterDOMProps, isFocusable, nodeContains, useLabels, useObjectRef, useSlotId} from '@react-aria/utils';
|
|
25
|
+
import {filterDOMProps, getEventTarget, isFocusable, nodeContains, useLabels, useObjectRef, useSlotId} from '@react-aria/utils';
|
|
26
26
|
// @ts-ignore
|
|
27
27
|
import intlMessages from '../intl/*.json';
|
|
28
28
|
import React, {createContext, ForwardedRef, forwardRef, useRef} from 'react';
|
|
@@ -116,7 +116,7 @@ export const DropZone = forwardRef(function DropZone(props: DropZoneProps, ref:
|
|
|
116
116
|
slot={props.slot || undefined}
|
|
117
117
|
ref={dropzoneRef}
|
|
118
118
|
onClick={(e) => {
|
|
119
|
-
let target = e
|
|
119
|
+
let target = getEventTarget(e) as HTMLElement | null;
|
|
120
120
|
while (target && nodeContains(dropzoneRef.current, target)) {
|
|
121
121
|
if (isFocusable(target)) {
|
|
122
122
|
break;
|
package/src/FileTrigger.tsx
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {filterDOMProps, useObjectRef} from '@react-aria/utils';
|
|
13
|
+
import {filterDOMProps, getEventTarget, useObjectRef} from '@react-aria/utils';
|
|
14
14
|
import {GlobalDOMAttributes} from '@react-types/shared';
|
|
15
15
|
import {Input} from './Input';
|
|
16
16
|
import {PressResponder} from '@react-aria/interactions';
|
|
@@ -69,7 +69,7 @@ export const FileTrigger = forwardRef(function FileTrigger(props: FileTriggerPro
|
|
|
69
69
|
ref={inputRef}
|
|
70
70
|
style={{display: 'none'}}
|
|
71
71
|
accept={acceptedFileTypes?.toString()}
|
|
72
|
-
onChange={(e) => onSelect?.(e.
|
|
72
|
+
onChange={(e) => onSelect?.(getEventTarget(e).files)}
|
|
73
73
|
capture={defaultCamera}
|
|
74
74
|
multiple={allowsMultiple}
|
|
75
75
|
// @ts-expect-error
|
package/src/GridList.tsx
CHANGED
|
@@ -289,7 +289,14 @@ function GridListInner<T extends object>({props, collection, gridListRef: ref}:
|
|
|
289
289
|
);
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
export interface GridListItemRenderProps extends ItemRenderProps {
|
|
292
|
+
export interface GridListItemRenderProps extends ItemRenderProps {
|
|
293
|
+
/** The unique id of the item. */
|
|
294
|
+
id?: Key,
|
|
295
|
+
/**
|
|
296
|
+
* State of the grid list.
|
|
297
|
+
*/
|
|
298
|
+
state: ListState<unknown>
|
|
299
|
+
}
|
|
293
300
|
|
|
294
301
|
export interface GridListItemProps<T = object> extends RenderProps<GridListItemRenderProps>, LinkDOMProps, HoverEvents, PressEvents, Omit<GlobalDOMAttributes<HTMLDivElement>, 'onClick'> {
|
|
295
302
|
/**
|
|
@@ -373,7 +380,9 @@ export const GridListItem = /*#__PURE__*/ createLeafComponent(ItemNode, function
|
|
|
373
380
|
selectionBehavior: state.selectionManager.selectionBehavior,
|
|
374
381
|
allowsDragging: !!dragState,
|
|
375
382
|
isDragging,
|
|
376
|
-
isDropTarget: dropIndicator?.isDropTarget
|
|
383
|
+
isDropTarget: dropIndicator?.isDropTarget,
|
|
384
|
+
id: item.key,
|
|
385
|
+
state
|
|
377
386
|
}
|
|
378
387
|
});
|
|
379
388
|
|
|
@@ -653,7 +662,7 @@ export const GridListSection = /*#__PURE__*/ createBranchComponent(SectionNode,
|
|
|
653
662
|
export interface GridListHeaderProps extends DOMRenderProps<'div', undefined>, DOMProps, GlobalDOMAttributes<HTMLElement> {}
|
|
654
663
|
|
|
655
664
|
export const GridListHeaderContext = createContext<ContextValue<GridListHeaderProps, HTMLDivElement>>({});
|
|
656
|
-
const GridListHeaderInnerContext = createContext<HTMLAttributes<HTMLElement> | null>(null);
|
|
665
|
+
export const GridListHeaderInnerContext = createContext<HTMLAttributes<HTMLElement> | null>(null);
|
|
657
666
|
|
|
658
667
|
export const GridListHeader = /*#__PURE__*/ createLeafComponent(HeaderNode, function Header(props: GridListHeaderProps, ref: ForwardedRef<HTMLDivElement>) {
|
|
659
668
|
[props, ref] = useContextProps(props, ref, GridListHeaderContext);
|
package/src/HiddenDateInput.tsx
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import {CalendarDate, CalendarDateTime, parseDate, parseDateTime, toCalendarDate, toCalendarDateTime, toLocalTimeZone} from '@internationalized/date';
|
|
15
15
|
import {DateFieldState, DatePickerState, DateSegmentType} from 'react-stately';
|
|
16
|
+
import {getEventTarget} from '@react-aria/utils';
|
|
16
17
|
import React, {ReactNode} from 'react';
|
|
17
18
|
import {useVisuallyHidden} from 'react-aria';
|
|
18
19
|
|
|
@@ -105,7 +106,7 @@ export function useHiddenDateInput(props: HiddenDateInputProps, state: DateField
|
|
|
105
106
|
step: inputStep,
|
|
106
107
|
value: dateValue,
|
|
107
108
|
onChange: (e) => {
|
|
108
|
-
let targetString = e.
|
|
109
|
+
let targetString = getEventTarget(e).value.toString();
|
|
109
110
|
if (targetString) {
|
|
110
111
|
try {
|
|
111
112
|
let targetValue: CalendarDateTime | CalendarDate = parseDateTime(targetString);
|
package/src/Keyboard.tsx
CHANGED
|
@@ -15,9 +15,9 @@ import React, {createContext, ForwardedRef, forwardRef, HTMLAttributes} from 're
|
|
|
15
15
|
|
|
16
16
|
export interface KeyboardProps extends HTMLAttributes<HTMLElement>, DOMRenderProps<'kbd', undefined> {}
|
|
17
17
|
|
|
18
|
-
export const KeyboardContext = createContext<ContextValue<
|
|
18
|
+
export const KeyboardContext = createContext<ContextValue<KeyboardProps, HTMLElement>>({});
|
|
19
19
|
|
|
20
|
-
export const Keyboard = forwardRef(function Keyboard(props:
|
|
20
|
+
export const Keyboard = forwardRef(function Keyboard(props: KeyboardProps, ref: ForwardedRef<HTMLElement>) {
|
|
21
21
|
[props, ref] = useContextProps(props, ref, KeyboardContext);
|
|
22
22
|
return <dom.kbd dir="ltr" {...props} ref={ref} />;
|
|
23
23
|
});
|
package/src/ListBox.tsx
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {AriaListBoxOptions, AriaListBoxProps, DraggableItemResult, DragPreviewRenderer, DroppableCollectionResult, DroppableItemResult, FocusScope, ListKeyboardDelegate, mergeProps, useCollator, useFocus, useFocusRing, useHover, useListBox, useListBoxSection, useLocale, useOption} from 'react-aria';
|
|
13
|
+
import {AriaListBoxOptions, AriaListBoxProps, DraggableItemResult, DragPreviewRenderer, DroppableCollectionResult, DroppableItemResult, FocusScope, ListKeyboardDelegate, mergeProps, useCollator, useFocus, useFocusRing, useHover, useKeyboard, useListBox, useListBoxSection, useLocale, useOption} from 'react-aria';
|
|
14
14
|
import {
|
|
15
15
|
ClassNameOrFunction,
|
|
16
16
|
ContextValue,
|
|
@@ -33,7 +33,7 @@ import {DragAndDropContext, DropIndicatorContext, DropIndicatorProps, useDndPers
|
|
|
33
33
|
import {DragAndDropHooks} from './useDragAndDrop';
|
|
34
34
|
import {DraggableCollectionState, DroppableCollectionState, ListState, Node, Orientation, SelectionBehavior, UNSTABLE_useFilteredListState, useListState} from 'react-stately';
|
|
35
35
|
import {filterDOMProps, inertValue, LoadMoreSentinelProps, useLoadMoreSentinel, useObjectRef} from '@react-aria/utils';
|
|
36
|
-
import {FocusEvents, forwardRefType, GlobalDOMAttributes, HoverEvents, Key, LinkDOMProps, PressEvents, RefObject} from '@react-types/shared';
|
|
36
|
+
import {FocusEvents, forwardRefType, GlobalDOMAttributes, HoverEvents, Key, KeyboardEvents, LinkDOMProps, PressEvents, RefObject} from '@react-types/shared';
|
|
37
37
|
import {HeaderContext} from './Header';
|
|
38
38
|
import React, {createContext, ForwardedRef, forwardRef, JSX, ReactNode, useContext, useEffect, useMemo, useRef} from 'react';
|
|
39
39
|
import {SelectableCollectionContext, SelectableCollectionContextValue} from './RSPContexts';
|
|
@@ -340,7 +340,7 @@ export const ListBoxSection = /*#__PURE__*/ createBranchComponent(SectionNode, L
|
|
|
340
340
|
|
|
341
341
|
export interface ListBoxItemRenderProps extends ItemRenderProps {}
|
|
342
342
|
|
|
343
|
-
export interface ListBoxItemProps<T = object> extends Omit<RenderProps<ListBoxItemRenderProps>, 'render'>, PossibleLinkDOMRenderProps<'div', ListBoxItemRenderProps>, LinkDOMProps, HoverEvents, PressEvents, FocusEvents<HTMLDivElement>, Omit<GlobalDOMAttributes<HTMLDivElement>, 'onClick'> {
|
|
343
|
+
export interface ListBoxItemProps<T = object> extends Omit<RenderProps<ListBoxItemRenderProps>, 'render'>, PossibleLinkDOMRenderProps<'div', ListBoxItemRenderProps>, LinkDOMProps, HoverEvents, PressEvents, KeyboardEvents, FocusEvents<HTMLDivElement>, Omit<GlobalDOMAttributes<HTMLDivElement>, 'onClick'> {
|
|
344
344
|
/**
|
|
345
345
|
* The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state.
|
|
346
346
|
* @default 'react-aria-ListBoxItem'
|
|
@@ -383,6 +383,7 @@ export const ListBoxItem = /*#__PURE__*/ createLeafComponent(ItemNode, function
|
|
|
383
383
|
onHoverEnd: item.props.onHoverEnd
|
|
384
384
|
});
|
|
385
385
|
|
|
386
|
+
let {keyboardProps} = useKeyboard(props);
|
|
386
387
|
let {focusProps} = useFocus(props);
|
|
387
388
|
|
|
388
389
|
let draggableItem: DraggableItemResult | null = null;
|
|
@@ -431,7 +432,7 @@ export const ListBoxItem = /*#__PURE__*/ createLeafComponent(ItemNode, function
|
|
|
431
432
|
|
|
432
433
|
return (
|
|
433
434
|
<ElementType
|
|
434
|
-
{...mergeProps(DOMProps, renderProps, optionProps, hoverProps, focusProps, draggableItem?.dragProps, droppableItem?.dropProps)}
|
|
435
|
+
{...mergeProps(DOMProps, renderProps, optionProps, hoverProps, keyboardProps, focusProps, draggableItem?.dragProps, droppableItem?.dropProps)}
|
|
435
436
|
ref={ref}
|
|
436
437
|
data-allows-dragging={!!dragState || undefined}
|
|
437
438
|
data-selected={states.isSelected || undefined}
|