diff --git a/packages/@react-stately/select/src/useSelectState.ts b/packages/@react-stately/select/src/useSelectState.ts index 176cbf02bba..2bcf82787a9 100644 --- a/packages/@react-stately/select/src/useSelectState.ts +++ b/packages/@react-stately/select/src/useSelectState.ts @@ -46,7 +46,7 @@ export interface SelectState extends List readonly defaultValue: ValueType, /** Sets the select value. */ - setValue(value: Key | Key[] | null): void, + setValue(value: Key | readonly Key[] | null): void, /** * The value of the first selected item. @@ -88,7 +88,7 @@ export function useSelectState; }, [props.value, props.selectedKey, selectionMode]); - let [controlledValue, setControlledValue] = useControlledState(value, defaultValue, props.onChange as any); + let [controlledValue, setControlledValue] = useControlledState(value, defaultValue, props.onChange as any); // Only display the first selected item if in single selection mode but the value is an array. let displayValue = selectionMode === 'single' && Array.isArray(controlledValue) ? controlledValue[0] : controlledValue; let setValue = (value: Key | Key[] | null) => { diff --git a/packages/@react-types/select/src/index.d.ts b/packages/@react-types/select/src/index.d.ts index 339f4163f9f..e30db1813cc 100644 --- a/packages/@react-types/select/src/index.d.ts +++ b/packages/@react-types/select/src/index.d.ts @@ -32,10 +32,11 @@ import { } from '@react-types/shared'; export type SelectionMode = 'single' | 'multiple'; -export type ValueType = M extends 'single' ? Key | null : Key[]; +export type ValueType = M extends 'single' ? Key | null : readonly Key[]; +export type ChangeValueType = M extends 'single' ? Key | null : Key[]; type ValidationType = M extends 'single' ? Key : Key[]; -export interface SelectProps extends CollectionBase, Omit, ValueBase>, Validation>, HelpTextProps, LabelableProps, TextInputBase, FocusableProps { +export interface SelectProps extends CollectionBase, Omit, ValueBase, ChangeValueType>, Validation>, HelpTextProps, LabelableProps, TextInputBase, FocusableProps { /** * Whether single or multiple selection is enabled. * @default 'single' diff --git a/packages/react-aria-components/src/GridList.tsx b/packages/react-aria-components/src/GridList.tsx index ec837fabffe..7711cf95e4e 100644 --- a/packages/react-aria-components/src/GridList.tsx +++ b/packages/react-aria-components/src/GridList.tsx @@ -156,7 +156,8 @@ function GridListInner({props, collection, gridListRef: ref}: // Only tab navigation is supported in grid layout. keyboardNavigationBehavior: layout === 'grid' ? 'tab' : keyboardNavigationBehavior, isVirtualized, - shouldSelectOnPressUp: props.shouldSelectOnPressUp + shouldSelectOnPressUp: props.shouldSelectOnPressUp, + disallowTypeAhead }, filteredState, ref); let selectionManager = filteredState.selectionManager; diff --git a/packages/react-aria-components/src/HiddenDateInput.tsx b/packages/react-aria-components/src/HiddenDateInput.tsx index 60fc3af948e..a7eeeb9c4d9 100644 --- a/packages/react-aria-components/src/HiddenDateInput.tsx +++ b/packages/react-aria-components/src/HiddenDateInput.tsx @@ -11,7 +11,7 @@ */ -import {CalendarDate, CalendarDateTime, parseDate, parseDateTime} from '@internationalized/date'; +import {CalendarDate, CalendarDateTime, parseDate, parseDateTime, toCalendarDate, toCalendarDateTime, toLocalTimeZone} from '@internationalized/date'; import {DateFieldState, DatePickerState, DateSegmentType} from 'react-stately'; import React, {ReactNode} from 'react'; import {useVisuallyHidden} from 'react-aria'; @@ -65,8 +65,15 @@ export function useHiddenDateInput(props: HiddenDateInputProps, state: DateField } else if (state.granularity === 'hour') { inputStep = 3600; } - - let dateValue = state.value == null ? '' : state.value.toString(); + + let dateValue = ''; + if (state.value) { + if (state.granularity === 'day') { + dateValue = toCalendarDate(state.value).toString(); + } else { + dateValue = toCalendarDateTime('timeZone' in state.value ? toLocalTimeZone(state.value) : state.value).toString(); + } + } let inputType = state.granularity === 'day' ? 'date' : 'datetime-local'; diff --git a/packages/react-aria-components/stories/DateField.stories.tsx b/packages/react-aria-components/stories/DateField.stories.tsx index 3c7ff7cdabc..133fc0602ab 100644 --- a/packages/react-aria-components/stories/DateField.stories.tsx +++ b/packages/react-aria-components/stories/DateField.stories.tsx @@ -94,8 +94,7 @@ export const DateFieldAutoFill = (props) => ( {...props} name="bday" autoComplete="bday" - defaultValue={parseAbsoluteToLocal('2021-04-07T18:45:22Z') - } + defaultValue={parseAbsoluteToLocal('2021-04-07T18:45:22Z')} data-testid="date-field-example"> diff --git a/packages/react-aria-components/stories/DatePicker.stories.tsx b/packages/react-aria-components/stories/DatePicker.stories.tsx index 4838bcffe59..ae079959edf 100644 --- a/packages/react-aria-components/stories/DatePicker.stories.tsx +++ b/packages/react-aria-components/stories/DatePicker.stories.tsx @@ -14,6 +14,7 @@ import {action} from '@storybook/addon-actions'; import {Button, Calendar, CalendarCell, CalendarGrid, DateInput, DatePicker, DateRangePicker, DateSegment, Dialog, Form, Group, Heading, Input, Label, Popover, RangeCalendar, TextField} from 'react-aria-components'; import clsx from 'clsx'; import {Meta, StoryFn} from '@storybook/react'; +import {parseAbsoluteToLocal} from '@internationalized/date'; import React from 'react'; import styles from '../example/index.css'; import './styles.css'; @@ -211,7 +212,7 @@ export const DatePickerAutofill = (props) => ( - + diff --git a/packages/react-aria-components/stories/GridList.stories.tsx b/packages/react-aria-components/stories/GridList.stories.tsx index 0d8c197519a..b6f0174a509 100644 --- a/packages/react-aria-components/stories/GridList.stories.tsx +++ b/packages/react-aria-components/stories/GridList.stories.tsx @@ -68,15 +68,15 @@ export const GridListExample: GridListStory = (args) => ( gridTemplate: args.layout === 'grid' ? 'repeat(3, 1fr) / repeat(3, 1fr)' : 'auto / 1fr', gridAutoFlow: 'row' }}> - 1,1 - 1,2 - 1,3 - 2,1 - 2,2 - 2,3 - 3,1 - 3,2 - 3,3 + 1,1 + 1,2 + 1,3 + 2,1 + 2,2 + 2,3 + 3,1 + 3,2 + 3,3 ); @@ -103,7 +103,8 @@ GridListExample.story = { args: { layout: 'stack', escapeKeyBehavior: 'clearSelection', - shouldSelectOnPressUp: false + shouldSelectOnPressUp: false, + disallowTypeAhead: false }, argTypes: { layout: { @@ -634,3 +635,4 @@ export let GridListInModalPicker: StoryObj = } } }; +