react-aria-components 1.0.0-alpha.2 → 1.0.0-alpha.4

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/src/Table.tsx CHANGED
@@ -1,9 +1,9 @@
1
1
  import {AriaLabelingProps} from '@react-types/shared';
2
- import {BaseCollection, CollectionContext, CollectionProps, CollectionRendererContext, ItemRenderProps, NodeValue, useCachedChildren, useCollection, useCollectionChildren} from './Collection';
2
+ import {BaseCollection, CollectionContext, CollectionProps, CollectionRendererContext, ItemRenderProps, NodeValue, useCachedChildren, useCollection, useCollectionChildren, useCollectionItemRef} from './Collection';
3
3
  import {buildHeaderRows} from '@react-stately/table';
4
4
  import {ButtonContext} from './Button';
5
5
  import {CheckboxContext} from './Checkbox';
6
- import {ContextValue, defaultSlot, Provider, RenderProps, SlotProps, StyleRenderProps, useContextProps, useRenderProps} from './utils';
6
+ import {ContextValue, defaultSlot, forwardRefType, Provider, RenderProps, SlotProps, StyleProps, StyleRenderProps, useContextProps, useRenderProps} from './utils';
7
7
  import {DisabledBehavior, DraggableCollectionState, DroppableCollectionState, Node, SelectionBehavior, SelectionMode, SortDirection, TableState, useTableState} from 'react-stately';
8
8
  import {DragAndDropHooks, DropIndicator, DropIndicatorContext, DropIndicatorProps} from './useDragAndDrop';
9
9
  import {DraggableItemResult, DragPreviewRenderer, DropIndicatorAria, DroppableCollectionResult, FocusScope, ListKeyboardDelegate, mergeProps, useFocusRing, useHover, useTable, useTableCell, useTableColumnHeader, useTableHeaderRow, useTableRow, useTableRowGroup, useTableSelectAllCheckbox, useTableSelectionCheckbox, useVisuallyHidden} from 'react-aria';
@@ -316,7 +316,7 @@ function Table(props: TableProps, ref: ForwardedRef<HTMLTableElement>) {
316
316
  <Provider
317
317
  values={[
318
318
  [InternalTableContext, {state, dragAndDropHooks, dragState, dropState}],
319
- [DropIndicatorContext, {render: TableDropIndicator}]
319
+ [DropIndicatorContext, {render: TableDropIndicatorWrapper}]
320
320
  ]}>
321
321
  <FocusScope>
322
322
  <table
@@ -368,17 +368,14 @@ export function useTableOptions(): TableOptionsContextValue {
368
368
  return useContext(TableOptionsContext)!;
369
369
  }
370
370
 
371
- export interface TableHeaderProps<T> {
371
+ export interface TableHeaderProps<T> extends StyleProps {
372
372
  /** A list of table columns. */
373
373
  columns?: T[],
374
374
  /** A list of `Column(s)` or a function. If the latter, a list of columns must be provided using the `columns` prop. */
375
375
  children?: ReactNode | ((item: T) => ReactElement)
376
376
  }
377
377
 
378
- /**
379
- * A header within a `<Table>`, containing the table columns.
380
- */
381
- export function TableHeader<T extends object>(props: TableHeaderProps<T>) {
378
+ function TableHeader<T extends object>(props: TableHeaderProps<T>, ref: ForwardedRef<HTMLTableSectionElement>) {
382
379
  let children = useCollectionChildren({
383
380
  children: props.children,
384
381
  items: props.columns
@@ -388,11 +385,17 @@ export function TableHeader<T extends object>(props: TableHeaderProps<T>) {
388
385
  return (
389
386
  <CollectionRendererContext.Provider value={renderer}>
390
387
  {/* @ts-ignore */}
391
- <tableheader multiple={props}>{children}</tableheader>
388
+ <tableheader ref={useCollectionItemRef(props, ref)}>{children}</tableheader>
392
389
  </CollectionRendererContext.Provider>
393
390
  );
394
391
  }
395
392
 
393
+ /**
394
+ * A header within a `<Table>`, containing the table columns.
395
+ */
396
+ const _TableHeader = /*#__PURE__*/ (forwardRef as forwardRefType)(TableHeader);
397
+ export {_TableHeader as TableHeader};
398
+
396
399
  export interface ColumnRenderProps {
397
400
  /**
398
401
  * Whether the item is currently focused.
@@ -430,10 +433,7 @@ export interface ColumnProps<T = object> extends RenderProps<ColumnRenderProps>
430
433
  textValue?: string
431
434
  }
432
435
 
433
- /**
434
- * A column within a `<Table>`.
435
- */
436
- export function Column<T extends object>(props: ColumnProps<T>): JSX.Element {
436
+ function Column<T extends object>(props: ColumnProps<T>, ref: ForwardedRef<HTMLTableCellElement>): JSX.Element {
437
437
  let render = useContext(CollectionRendererContext);
438
438
  let childColumns = typeof render === 'function' ? render : props.children;
439
439
  let children = useCollectionChildren({
@@ -442,9 +442,15 @@ export function Column<T extends object>(props: ColumnProps<T>): JSX.Element {
442
442
  });
443
443
 
444
444
  // @ts-ignore
445
- return <column multiple={{...props, rendered: props.title ?? props.children}}>{children}</column>;
445
+ return <column ref={useCollectionItemRef(props, ref, props.title ?? props.children)}>{children}</column>;
446
446
  }
447
447
 
448
+ /**
449
+ * A column within a `<Table>`.
450
+ */
451
+ const _Column = /*#__PURE__*/ (forwardRef as forwardRefType)(Column);
452
+ export {_Column as Column};
453
+
448
454
  export interface TableBodyRenderProps {
449
455
  /**
450
456
  * Whether the table body has no rows and should display its empty state.
@@ -458,16 +464,19 @@ export interface TableBodyProps<T> extends CollectionProps<T>, StyleRenderProps<
458
464
  renderEmptyState?: () => ReactNode
459
465
  }
460
466
 
461
- /**
462
- * The body of a `<Table>`, containing the table rows.
463
- */
464
- export function TableBody<T extends object>(props: TableBodyProps<T>) {
467
+ function TableBody<T extends object>(props: TableBodyProps<T>, ref: ForwardedRef<HTMLTableSectionElement>) {
465
468
  let children = useCollectionChildren(props);
466
469
 
467
470
  // @ts-ignore
468
- return <tablebody multiple={props}>{children}</tablebody>;
471
+ return <tablebody ref={useCollectionItemRef(props, ref)}>{children}</tablebody>;
469
472
  }
470
473
 
474
+ /**
475
+ * The body of a `<Table>`, containing the table rows.
476
+ */
477
+ const _TableBody = /*#__PURE__*/ (forwardRef as forwardRefType)(TableBody);
478
+ export {_TableBody as TableBody};
479
+
471
480
  export interface RowRenderProps extends ItemRenderProps {}
472
481
 
473
482
  export interface RowProps<T> extends RenderProps<RowRenderProps> {
@@ -480,10 +489,7 @@ export interface RowProps<T> extends RenderProps<RowRenderProps> {
480
489
  textValue?: string
481
490
  }
482
491
 
483
- /**
484
- * A row within a `<Table>`.
485
- */
486
- export function Row<T extends object>(props: RowProps<T>) {
492
+ function Row<T extends object>(props: RowProps<T>, ref: ForwardedRef<HTMLTableRowElement>) {
487
493
  let children = useCollectionChildren({
488
494
  children: props.children,
489
495
  items: props.columns,
@@ -494,7 +500,7 @@ export function Row<T extends object>(props: RowProps<T>) {
494
500
 
495
501
  return (
496
502
  // @ts-ignore
497
- <item multiple={props}>
503
+ <item ref={useCollectionItemRef(props, ref)}>
498
504
  <CollectionContext.Provider value={ctx}>
499
505
  {children}
500
506
  </CollectionContext.Provider>
@@ -503,6 +509,12 @@ export function Row<T extends object>(props: RowProps<T>) {
503
509
  );
504
510
  }
505
511
 
512
+ /**
513
+ * A row within a `<Table>`.
514
+ */
515
+ const _Row = /*#__PURE__*/ (forwardRef as forwardRefType)(Row);
516
+ export {_Row as Row};
517
+
506
518
  export interface CellRenderProps {
507
519
  /**
508
520
  * Whether the cell is currently in a pressed state.
@@ -529,13 +541,16 @@ export interface CellProps extends RenderProps<CellRenderProps> {
529
541
  textValue?: string
530
542
  }
531
543
 
544
+ function Cell(props: CellProps, ref: ForwardedRef<HTMLTableCellElement>): JSX.Element {
545
+ // @ts-ignore
546
+ return <cell ref={useCollectionItemRef(props, ref, props.children)} />;
547
+ }
548
+
532
549
  /**
533
550
  * A cell within a table row.
534
551
  */
535
- export function Cell(props: CellProps): JSX.Element {
536
- // @ts-ignore
537
- return <cell multiple={{...props, rendered: props.children}} />;
538
- }
552
+ const _Cell = forwardRef(Cell);
553
+ export {_Cell as Cell};
539
554
 
540
555
  function TableHeaderRowGroup<T>({collection}: {collection: TableCollection<T>}) {
541
556
  let headerRows = useCachedChildren({
@@ -555,6 +570,7 @@ function TableHeaderRowGroup<T>({collection}: {collection: TableCollection<T>})
555
570
  <thead
556
571
  {...filterDOMProps(collection.head.props)}
557
572
  {...rowGroupProps}
573
+ ref={collection.head.props.ref}
558
574
  className={collection.head.props.className ?? 'react-aria-TableHeader'}
559
575
  style={collection.head.props.style}>
560
576
  {headerRows}
@@ -600,8 +616,9 @@ function TableBodyRowGroup<T>({collection, isDroppable}: {collection: TableColle
600
616
  let {rowGroupProps} = useTableRowGroup();
601
617
  return (
602
618
  <tbody
619
+ {...mergeProps(filterDOMProps(props as any), rowGroupProps)}
603
620
  {...renderProps}
604
- {...rowGroupProps}
621
+ ref={collection.body.props.ref}
605
622
  data-empty={collection.size === 0 || undefined}>
606
623
  {isDroppable && <RootDropIndicator />}
607
624
  {bodyRows}
@@ -645,7 +662,7 @@ function TableHeaderRow<T>({item}: {item: GridNode<T>}) {
645
662
  }
646
663
 
647
664
  function TableColumnHeader<T>({column}: {column: GridNode<T>}) {
648
- let ref = useRef<HTMLTableHeaderCellElement>(null);
665
+ let ref = useObjectRef<HTMLTableHeaderCellElement>(column.props.ref);
649
666
  let {state} = useContext(InternalTableContext)!;
650
667
  let {columnHeaderProps} = useTableColumnHeader(
651
668
  {node: column},
@@ -672,7 +689,7 @@ function TableColumnHeader<T>({column}: {column: GridNode<T>}) {
672
689
 
673
690
  return (
674
691
  <th
675
- {...mergeProps(columnHeaderProps, focusProps)}
692
+ {...mergeProps(filterDOMProps(props as any), columnHeaderProps, focusProps)}
676
693
  {...renderProps}
677
694
  colSpan={column.colspan}
678
695
  ref={ref}
@@ -684,7 +701,7 @@ function TableColumnHeader<T>({column}: {column: GridNode<T>}) {
684
701
  }
685
702
 
686
703
  function TableRow<T>({item}: {item: GridNode<T>}) {
687
- let ref = useRef<HTMLTableRowElement>(null);
704
+ let ref = useObjectRef<HTMLTableRowElement>(item.props.ref);
688
705
  let {state, dragAndDropHooks, dragState, dropState} = useContext(InternalTableContext)!;
689
706
  let {rowProps, ...states} = useTableRow(
690
707
  {
@@ -770,7 +787,7 @@ function TableRow<T>({item}: {item: GridNode<T>}) {
770
787
  </tr>
771
788
  )}
772
789
  <tr
773
- {...mergeProps(rowProps, focusProps, hoverProps, draggableItem?.dragProps)}
790
+ {...mergeProps(filterDOMProps(props as any), rowProps, focusProps, hoverProps, draggableItem?.dragProps)}
774
791
  {...renderProps}
775
792
  ref={ref}
776
793
  data-hovered={isHovered || undefined}
@@ -810,7 +827,7 @@ function TableRow<T>({item}: {item: GridNode<T>}) {
810
827
  }
811
828
 
812
829
  function TableCell<T>({cell}: {cell: GridNode<T>}) {
813
- let ref = useRef<HTMLTableCellElement>(null);
830
+ let ref = useObjectRef<HTMLTableCellElement>(cell.props.ref);
814
831
  let {state, dragState} = useContext(InternalTableContext)!;
815
832
 
816
833
  // @ts-ignore
@@ -836,20 +853,20 @@ function TableCell<T>({cell}: {cell: GridNode<T>}) {
836
853
 
837
854
  return (
838
855
  <td
839
- {...mergeProps(gridCellProps, focusProps)}
856
+ {...mergeProps(filterDOMProps(props as any), gridCellProps, focusProps)}
840
857
  {...renderProps}
841
858
  ref={ref}
842
859
  data-focused={isFocused || undefined}
843
860
  data-focus-visible={isFocusVisible || undefined}
844
861
  data-pressed={isPressed || undefined}>
845
- {cell.rendered}
862
+ {renderProps.children}
846
863
  </td>
847
864
  );
848
865
  }
849
866
 
850
- function TableDropIndicator(props: DropIndicatorProps, ref: ForwardedRef<HTMLElement>) {
867
+ function TableDropIndicatorWrapper(props: DropIndicatorProps, ref: ForwardedRef<HTMLElement>) {
851
868
  ref = useObjectRef(ref);
852
- let {state, dragAndDropHooks, dropState} = useContext(InternalTableContext)!;
869
+ let {dragAndDropHooks, dropState} = useContext(InternalTableContext)!;
853
870
  let buttonRef = useRef<HTMLDivElement>(null);
854
871
  let {dropIndicatorProps, isHidden, isDropTarget} = dragAndDropHooks!.useDropIndicator!(
855
872
  props,
@@ -857,15 +874,33 @@ function TableDropIndicator(props: DropIndicatorProps, ref: ForwardedRef<HTMLEle
857
874
  buttonRef
858
875
  );
859
876
 
860
- let {visuallyHiddenProps} = useVisuallyHidden();
861
-
862
877
  if (isHidden) {
863
878
  return null;
864
879
  }
865
880
 
866
- // eslint-disable-next-line react-hooks/rules-of-hooks
881
+ return (
882
+ <TableDropIndicatorForwardRef {...props} dropIndicatorProps={dropIndicatorProps} isDropTarget={isDropTarget} buttonRef={buttonRef} ref={ref} />
883
+ );
884
+ }
885
+
886
+ interface TableDropIndicatorProps extends DropIndicatorProps {
887
+ dropIndicatorProps: React.HTMLAttributes<HTMLElement>,
888
+ isDropTarget: boolean,
889
+ buttonRef: RefObject<HTMLDivElement>
890
+ }
891
+
892
+ function TableDropIndicator(props: TableDropIndicatorProps, ref: ForwardedRef<HTMLElement>) {
893
+ let {
894
+ dropIndicatorProps,
895
+ isDropTarget,
896
+ buttonRef,
897
+ ...otherProps
898
+ } = props;
899
+
900
+ let {state} = useContext(InternalTableContext)!;
901
+ let {visuallyHiddenProps} = useVisuallyHidden();
867
902
  let renderProps = useRenderProps({
868
- ...props,
903
+ ...otherProps,
869
904
  defaultClassName: 'react-aria-DropIndicator',
870
905
  values: {
871
906
  isDropTarget
@@ -874,6 +909,7 @@ function TableDropIndicator(props: DropIndicatorProps, ref: ForwardedRef<HTMLEle
874
909
 
875
910
  return (
876
911
  <tr
912
+ {...filterDOMProps(props as any)}
877
913
  {...renderProps}
878
914
  role="row"
879
915
  ref={ref as RefObject<HTMLTableRowElement>}
@@ -888,6 +924,8 @@ function TableDropIndicator(props: DropIndicatorProps, ref: ForwardedRef<HTMLEle
888
924
  );
889
925
  }
890
926
 
927
+ const TableDropIndicatorForwardRef = forwardRef(TableDropIndicator);
928
+
891
929
  function RootDropIndicator() {
892
930
  let {state, dragAndDropHooks, dropState} = useContext(InternalTableContext)!;
893
931
  let ref = useRef<HTMLDivElement>(null);
package/src/Tabs.tsx CHANGED
@@ -14,9 +14,9 @@ import {AriaLabelingProps} from '@react-types/shared';
14
14
  import {AriaTabListProps, AriaTabPanelProps, mergeProps, Orientation, useFocusRing, useHover, useTab, useTabList, useTabPanel} from 'react-aria';
15
15
  import {CollectionProps, Item, useCollection} from './Collection';
16
16
  import {ContextValue, forwardRefType, RenderProps, SlotProps, StyleRenderProps, useContextProps, useRenderProps} from './utils';
17
+ import {filterDOMProps, useObjectRef} from '@react-aria/utils';
17
18
  import {Node, TabListState, useTabListState} from 'react-stately';
18
- import React, {createContext, ForwardedRef, forwardRef, Key, useContext, useEffect, useState} from 'react';
19
- import {useObjectRef} from '@react-aria/utils';
19
+ import React, {createContext, ForwardedRef, forwardRef, Key, useContext, useEffect, useMemo, useState} from 'react';
20
20
 
21
21
  export interface TabsProps extends RenderProps<TabsRenderProps>, SlotProps {
22
22
  /**
@@ -107,24 +107,24 @@ const InternalTabsContext = createContext<InternalTabsContextValue | null>(null)
107
107
  function Tabs(props: TabsProps, ref: ForwardedRef<HTMLDivElement>) {
108
108
  [props, ref] = useContextProps(props, ref, TabsContext);
109
109
  let {orientation = 'horizontal'} = props;
110
+ let values = useMemo(() => ({orientation}), [orientation]);
110
111
  let [state, setState] = useState<TabListState<unknown> | null>(null);
111
112
 
112
113
  let renderProps = useRenderProps({
113
114
  ...props,
114
115
  defaultClassName: 'react-aria-Tabs',
115
- values: {
116
- orientation
117
- }
116
+ values
118
117
  });
119
118
 
120
119
  return (
121
120
  <div
121
+ {...filterDOMProps(props as any)}
122
122
  {...renderProps}
123
123
  ref={ref}
124
124
  slot={props.slot}
125
125
  data-orientation={orientation}>
126
126
  <InternalTabsContext.Provider value={{state, setState, orientation}}>
127
- {props.children}
127
+ {renderProps.children}
128
128
  </InternalTabsContext.Provider>
129
129
  </div>
130
130
  );
@@ -166,9 +166,12 @@ function TabList<T extends object>(props: TabListProps<T>, ref: ForwardedRef<HTM
166
166
  }
167
167
  });
168
168
 
169
+ let DOMProps = filterDOMProps(props);
170
+ delete DOMProps.id;
171
+
169
172
  return (
170
173
  <>
171
- <div {...tabListProps} ref={objectRef} {...renderProps}>
174
+ <div {...DOMProps} {...tabListProps} ref={objectRef} {...renderProps}>
172
175
  {[...state.collection].map((item) => (
173
176
  <TabInner
174
177
  key={item.key}
@@ -185,20 +188,23 @@ function TabList<T extends object>(props: TabListProps<T>, ref: ForwardedRef<HTM
185
188
  * A TabList is used within Tabs to group tabs that a user can switch between.
186
189
  * The ids of the items within the <TabList> must match up with a corresponding item inside the <TabPanels>.
187
190
  */
188
- const _TabList = (forwardRef as forwardRefType)(TabList);
191
+ const _TabList = /*#__PURE__*/ (forwardRef as forwardRefType)(TabList);
189
192
  export {_TabList as TabList};
190
193
 
194
+ function Tab(props: TabProps, ref: ForwardedRef<HTMLDivElement>) {
195
+ // @ts-ignore
196
+ return <Item {...props} ref={ref} />;
197
+ }
198
+
191
199
  /**
192
200
  * A Tab provides a title for an individual item within a TabList.
193
201
  */
194
- export function Tab(props: TabProps): JSX.Element {
195
- // @ts-ignore
196
- return Item(props);
197
- }
202
+ const _Tab = forwardRef(Tab);
203
+ export {_Tab as Tab};
198
204
 
199
205
  function TabInner({item, state}: {item: Node<object>, state: TabListState<object>}) {
200
206
  let {key} = item;
201
- let ref = React.useRef<HTMLDivElement>(null);
207
+ let ref = useObjectRef<HTMLDivElement>(item.props.ref);
202
208
  let {tabProps, isSelected, isDisabled, isPressed} = useTab({key}, state, ref);
203
209
  let {focusProps, isFocused, isFocusVisible} = useFocusRing();
204
210
  let {hoverProps, isHovered} = useHover({
@@ -219,9 +225,12 @@ function TabInner({item, state}: {item: Node<object>, state: TabListState<object
219
225
  }
220
226
  });
221
227
 
228
+ let DOMProps = filterDOMProps(item.props);
229
+ delete DOMProps.id;
230
+
222
231
  return (
223
232
  <div
224
- {...mergeProps(tabProps, focusProps, hoverProps, renderProps)}
233
+ {...mergeProps(DOMProps, tabProps, focusProps, hoverProps, renderProps)}
225
234
  ref={ref}
226
235
  data-focus-visible={isFocusVisible || undefined}
227
236
  data-pressed={isPressed || undefined}
@@ -250,16 +259,19 @@ export function TabPanels<T extends object>(props: TabPanelsProps<T>) {
250
259
  );
251
260
  }
252
261
 
262
+ function TabPanel(props: TabPanelProps, ref: ForwardedRef<HTMLDivElement>) {
263
+ return <Item {...props} ref={ref} />;
264
+ }
265
+
253
266
  /**
254
267
  * A TabPanel provides the content for a tab.
255
268
  */
256
- export function TabPanel(props: TabPanelProps): JSX.Element {
257
- return Item(props);
258
- }
269
+ const _TabPanel = forwardRef(TabPanel);
270
+ export {_TabPanel as TabPanel};
259
271
 
260
272
  function SelectedTabPanel({item}: {item: Node<object>}) {
261
273
  const {state} = useContext(InternalTabsContext)!;
262
- let ref = React.useRef<HTMLDivElement>(null);
274
+ let ref = useObjectRef<HTMLDivElement>(item.props.ref);
263
275
  let {tabPanelProps} = useTabPanel(item.props, state!, ref);
264
276
  let {focusProps, isFocused, isFocusVisible} = useFocusRing();
265
277
 
@@ -273,9 +285,12 @@ function SelectedTabPanel({item}: {item: Node<object>}) {
273
285
  }
274
286
  });
275
287
 
288
+ let DOMProps = filterDOMProps(item.props);
289
+ delete DOMProps.id;
290
+
276
291
  return (
277
292
  <div
278
- {...mergeProps(tabPanelProps, focusProps, renderProps)}
293
+ {...mergeProps(DOMProps, tabPanelProps, focusProps, renderProps)}
279
294
  ref={ref}
280
295
  data-focus-visible={isFocusVisible || undefined} />
281
296
  );
package/src/index.ts CHANGED
@@ -55,7 +55,7 @@ export type {BreadcrumbsProps} from './Breadcrumbs';
55
55
  export type {ButtonProps, ButtonRenderProps} from './Button';
56
56
  export type {CalendarCellProps, CalendarProps, CalendarGridProps, CalendarGridHeaderProps, CalendarGridBodyProps, CalendarHeaderCellProps, CalendarCellRenderProps, RangeCalendarProps} from './Calendar';
57
57
  export type {CheckboxGroupProps, CheckboxGroupRenderProps, CheckboxRenderProps, CheckboxProps} from './Checkbox';
58
- export type {ComboBoxProps} from './ComboBox';
58
+ export type {ComboBoxProps, ComboBoxRenderProps} from './ComboBox';
59
59
  export type {DateFieldProps, DateInputProps, DateInputRenderProps, DateSegmentProps, DateSegmentRenderProps, TimeFieldProps} from './DateField';
60
60
  export type {DatePickerProps, DateRangePickerProps} from './DatePicker';
61
61
  export type {DialogProps, DialogTriggerProps} from './Dialog';
@@ -77,7 +77,7 @@ export type {PopoverProps, PopoverRenderProps} from './Popover';
77
77
  export type {ProgressBarProps, ProgressBarRenderProps} from './ProgressBar';
78
78
  export type {RadioGroupProps, RadioGroupRenderProps, RadioProps, RadioRenderProps} from './RadioGroup';
79
79
  export type {SearchFieldProps, SearchFieldRenderProps} from './SearchField';
80
- export type {SelectProps, SelectValueProps, SelectValueRenderProps} from './Select';
80
+ export type {SelectProps, SelectValueProps, SelectValueRenderProps, SelectRenderProps} from './Select';
81
81
  export type {SeparatorProps} from './Separator';
82
82
  export type {SliderOutputProps, SliderProps, SliderRenderProps, SliderThumbProps, SliderTrackProps, SliderThumbRenderProps} from './Slider';
83
83
  export type {SwitchProps, SwitchRenderProps} from './Switch';
@@ -87,7 +87,7 @@ export type {TextFieldProps} from './TextField';
87
87
  export type {TextProps} from './Text';
88
88
  export type {ToggleButtonProps, ToggleButtonRenderProps} from './ToggleButton';
89
89
  export type {TooltipProps, TooltipRenderProps, TooltipTriggerComponentProps} from './Tooltip';
90
- export type {DragAndDropHooks, DragAndDropOptions} from './useDragAndDrop';
90
+ export type {DragAndDropHooks, DragAndDropOptions, DropIndicatorProps} from './useDragAndDrop';
91
91
 
92
92
  export type {DateValue, DateRange, TimeValue} from 'react-aria';
93
93
  export type {DirectoryDropItem, DraggableCollectionEndEvent, DraggableCollectionMoveEvent, DraggableCollectionStartEvent, DragPreviewRenderer, DragTypes, DropItem, DropOperation, DroppableCollectionDropEvent, DroppableCollectionEnterEvent, DroppableCollectionExitEvent, DroppableCollectionInsertDropEvent, DroppableCollectionMoveEvent, DroppableCollectionOnItemDropEvent, DroppableCollectionReorderEvent, DroppableCollectionRootDropEvent, DropPosition, DropTarget, FileDropItem, ItemDropTarget, RootDropTarget, TextDropItem} from 'react-aria';
package/src/utils.tsx CHANGED
@@ -11,8 +11,9 @@
11
11
  */
12
12
 
13
13
  import {AriaLabelingProps, DOMProps as SharedDOMProps} from '@react-types/shared';
14
- import {filterDOMProps, mergeProps, mergeRefs, useLayoutEffect, useObjectRef} from '@react-aria/utils';
15
- import React, {createContext, CSSProperties, ReactNode, RefCallback, RefObject, useCallback, useContext, useEffect, useRef, useState} from 'react';
14
+ import {mergeProps, mergeRefs, useLayoutEffect, useObjectRef} from '@react-aria/utils';
15
+ import React, {createContext, CSSProperties, ReactNode, RefCallback, RefObject, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
16
+ import ReactDOM from 'react-dom';
16
17
 
17
18
  // Override forwardRef types so generics work.
18
19
  declare function forwardRef<T, P = {}>(
@@ -59,7 +60,7 @@ export function Provider<A, B, C, D, E, F, G, H>({values, children}: ProviderPro
59
60
  export interface StyleProps {
60
61
  /** The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. */
61
62
  className?: string,
62
- /** The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/Element/style) for the element. */
63
+ /** The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. */
63
64
  style?: CSSProperties
64
65
  }
65
66
 
@@ -71,7 +72,7 @@ export interface DOMProps extends StyleProps {
71
72
  export interface StyleRenderProps<T> {
72
73
  /** 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. */
73
74
  className?: string | ((values: T) => string),
74
- /** The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/Element/style) for the element. A function may be provided to compute the style based on component state. */
75
+ /** 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. */
75
76
  style?: CSSProperties | ((values: T) => CSSProperties)
76
77
  }
77
78
 
@@ -86,28 +87,47 @@ interface RenderPropsHookOptions<T> extends RenderProps<T>, SharedDOMProps, Aria
86
87
  defaultClassName?: string
87
88
  }
88
89
 
89
- export function useRenderProps<T>({className, style, children, defaultClassName, defaultChildren, values, ...otherProps}: RenderPropsHookOptions<T>) {
90
- if (typeof className === 'function') {
91
- className = className(values);
92
- }
90
+ export function useRenderProps<T>(props: RenderPropsHookOptions<T>) {
91
+ let {
92
+ className,
93
+ style,
94
+ children,
95
+ defaultClassName,
96
+ defaultChildren,
97
+ values
98
+ } = props;
99
+
100
+ return useMemo(() => {
101
+ let computedClassName: string | undefined;
102
+ let computedStyle: React.CSSProperties | undefined;
103
+ let computedChildren: React.ReactNode | undefined;
104
+
105
+ if (typeof className === 'function') {
106
+ computedClassName = className(values);
107
+ } else {
108
+ computedClassName = className;
109
+ }
93
110
 
94
- if (typeof style === 'function') {
95
- style = style(values);
96
- }
111
+ if (typeof style === 'function') {
112
+ computedStyle = style(values);
113
+ } else {
114
+ computedStyle = style;
115
+ }
97
116
 
98
- if (typeof children === 'function') {
99
- children = children(values);
100
- } else if (children == null) {
101
- children = defaultChildren;
102
- }
117
+ if (typeof children === 'function') {
118
+ computedChildren = children(values);
119
+ } else if (children == null) {
120
+ computedChildren = defaultChildren;
121
+ } else {
122
+ computedChildren = children;
123
+ }
103
124
 
104
- delete otherProps.id;
105
- return {
106
- ...filterDOMProps(otherProps),
107
- className: className ?? defaultClassName,
108
- style,
109
- children
110
- };
125
+ return {
126
+ className: computedClassName ?? defaultClassName,
127
+ style: computedStyle,
128
+ children: computedChildren
129
+ };
130
+ }, [className, style, children, defaultClassName, defaultChildren, values]);
111
131
  }
112
132
 
113
133
  export type WithRef<T, E> = T & {ref?: React.ForwardedRef<E>};
@@ -216,7 +236,7 @@ function useAnimation(ref: RefObject<HTMLElement>, isActive: boolean, onEnd: ()
216
236
  let onAnimationEnd = (e: AnimationEvent) => {
217
237
  if (e.target === ref.current) {
218
238
  element.removeEventListener('animationend', onAnimationEnd);
219
- onEnd();
239
+ ReactDOM.flushSync(() => {onEnd();});
220
240
  }
221
241
  };
222
242