Skip to content

Commit 8bd923f

Browse files
committed
Merge branch 'main' of github.com:adobe/react-spectrum into loadmore_rac
2 parents 935e439 + 2a2d571 commit 8bd923f

File tree

95 files changed

+2511
-3041
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+2511
-3041
lines changed

packages/@react-aria/collections/src/CollectionBuilder.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ function useSSRCollectionNode<T extends Element>(Type: string, props: object, re
157157
return <Type ref={itemRef}>{children}</Type>;
158158
}
159159

160-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactNode;
161-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactNode;
162-
export function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactElement): (props: P & React.RefAttributes<any>) => ReactNode {
160+
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactElement | null;
161+
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactElement | null;
162+
export function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactElement): (props: P & React.RefAttributes<any>) => ReactElement | null {
163163
let Component = ({node}) => render(node.props, node.props.ref, node);
164164
let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {
165165
let focusableProps = useContext(FocusableContext);
@@ -190,7 +190,7 @@ export function createLeafComponent<P extends object, E extends Element>(type: s
190190
return Result;
191191
}
192192

193-
export function createBranchComponent<T extends object, P extends {children?: any}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement, useChildren: (props: P) => ReactNode = useCollectionChildren): (props: P & React.RefAttributes<E>) => ReactNode {
193+
export function createBranchComponent<T extends object, P extends {children?: any}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement, useChildren: (props: P) => ReactNode = useCollectionChildren): (props: P & React.RefAttributes<E>) => ReactElement | null {
194194
let Component = ({node}) => render(node.props, node.props.ref, node);
195195
let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {
196196
let children = useChildren(props);

packages/@react-aria/collections/src/Hidden.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import {forwardRefType} from '@react-types/shared';
14-
import React, {createContext, forwardRef, ReactElement, ReactNode, useContext} from 'react';
14+
import React, {createContext, forwardRef, JSX, ReactElement, ReactNode, useContext} from 'react';
1515

1616
// React doesn't understand the <template> element, which doesn't have children like a normal element.
1717
// It will throw an error during hydration when it expects the firstChild to contain content rendered
@@ -35,7 +35,7 @@ if (typeof HTMLTemplateElement !== 'undefined') {
3535

3636
export const HiddenContext = createContext<boolean>(false);
3737

38-
export function Hidden(props: {children: ReactNode}): ReactNode {
38+
export function Hidden(props: {children: ReactNode}): JSX.Element {
3939
let isHidden = useContext(HiddenContext);
4040
if (isHidden) {
4141
// Don't hide again if we are already hidden.

packages/@react-aria/focus/src/FocusRing.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import clsx from 'clsx';
1414
import {mergeProps} from '@react-aria/utils';
15-
import React, {ReactElement, ReactNode} from 'react';
15+
import React, {ReactElement} from 'react';
1616
import {useFocusRing} from './useFocusRing';
1717

1818
export interface FocusRingProps {
@@ -40,7 +40,7 @@ export interface FocusRingProps {
4040
* Focus rings are visible only when the user is interacting with a keyboard,
4141
* not with a mouse, touch, or other input methods.
4242
*/
43-
export function FocusRing(props: FocusRingProps): ReactNode {
43+
export function FocusRing(props: FocusRingProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>> {
4444
let {children, focusClass, focusRingClass} = props;
4545
let {isFocused, isFocusVisible, focusProps} = useFocusRing(props);
4646
let child = React.Children.only(children);

packages/@react-aria/i18n/src/context.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import {isRTL} from './utils';
1414
import {Locale, useDefaultLocale} from './useDefaultLocale';
15-
import React, {ReactNode, useContext} from 'react';
15+
import React, {JSX, ReactNode, useContext} from 'react';
1616

1717
export interface I18nProviderProps {
1818
/** Contents that should have the locale applied. */
@@ -26,7 +26,7 @@ const I18nContext = React.createContext<Locale | null>(null);
2626
/**
2727
* Provides the locale for the application to all child components.
2828
*/
29-
export function I18nProvider(props: I18nProviderProps): ReactNode {
29+
export function I18nProvider(props: I18nProviderProps): JSX.Element {
3030
let {locale, children} = props;
3131
let defaultLocale = useDefaultLocale();
3232

packages/@react-aria/i18n/src/server.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import type {LocalizedString} from '@internationalized/string';
14-
import React, {ReactNode} from 'react';
14+
import React, {JSX} from 'react';
1515

1616
type PackageLocalizedStrings = {
1717
[packageName: string]: Record<string, LocalizedString>
@@ -27,7 +27,7 @@ interface PackageLocalizationProviderProps {
2727
* A PackageLocalizationProvider can be rendered on the server to inject the localized strings
2828
* needed by the client into the initial HTML.
2929
*/
30-
export function PackageLocalizationProvider(props: PackageLocalizationProviderProps): ReactNode | null {
30+
export function PackageLocalizationProvider(props: PackageLocalizationProviderProps): JSX.Element | null {
3131
if (typeof document !== 'undefined') {
3232
console.log('PackageLocalizationProvider should only be rendered on the server.');
3333
return null;

packages/@react-aria/interactions/src/PressResponder.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {FocusableElement} from '@react-types/shared';
1414
import {mergeProps, useObjectRef, useSyncRef} from '@react-aria/utils';
1515
import {PressProps} from './usePress';
1616
import {PressResponderContext} from './context';
17-
import React, {ForwardedRef, ReactNode, useContext, useEffect, useMemo, useRef} from 'react';
17+
import React, {ForwardedRef, JSX, ReactNode, useContext, useEffect, useMemo, useRef} from 'react';
1818

1919
interface PressResponderProps extends PressProps {
2020
children: ReactNode
@@ -56,7 +56,7 @@ export const PressResponder = React.forwardRef(({children, ...props}: PressRespo
5656
);
5757
});
5858

59-
export function ClearPressResponder({children}: {children: ReactNode}): ReactNode {
59+
export function ClearPressResponder({children}: {children: ReactNode}): JSX.Element {
6060
let context = useMemo(() => ({register: () => {}}), []);
6161
return (
6262
<PressResponderContext.Provider value={context}>

packages/@react-aria/interactions/src/usePress.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class PressEvent implements IPressEvent {
157157
}
158158

159159
const LINK_CLICKED = Symbol('linkClicked');
160+
const STYLE_ID = 'react-aria-pressable-style';
161+
const PRESSABLE_ATTRIBUTE = 'data-react-aria-pressable';
160162

161163
/**
162164
* Handles press interactions across mouse, touch, keyboard, and screen readers.
@@ -815,17 +817,28 @@ export function usePress(props: PressHookProps): PressResult {
815817

816818
// Avoid onClick delay for double tap to zoom by default.
817819
useEffect(() => {
818-
let element = domRef?.current;
819-
if (element && (element instanceof getOwnerWindow(element).Element)) {
820-
// Only apply touch-action if not already set by another CSS rule.
821-
let style = getOwnerWindow(element).getComputedStyle(element);
822-
if (style.touchAction === 'auto') {
823-
// touchAction: 'manipulation' is supposed to be equivalent, but in
824-
// Safari it causes onPointerCancel not to fire on scroll.
825-
// https://bugs.webkit.org/show_bug.cgi?id=240917
826-
(element as HTMLElement).style.touchAction = 'pan-x pan-y pinch-zoom';
827-
}
820+
if (!domRef || process.env.NODE_ENV === 'test') {
821+
return;
822+
}
823+
824+
const ownerDocument = getOwnerDocument(domRef.current);
825+
if (!ownerDocument || !ownerDocument.head || ownerDocument.getElementById(STYLE_ID)) {
826+
return;
828827
}
828+
829+
const style = ownerDocument.createElement('style');
830+
style.id = STYLE_ID;
831+
// touchAction: 'manipulation' is supposed to be equivalent, but in
832+
// Safari it causes onPointerCancel not to fire on scroll.
833+
// https://bugs.webkit.org/show_bug.cgi?id=240917
834+
style.textContent = `
835+
@layer {
836+
[${PRESSABLE_ATTRIBUTE}] {
837+
touch-action: pan-x pan-y pinch-zoom;
838+
}
839+
}
840+
`.trim();
841+
ownerDocument.head.prepend(style);
829842
}, [domRef]);
830843

831844
// Remove user-select: none in case component unmounts immediately after pressStart
@@ -844,7 +857,7 @@ export function usePress(props: PressHookProps): PressResult {
844857

845858
return {
846859
isPressed: isPressedProp || isPressed,
847-
pressProps: mergeProps(domProps, pressProps)
860+
pressProps: mergeProps(domProps, pressProps, {[PRESSABLE_ATTRIBUTE]: true})
848861
};
849862
}
850863

packages/@react-aria/overlays/src/DismissButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import {AriaLabelingProps, DOMProps} from '@react-types/shared';
1414
// @ts-ignore
1515
import intlMessages from '../intl/*.json';
16-
import React, {ReactNode} from 'react';
16+
import React, {JSX} from 'react';
1717
import {useLabels} from '@react-aria/utils';
1818
import {useLocalizedStringFormatter} from '@react-aria/i18n';
1919
import {VisuallyHidden} from '@react-aria/visually-hidden';
@@ -28,7 +28,7 @@ export interface DismissButtonProps extends AriaLabelingProps, DOMProps {
2828
* users to dismiss a modal or popup when there is no visual
2929
* affordance to do so.
3030
*/
31-
export function DismissButton(props: DismissButtonProps): ReactNode {
31+
export function DismissButton(props: DismissButtonProps): JSX.Element {
3232
let {onDismiss, ...otherProps} = props;
3333
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/overlays');
3434

packages/@react-aria/overlays/src/Overlay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const OverlayContext = React.createContext<{contain: boolean, setContain:
4949
* A container which renders an overlay such as a popover or modal in a portal,
5050
* and provides a focus scope for the child elements.
5151
*/
52-
export function Overlay(props: OverlayProps): ReactNode | null {
52+
export function Overlay(props: OverlayProps): React.ReactPortal | null {
5353
let isSSR = useIsSSR();
5454
let {portalContainer = isSSR ? null : document.body, isExiting} = props;
5555
let [contain, setContain] = useState(false);

packages/@react-aria/overlays/src/PortalProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import React, {createContext, ReactNode, useContext} from 'react';
13+
import React, {createContext, JSX, ReactNode, useContext} from 'react';
1414

1515
export interface PortalProviderProps {
1616
/** Should return the element where we should portal to. Can clear the context by passing null. */
@@ -26,7 +26,7 @@ export const PortalContext = createContext<PortalProviderContextValue>({});
2626
/**
2727
* Sets the portal container for all overlay elements rendered by its children.
2828
*/
29-
export function UNSAFE_PortalProvider(props: PortalProviderProps): ReactNode {
29+
export function UNSAFE_PortalProvider(props: PortalProviderProps): JSX.Element {
3030
let {getContainer} = props;
3131
let {getContainer: ctxGetContainer} = useUNSAFE_PortalContext();
3232
return (

0 commit comments

Comments
 (0)