Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/@react-aria/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@swc/helpers": "^0.5.0"
},
"peerDependencies": {
"@testing-library/dom": "^10.1.0",
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.0.0",
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
Expand Down
23 changes: 0 additions & 23 deletions packages/@react-aria/test-utils/src/act.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/@react-aria/test-utils/src/checkboxgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
* governing permissions and limitations under the License.
*/

import {act} from './act';
import {act, within} from '@testing-library/react';
import {CheckboxGroupTesterOpts, UserOpts} from './types';
import {pressElement} from './events';
import {within} from '@testing-library/dom';

interface TriggerCheckboxOptions {
/**
Expand Down
3 changes: 1 addition & 2 deletions packages/@react-aria/test-utils/src/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
* governing permissions and limitations under the License.
*/

import {act} from './act';
import {act, waitFor, within} from '@testing-library/react';
import {ComboBoxTesterOpts, UserOpts} from './types';
import {waitFor, within} from '@testing-library/dom';

interface ComboBoxOpenOpts {
/**
Expand Down
3 changes: 1 addition & 2 deletions packages/@react-aria/test-utils/src/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
* governing permissions and limitations under the License.
*/

import {act} from './act';
import {act, waitFor, within} from '@testing-library/react';
import {DialogTesterOpts, UserOpts} from './types';
import {waitFor, within} from '@testing-library/dom';

interface DialogOpenOpts {
/**
Expand Down
3 changes: 1 addition & 2 deletions packages/@react-aria/test-utils/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
* governing permissions and limitations under the License.
*/

import {act} from './act';
import {fireEvent} from '@testing-library/dom';
import {act, fireEvent} from '@testing-library/react';
import {UserOpts} from './types';

export const DEFAULT_LONG_PRESS_TIME = 500;
Expand Down
3 changes: 1 addition & 2 deletions packages/@react-aria/test-utils/src/gridlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
* governing permissions and limitations under the License.
*/

import {act} from './act';
import {act, within} from '@testing-library/react';
import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';
import {GridListTesterOpts, GridRowActionOpts, ToggleGridRowOpts, UserOpts} from './types';
import {within} from '@testing-library/dom';

interface GridListToggleRowOpts extends ToggleGridRowOpts {}
interface GridListRowActionOpts extends GridRowActionOpts {}
Expand Down
3 changes: 1 addition & 2 deletions packages/@react-aria/test-utils/src/listbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
* governing permissions and limitations under the License.
*/

import {act} from './act';
import {act, within} from '@testing-library/react';
import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';
import {ListBoxTesterOpts, UserOpts} from './types';
import {within} from '@testing-library/dom';

interface ListBoxToggleOptionOpts {
/**
Expand Down
3 changes: 1 addition & 2 deletions packages/@react-aria/test-utils/src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
* governing permissions and limitations under the License.
*/

import {act} from './act';
import {act, waitFor, within} from '@testing-library/react';
import {MenuTesterOpts, UserOpts} from './types';
import {triggerLongPress} from './events';
import {waitFor, within} from '@testing-library/dom';

interface MenuOpenOpts {
/**
Expand Down
3 changes: 1 addition & 2 deletions packages/@react-aria/test-utils/src/radiogroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
* governing permissions and limitations under the License.
*/

import {act} from './act';
import {act, within} from '@testing-library/react';
import {Direction, Orientation, RadioGroupTesterOpts, UserOpts} from './types';
import {pressElement} from './events';
import {within} from '@testing-library/dom';

interface TriggerRadioOptions {
/**
Expand Down
3 changes: 1 addition & 2 deletions packages/@react-aria/test-utils/src/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
* governing permissions and limitations under the License.
*/

import {act} from './act';
import {act, waitFor, within} from '@testing-library/react';
import {SelectTesterOpts, UserOpts} from './types';
import {waitFor, within} from '@testing-library/dom';

interface SelectOpenOpts {
/**
Expand Down
3 changes: 1 addition & 2 deletions packages/@react-aria/test-utils/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
* governing permissions and limitations under the License.
*/

import {act} from './act';
import {act, waitFor, within} from '@testing-library/react';
import {BaseGridRowInteractionOpts, GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';
import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';
import {waitFor, within} from '@testing-library/dom';

interface TableToggleRowOpts extends ToggleGridRowOpts {}
interface TableToggleExpansionOpts extends BaseGridRowInteractionOpts {}
Expand Down
3 changes: 1 addition & 2 deletions packages/@react-aria/test-utils/src/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
* governing permissions and limitations under the License.
*/

import {act} from './act';
import {act, within} from '@testing-library/react';
import {Direction, Orientation, TabsTesterOpts, UserOpts} from './types';
import {pressElement} from './events';
import {within} from '@testing-library/dom';

interface TriggerTabOptions {
/**
Expand Down
3 changes: 1 addition & 2 deletions packages/@react-aria/test-utils/src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
* governing permissions and limitations under the License.
*/

import {act} from './act';
import {act, within} from '@testing-library/react';
import {BaseGridRowInteractionOpts, GridRowActionOpts, ToggleGridRowOpts, TreeTesterOpts, UserOpts} from './types';
import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';
import {within} from '@testing-library/dom';

interface TreeToggleExpansionOpts extends BaseGridRowInteractionOpts {}
interface TreeToggleRowOpts extends ToggleGridRowOpts {}
Expand Down
14 changes: 7 additions & 7 deletions packages/@react-spectrum/s2/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ export interface DatePickerProps<T extends DateValue> extends
* The maximum number of months to display at once in the calendar popover, if screen space permits.
* @default 1
*/
maxVisibleMonths?: number,
/**
* The error message to display when the calendar is invalid.
*/
errorMessage?: ReactNode
maxVisibleMonths?: number
}

export const DatePickerContext = createContext<ContextValue<Partial<DatePickerProps<any>>, HTMLDivElement>>(null);
Expand Down Expand Up @@ -167,6 +163,10 @@ export const DatePicker = /*#__PURE__*/ (forwardRef as forwardRefType)(function
let timeMaxValue = props.maxValue && 'hour' in props.maxValue ? props.maxValue : undefined;
let timeGranularity = state.granularity === 'hour' || state.granularity === 'minute' || state.granularity === 'second' ? state.granularity : undefined;
let showTimeField = !!timeGranularity;

// Ideally, we could omit errorMessage here and let S2 Calendar read it from RAC's CalendarContext which already contains the resolved value via calendarProps from useDatePicker.
// However, RAC's CalendarProps omits errorMessage, so reading it back from the context would require an unsafe cast. Instead, we resolve it here using the same logic as useDatePicker.
let resolvedErrorMessage = typeof errorMessage === 'function' ? errorMessage(state.displayValidation) : (errorMessage || state.displayValidation.validationErrors.join(' '));
return (
<>
<FieldLabel
Expand Down Expand Up @@ -208,7 +208,7 @@ export const DatePicker = /*#__PURE__*/ (forwardRef as forwardRefType)(function
<Calendar
visibleMonths={maxVisibleMonths}
createCalendar={createCalendar}
errorMessage={errorMessage} />
errorMessage={resolvedErrorMessage} />
{showTimeField && (
<div className={style({display: 'flex', gap: 16, contain: 'inline-size'})}>
<TimeField
Expand All @@ -231,7 +231,7 @@ export const DatePicker = /*#__PURE__*/ (forwardRef as forwardRefType)(function
isDisabled={isDisabled}
isInvalid={isInvalid}
description={descriptionMessage}>
{errorMessage}
{resolvedErrorMessage}
</HelpText>
</>
);
Expand Down
16 changes: 8 additions & 8 deletions packages/@react-spectrum/s2/src/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from 'react-aria-components/DateRangePicker';
import {CalendarButton, CalendarPopover, timeField} from './DatePicker';
import {ContextValue} from 'react-aria-components/slots';
import {createContext, forwardRef, ReactElement, ReactNode, Ref, useContext, useState} from 'react';
import {createContext, forwardRef, ReactElement, Ref, useContext, useState} from 'react';
import {DateInput, DateInputContainer, InvalidIndicator} from './DateField';
import {field, fieldInput, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
import {FieldGroup, FieldLabel, HelpText} from './Field';
Expand Down Expand Up @@ -50,11 +50,7 @@ export interface DateRangePickerProps<T extends DateValue> extends
* The maximum number of months to display at once in the calendar popover, if screen space permits.
* @default 1
*/
maxVisibleMonths?: number,
/**
* The error message to display when the calendar is invalid.
*/
errorMessage?: ReactNode
maxVisibleMonths?: number
}

export const DateRangePickerContext = createContext<ContextValue<Partial<DateRangePickerProps<any>>, HTMLDivElement>>(null);
Expand Down Expand Up @@ -111,6 +107,10 @@ export const DateRangePicker = /*#__PURE__*/ (forwardRef as forwardRefType)(func
|| state.granularity === 'second'
? state.granularity : undefined;
let showTimeField = !!timeGranularity;

// Ideally, we could omit errorMessage here and let S2 Calendar read it from RAC's CalendarContext which already contains the resolved value via calendarProps from useDatePicker.
// However, RAC's CalendarProps omits errorMessage, so reading it back from the context would require an unsafe cast. Instead, we resolve it here using the same logic as useDatePicker.
let resolvedErrorMessage = typeof errorMessage === 'function' ? errorMessage(state.displayValidation) : (errorMessage || state.displayValidation.validationErrors.join(' '));
return (
<>
<FieldLabel
Expand Down Expand Up @@ -156,7 +156,7 @@ export const DateRangePicker = /*#__PURE__*/ (forwardRef as forwardRefType)(func
visibleMonths={maxVisibleMonths}
createCalendar={createCalendar}
interactOutsideBehavior={interactOutsideBehavior}
errorMessage={errorMessage} />
errorMessage={resolvedErrorMessage} />
{showTimeField && (
<div className={style({display: 'flex', gap: 16, contain: 'inline-size', marginTop: 24})}>
<TimeField
Expand Down Expand Up @@ -189,7 +189,7 @@ export const DateRangePicker = /*#__PURE__*/ (forwardRef as forwardRefType)(func
isDisabled={isDisabled}
isInvalid={isInvalid}
description={descriptionMessage}>
{errorMessage}
{resolvedErrorMessage}
</HelpText>
</>
);
Expand Down
1 change: 0 additions & 1 deletion packages/@react-spectrum/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@swc/helpers": "^0.5.0"
},
"peerDependencies": {
"@testing-library/dom": "^10.1.0",
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.0.0",
"jest": "^29.5.0",
Expand Down
2 changes: 0 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6428,7 +6428,6 @@ __metadata:
dependencies:
"@swc/helpers": "npm:^0.5.0"
peerDependencies:
"@testing-library/dom": ^10.1.0
"@testing-library/react": ^16.0.0
"@testing-library/user-event": ^14.0.0
react: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1
Expand Down Expand Up @@ -7393,7 +7392,6 @@ __metadata:
"@react-aria/test-utils": "npm:1.0.0-beta.2"
"@swc/helpers": "npm:^0.5.0"
peerDependencies:
"@testing-library/dom": ^10.1.0
"@testing-library/react": ^16.0.0
"@testing-library/user-event": ^14.0.0
jest: ^29.5.0
Expand Down
Loading