Skip to content

Commit d30ec97

Browse files
authored
docs: Assorted fixes (#9271)
1 parent f9c6eec commit d30ec97

File tree

166 files changed

+784
-849
lines changed

Some content is hidden

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

166 files changed

+784
-849
lines changed

packages/@react-aria/autocomplete/src/useAutocomplete.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {AriaTextFieldProps} from '@react-aria/textfield';
1515
import {AutocompleteProps, AutocompleteState} from '@react-stately/autocomplete';
1616
import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, getActiveElement, getOwnerDocument, isAndroid, isCtrlKeyPressed, isIOS, mergeProps, mergeRefs, useEffectEvent, useEvent, useId, useLabels, useLayoutEffect, useObjectRef} from '@react-aria/utils';
1717
import {dispatchVirtualBlur, dispatchVirtualFocus, getVirtuallyFocusedElement, moveVirtualFocus} from '@react-aria/focus';
18-
import {getInteractionModality} from '@react-aria/interactions';
18+
import {getInteractionModality, getPointerType} from '@react-aria/interactions';
1919
// @ts-ignore
2020
import intlMessages from '../intl/*.json';
2121
import {FocusEvent as ReactFocusEvent, KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect, useMemo, useRef, useState} from 'react';
@@ -92,7 +92,6 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
9292
let timeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
9393
let delayNextActiveDescendant = useRef(false);
9494
let queuedActiveDescendant = useRef<string | null>(null);
95-
let lastPointerType = useRef<string | null>(null);
9695

9796
// For mobile screen readers, we don't want virtual focus, instead opting to disable FocusScope's restoreFocus and manually
9897
// moving focus back to the subtriggers
@@ -106,23 +105,10 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
106105
return () => clearTimeout(timeout.current);
107106
}, []);
108107

109-
useEffect(() => {
110-
let handlePointerDown = (e: PointerEvent) => {
111-
lastPointerType.current = e.pointerType;
112-
};
113-
114-
if (typeof PointerEvent !== 'undefined') {
115-
document.addEventListener('pointerdown', handlePointerDown, true);
116-
return () => {
117-
document.removeEventListener('pointerdown', handlePointerDown, true);
118-
};
119-
}
120-
}, []);
121-
122108
let updateActiveDescendantEvent = useEffectEvent((e: Event) => {
123109
// Ensure input is focused if the user clicks on the collection directly.
124110
// don't trigger on touch so that mobile keyboard doesnt appear when tapping on options
125-
if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) !== inputRef.current && lastPointerType.current !== 'touch') {
111+
if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) !== inputRef.current && getPointerType() !== 'touch') {
126112
inputRef.current.focus();
127113
}
128114

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export {
1717
isFocusVisible,
1818
getInteractionModality,
1919
setInteractionModality,
20+
getPointerType,
2021
addWindowFocusTracking,
2122
useInteractionModality,
2223
useFocusVisible,

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import {getOwnerDocument, getOwnerWindow, isMac, isVirtualClick, openLink} from '@react-aria/utils';
1919
import {ignoreFocusEvent} from './utils';
20+
import {PointerType} from '@react-types/shared';
2021
import {useEffect, useState} from 'react';
2122
import {useIsSSR} from '@react-aria/ssr';
2223

@@ -37,6 +38,7 @@ export interface FocusVisibleResult {
3738
}
3839

3940
let currentModality: null | Modality = null;
41+
let currentPointerType: PointerType = 'keyboard';
4042
let changeHandlers = new Set<Handler>();
4143
interface GlobalListenerData {
4244
focus: () => void
@@ -70,12 +72,14 @@ function handleKeyboardEvent(e: KeyboardEvent) {
7072
hasEventBeforeFocus = true;
7173
if (!(openLink as any).isOpening && isValidKey(e)) {
7274
currentModality = 'keyboard';
75+
currentPointerType = 'keyboard';
7376
triggerChangeHandlers('keyboard', e);
7477
}
7578
}
7679

7780
function handlePointerEvent(e: PointerEvent | MouseEvent) {
7881
currentModality = 'pointer';
82+
currentPointerType = 'pointerType' in e ? e.pointerType as PointerType : 'mouse';
7983
if (e.type === 'mousedown' || e.type === 'pointerdown') {
8084
hasEventBeforeFocus = true;
8185
triggerChangeHandlers('pointer', e);
@@ -86,6 +90,7 @@ function handleClickEvent(e: MouseEvent) {
8690
if (!(openLink as any).isOpening && isVirtualClick(e)) {
8791
hasEventBeforeFocus = true;
8892
currentModality = 'virtual';
93+
currentPointerType = 'virtual';
8994
}
9095
}
9196

@@ -101,6 +106,7 @@ function handleFocusEvent(e: FocusEvent) {
101106
// This occurs, for example, when navigating a form with the next/previous buttons on iOS.
102107
if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {
103108
currentModality = 'virtual';
109+
currentPointerType = 'virtual';
104110
triggerChangeHandlers('virtual', e);
105111
}
106112

@@ -249,9 +255,15 @@ export function getInteractionModality(): Modality | null {
249255

250256
export function setInteractionModality(modality: Modality): void {
251257
currentModality = modality;
258+
currentPointerType = modality === 'pointer' ? 'mouse' : modality;
252259
triggerChangeHandlers(modality, null);
253260
}
254261

262+
/** @private */
263+
export function getPointerType(): PointerType {
264+
return currentPointerType;
265+
}
266+
255267
/**
256268
* Keeps state of the current modality.
257269
*/

packages/@react-aria/test-utils/src/testSetup.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,37 @@ export function installMouseEvent(): void {
3535
});
3636
}
3737

38+
export function definePointerEvent(): void {
39+
// @ts-ignore
40+
global.PointerEvent = class FakePointerEvent extends MouseEvent {
41+
_init: {pageX: number, pageY: number, pointerType: string, pointerId: number, width: number, height: number};
42+
constructor(name, init) {
43+
super(name, init);
44+
this._init = init;
45+
}
46+
get pointerType() {
47+
return this._init.pointerType ?? 'mouse';
48+
}
49+
get pointerId() {
50+
return this._init.pointerId;
51+
}
52+
get pageX() {
53+
return this._init.pageX;
54+
}
55+
get pageY() {
56+
return this._init.pageY;
57+
}
58+
get width() {
59+
return this._init.width;
60+
}
61+
get height() {
62+
return this._init.height;
63+
}
64+
};
65+
}
66+
3867
export function installPointerEvent(): void {
39-
beforeAll(() => {
40-
// @ts-ignore
41-
global.PointerEvent = class FakePointerEvent extends MouseEvent {
42-
_init: {pageX: number, pageY: number, pointerType: string, pointerId: number, width: number, height: number};
43-
constructor(name, init) {
44-
super(name, init);
45-
this._init = init;
46-
}
47-
get pointerType() {
48-
return this._init.pointerType ?? 'mouse';
49-
}
50-
get pointerId() {
51-
return this._init.pointerId;
52-
}
53-
get pageX() {
54-
return this._init.pageX;
55-
}
56-
get pageY() {
57-
return this._init.pageY;
58-
}
59-
get width() {
60-
return this._init.width;
61-
}
62-
get height() {
63-
return this._init.height;
64-
}
65-
};
66-
});
68+
beforeAll(definePointerEvent);
6769
afterAll(() => {
6870
// @ts-ignore
6971
delete global.PointerEvent;

packages/@react-aria/utils/src/mergeProps.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
2828

2929
/**
3030
* Merges multiple props objects together. Event handlers are chained,
31-
* classNames are combined, and ids are deduplicated - different ids
32-
* will trigger a side-effect and re-render components hooked up with `useId`.
31+
* classNames are combined, and ids are deduplicated.
3332
* For all other props, the last prop object overrides all previous ones.
3433
* @param args - Multiple sets of props to merge together.
3534
*/

packages/@react-spectrum/s2/src/Tabs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ export function TabPanel(props: TabPanelProps): ReactNode | null {
476476

477477
function CollapsedTabPanel(props: TabPanelProps) {
478478
// eslint-disable-next-line @typescript-eslint/no-unused-vars
479-
let {UNSAFE_style, UNSAFE_className = '', id, ...otherProps} = props;
479+
let {UNSAFE_style, UNSAFE_className = '', id, shouldForceMount, ...otherProps} = props;
480480
let {menuId, valueId} = useContext(CollapseContext);
481481
let ref = useRef(null);
482482
let tabIndex = useHasTabbableChild(ref) ? undefined : 0;

packages/@react-spectrum/s2/src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ export {TreeView, TreeViewItem, TreeViewItemContent, TreeViewLoadMoreItem} from
9191

9292
export {pressScale} from './pressScale';
9393

94-
export {Autocomplete} from 'react-aria-components';
95-
export {Collection} from 'react-aria-components';
96-
export {FileTrigger} from 'react-aria-components';
97-
export {parseColor} from 'react-aria-components';
94+
export {Autocomplete, Collection, FileTrigger, parseColor, useLocale} from 'react-aria-components';
95+
export {useListData, useTreeData, useAsyncList} from 'react-stately';
9896

9997
export type {AccordionProps, AccordionItemProps, AccordionItemHeaderProps, AccordionItemTitleProps, AccordionItemPanelProps} from './Accordion';
10098
export type {ActionBarProps} from './ActionBar';
@@ -169,3 +167,4 @@ export type {ToggleButtonGroupProps} from './ToggleButtonGroup';
169167
export type {TooltipProps} from './Tooltip';
170168
export type {TreeViewProps, TreeViewItemProps, TreeViewItemContentProps, TreeViewLoadMoreItemProps} from './TreeView';
171169
export type {AutocompleteProps, FileTriggerProps, TooltipTriggerComponentProps as TooltipTriggerProps, SortDescriptor, Color, Key, Selection} from 'react-aria-components';
170+
export type {ListData, TreeData, AsyncListData} from 'react-stately';

packages/dev/s2-docs/pages/react-aria/Autocomplete.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ Autocomplete filters a collection component using a [TextField](TextField) or [S
122122
import {Autocomplete, useFilter} from 'react-aria-components';
123123
import {MenuTrigger, Menu, MenuItem} from 'vanilla-starter/Menu';
124124
import {Button} from 'vanilla-starter/Button';
125-
import {Popover} from 'vanilla-starter/Popover';
126125
import {SearchField} from 'vanilla-starter/SearchField';
127126

128127
function Example(props) {
@@ -131,7 +130,7 @@ function Example(props) {
131130
return (
132131
<MenuTrigger>
133132
<Button>Add tag...</Button>
134-
<Popover style={{display: 'flex', flexDirection: 'column'}}>
133+
<div style={{display: 'flex', flexDirection: 'column', maxHeight: 'inherit'}}>
135134
{/*- begin highlight -*/}
136135
<Autocomplete {...props}/* PROPS */ filter={contains}>
137136
<SearchField
@@ -152,7 +151,7 @@ function Example(props) {
152151
<MenuItem>Science</MenuItem>
153152
</Menu>
154153
</Autocomplete>
155-
</Popover>
154+
</div>
156155
</MenuTrigger>
157156
);
158157
}
@@ -1059,10 +1058,9 @@ When the `filter` prop is not set, the items are controlled. This example uses a
10591058

10601059
```tsx render
10611060
"use client";
1062-
import {Autocomplete} from 'react-aria-components';
1061+
import {Autocomplete, useAsyncList} from 'react-aria-components';
10631062
import {SearchField} from 'vanilla-starter/SearchField';
10641063
import {ListBox, ListBoxItem} from 'vanilla-starter/ListBox';
1065-
import {useAsyncList} from 'react-stately';
10661064

10671065
function AsyncLoadingExample() {
10681066
let list = useAsyncList<{name: string}>({

packages/dev/s2-docs/pages/react-aria/Breadcrumbs.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export const description = 'Displays a hierarchy of links to the current page or
2020
import {Breadcrumbs, Breadcrumb} from 'vanilla-starter/Breadcrumbs';
2121

2222
<Breadcrumbs/* PROPS */>
23-
<Breadcrumb href="/">Home</Breadcrumb>
24-
<Breadcrumb href="/react-aria/">React Aria</Breadcrumb>
23+
<Breadcrumb href="https://adobe.com/" target="_blank">Adobe</Breadcrumb>
24+
<Breadcrumb href="/">React Aria</Breadcrumb>
2525
<Breadcrumb>Breadcrumbs</Breadcrumb>
2626
</Breadcrumbs>
2727
```
@@ -31,8 +31,8 @@ export const description = 'Displays a hierarchy of links to the current page or
3131
import {Breadcrumbs, Breadcrumb} from 'tailwind-starter/Breadcrumbs';
3232

3333
<Breadcrumbs/* PROPS */>
34-
<Breadcrumb href="/">Home</Breadcrumb>
35-
<Breadcrumb href="/react-aria/">React Aria</Breadcrumb>
34+
<Breadcrumb href="https://adobe.com/" target="_blank">Adobe</Breadcrumb>
35+
<Breadcrumb href="/">React Aria</Breadcrumb>
3636
<Breadcrumb>Breadcrumbs</Breadcrumb>
3737
</Breadcrumbs>
3838
```

packages/dev/s2-docs/pages/react-aria/Button.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import vanillaDocs from 'docs:vanilla-starter/Button';
1010
import tailwindDocs from 'docs:tailwind-starter/Button';
1111
import '../../tailwind/tailwind.css';
1212
import typesDocs from 'docs:@react-types/shared/src/events.d.ts';
13-
import {getBaseUrl} from '../../src/pageUtils';
1413

1514
export const tags = ['btn'];
1615
export const relatedPages = [{'title': 'useButton', 'url': 'https://react-spectrum.adobe.com/react-aria/useButton.html'}];
@@ -50,7 +49,7 @@ export const description = 'Allows a user to perform an action, with mouse, touc
5049

5150
Use the `onPress` prop to handle interactions via mouse, keyboard, and touch. This is similar to `onClick`, but normalized for consistency across browsers, devices, and interaction methods. Read our [blog post](blog/building-a-button-part-1) to learn more.
5251

53-
The `onPressStart`, `onPressEnd`, and `onPressChange` events are also emitted as the user interacts with the button. Each of these handlers receives a <TypeLink links={typesDocs.links} type={typesDocs.exports.PressEvent} />, which provides information about the target and interaction method. See <Link href={`${getBaseUrl('react-aria')}/usePress`}>usePress</Link> for more details.
52+
The `onPressStart`, `onPressEnd`, and `onPressChange` events are also emitted as the user interacts with the button. Each of these handlers receives a <TypeLink links={typesDocs.links} type={typesDocs.exports.PressEvent} />, which provides information about the target and interaction method. See [usePress](usePress) for more details.
5453

5554
```tsx render
5655
"use client";

0 commit comments

Comments
 (0)