@react-spectrum/table 3.3.2-nightly.3458 → 3.3.2

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/TableView.tsx CHANGED
@@ -15,7 +15,7 @@ import {chain, mergeProps, useLayoutEffect} from '@react-aria/utils';
15
15
  import {Checkbox} from '@react-spectrum/checkbox';
16
16
  import {classNames, useDOMRef, useFocusableRef, useStyleProps, useUnwrapDOMRef} from '@react-spectrum/utils';
17
17
  import {DOMRef, FocusableRef} from '@react-types/shared';
18
- import {FocusRing, FocusScope, useFocusRing} from '@react-aria/focus';
18
+ import {FocusRing, useFocusRing} from '@react-aria/focus';
19
19
  import {GridNode} from '@react-types/grid';
20
20
  // @ts-ignore
21
21
  import intlMessages from '../intl/*.json';
@@ -81,8 +81,7 @@ interface TableContextValue<T> {
81
81
  state: TableState<T>,
82
82
  layout: TableLayout<T>,
83
83
  columnState: TableColumnResizeState<T>,
84
- headerRowHovered: boolean,
85
- isEmpty: boolean
84
+ headerRowHovered: boolean
86
85
  }
87
86
 
88
87
  const TableContext = React.createContext<TableContextValue<unknown>>(null);
@@ -253,7 +252,6 @@ function TableView<T extends object>(props: SpectrumTableProps<T>, ref: DOMRef<H
253
252
  return <TableSelectAllCell column={item} />;
254
253
  }
255
254
 
256
- // TODO: consider this case, what if we have hidden headers and a empty table
257
255
  if (item.props.hideHeader) {
258
256
  return (
259
257
  <TooltipTrigger placement="top" trigger="focus">
@@ -306,13 +304,11 @@ function TableView<T extends object>(props: SpectrumTableProps<T>, ref: DOMRef<H
306
304
  setHorizontalScollbarVisible(bodyRef.current.clientHeight + 2 < bodyRef.current.offsetHeight);
307
305
  }
308
306
  }, []);
309
- let {isFocusVisible, focusProps} = useFocusRing();
310
- let isEmpty = state.collection.size === 0;
311
307
 
312
308
  return (
313
- <TableContext.Provider value={{state, layout, columnState, headerRowHovered, isEmpty}}>
309
+ <TableContext.Provider value={{state, layout, columnState, headerRowHovered}}>
314
310
  <TableVirtualizer
315
- {...mergeProps(gridProps, focusProps)}
311
+ {...gridProps}
316
312
  {...styleProps}
317
313
  className={
318
314
  classNames(
@@ -341,14 +337,13 @@ function TableView<T extends object>(props: SpectrumTableProps<T>, ref: DOMRef<H
341
337
  onVisibleRectChange={onVisibleRectChange}
342
338
  domRef={domRef}
343
339
  bodyRef={bodyRef}
344
- isFocusVisible={isFocusVisible}
345
340
  getColumnWidth={columnState.getColumnWidth} />
346
341
  </TableContext.Provider>
347
342
  );
348
343
  }
349
344
 
350
345
  // This is a custom Virtualizer that also has a header that syncs its scroll position with the body.
351
- function TableVirtualizer({layout, collection, focusedKey, renderView, renderWrapper, domRef, bodyRef, setTableWidth, getColumnWidth, onVisibleRectChange: onVisibleRectChangeProp, isFocusVisible, ...otherProps}) {
346
+ function TableVirtualizer({layout, collection, focusedKey, renderView, renderWrapper, domRef, bodyRef, setTableWidth, getColumnWidth, onVisibleRectChange: onVisibleRectChangeProp, ...otherProps}) {
352
347
  let {direction} = useLocale();
353
348
  let headerRef = useRef<HTMLDivElement>();
354
349
  let loadingState = collection.body.props.loadingState;
@@ -419,48 +414,37 @@ function TableVirtualizer({layout, collection, focusedKey, renderView, renderWra
419
414
  }, [state.contentSize, state.virtualizer, state.isAnimating, onLoadMore, isLoading]);
420
415
 
421
416
  return (
422
- <FocusScope>
417
+ <div
418
+ {...mergeProps(otherProps, virtualizerProps)}
419
+ ref={domRef}>
423
420
  <div
424
- // Override virtualizer provided tabindex if TableView is empty so it is tabbable.
425
- {...mergeProps(otherProps, virtualizerProps, collection.size === 0 && {tabIndex: 0})}
426
- ref={domRef}>
427
- <div
428
- role="presentation"
429
- className={classNames(styles, 'spectrum-Table-headWrapper')}
430
- style={{
431
- width: visibleRect.width,
432
- height: headerHeight,
433
- overflow: 'hidden',
434
- position: 'relative',
435
- willChange: state.isScrolling ? 'scroll-position' : '',
436
- transition: state.isAnimating ? `none ${state.virtualizer.transitionDuration}ms` : undefined
437
- }}
438
- ref={headerRef}>
439
- {state.visibleViews[0]}
440
- </div>
441
- <ScrollView
442
- role="presentation"
443
- className={
444
- classNames(
445
- styles,
446
- 'spectrum-Table-body',
447
- {
448
- 'focus-ring': isFocusVisible
449
- }
450
- )
451
- }
452
- style={{flex: 1}}
453
- innerStyle={{overflow: 'visible', transition: state.isAnimating ? `none ${state.virtualizer.transitionDuration}ms` : undefined}}
454
- ref={bodyRef}
455
- contentSize={state.contentSize}
456
- onVisibleRectChange={chain(onVisibleRectChange, onVisibleRectChangeProp)}
457
- onScrollStart={state.startScrolling}
458
- onScrollEnd={state.endScrolling}
459
- onScroll={onScroll}>
460
- {state.visibleViews[1]}
461
- </ScrollView>
421
+ role="presentation"
422
+ className={classNames(styles, 'spectrum-Table-headWrapper')}
423
+ style={{
424
+ width: visibleRect.width,
425
+ height: headerHeight,
426
+ overflow: 'hidden',
427
+ position: 'relative',
428
+ willChange: state.isScrolling ? 'scroll-position' : '',
429
+ transition: state.isAnimating ? `none ${state.virtualizer.transitionDuration}ms` : undefined
430
+ }}
431
+ ref={headerRef}>
432
+ {state.visibleViews[0]}
462
433
  </div>
463
- </FocusScope>
434
+ <ScrollView
435
+ role="presentation"
436
+ className={classNames(styles, 'spectrum-Table-body')}
437
+ style={{flex: 1}}
438
+ innerStyle={{overflow: 'visible', transition: state.isAnimating ? `none ${state.virtualizer.transitionDuration}ms` : undefined}}
439
+ ref={bodyRef}
440
+ contentSize={state.contentSize}
441
+ onVisibleRectChange={chain(onVisibleRectChange, onVisibleRectChangeProp)}
442
+ onScrollStart={state.startScrolling}
443
+ onScrollEnd={state.endScrolling}
444
+ onScroll={onScroll}>
445
+ {state.visibleViews[1]}
446
+ </ScrollView>
447
+ </div>
464
448
  );
465
449
  }
466
450
 
@@ -477,8 +461,7 @@ function TableHeader({children, ...otherProps}) {
477
461
  function TableColumnHeader(props) {
478
462
  let {column} = props;
479
463
  let ref = useRef<HTMLDivElement>(null);
480
- let {state, isEmpty} = useTableContext();
481
- let {pressProps, isPressed} = usePress({isDisabled: isEmpty});
464
+ let {state} = useTableContext();
482
465
  let {columnHeaderProps} = useTableColumnHeader({
483
466
  node: column,
484
467
  isVirtualized: true
@@ -486,9 +469,9 @@ function TableColumnHeader(props) {
486
469
 
487
470
  let columnProps = column.props as SpectrumColumnProps<unknown>;
488
471
 
489
- let {hoverProps, isHovered} = useHover({...props, isDisabled: isEmpty});
472
+ let {hoverProps, isHovered} = useHover(props);
490
473
 
491
- const allProps = [columnHeaderProps, hoverProps, pressProps];
474
+ const allProps = [columnHeaderProps, hoverProps];
492
475
 
493
476
  return (
494
477
  <FocusRing focusRingClass={classNames(styles, 'focus-ring')}>
@@ -500,7 +483,6 @@ function TableColumnHeader(props) {
500
483
  styles,
501
484
  'spectrum-Table-headCell',
502
485
  {
503
- 'is-active': isPressed,
504
486
  'is-resizable': columnProps.allowsResizing,
505
487
  'is-sortable': columnProps.allowsSorting,
506
488
  'is-sorted-desc': state.sortDescriptor?.column === column.key && state.sortDescriptor?.direction === 'descending',
@@ -531,9 +513,8 @@ function TableColumnHeader(props) {
531
513
  }
532
514
 
533
515
  let _TableColumnHeaderButton = (props, ref: FocusableRef<HTMLDivElement>) => {
534
- let {isEmpty} = useTableContext();
535
516
  let domRef = useFocusableRef(ref);
536
- let {buttonProps} = useButton({...props, elementType: 'div', isDisabled: isEmpty}, domRef);
517
+ let {buttonProps} = useButton({...props, elementType: 'div'}, domRef);
537
518
  return (
538
519
  <div className={classNames(styles, 'spectrum-Table-headCellContents')}>
539
520
  <FocusRing focusRingClass={classNames(styles, 'focus-ring')}>
@@ -549,17 +530,16 @@ function ResizableTableColumnHeader(props) {
549
530
  let ref = useRef(null);
550
531
  let triggerRef = useRef(null);
551
532
  let resizingRef = useRef(null);
552
- let {state, columnState, headerRowHovered, isEmpty} = useTableContext();
533
+ let {state, columnState, headerRowHovered} = useTableContext();
553
534
  let stringFormatter = useLocalizedStringFormatter(intlMessages);
554
- let {pressProps, isPressed} = usePress({isDisabled: isEmpty});
555
535
  let {columnHeaderProps} = useTableColumnHeader({
556
536
  node: column,
557
537
  isVirtualized: true,
558
538
  hasMenu: true
559
539
  }, state, ref);
560
- let {hoverProps, isHovered} = useHover({...props, isDisabled: isEmpty});
540
+ let {hoverProps, isHovered} = useHover(props);
561
541
 
562
- const allProps = [columnHeaderProps, hoverProps, pressProps];
542
+ const allProps = [columnHeaderProps, hoverProps];
563
543
 
564
544
  let columnProps = column.props as SpectrumColumnProps<unknown>;
565
545
 
@@ -609,7 +589,7 @@ function ResizableTableColumnHeader(props) {
609
589
  }
610
590
  }, [columnState.currentlyResizingColumn, column.key]);
611
591
 
612
- let showResizer = !isEmpty && (headerRowHovered || columnState.currentlyResizingColumn != null);
592
+ let showResizer = headerRowHovered || columnState.currentlyResizingColumn != null;
613
593
 
614
594
  return (
615
595
  <FocusRing focusRingClass={classNames(styles, 'focus-ring')}>
@@ -621,7 +601,6 @@ function ResizableTableColumnHeader(props) {
621
601
  styles,
622
602
  'spectrum-Table-headCell',
623
603
  {
624
- 'is-active': isPressed,
625
604
  'is-resizable': columnProps.allowsResizing,
626
605
  'is-sortable': columnProps.allowsSorting,
627
606
  'is-sorted-desc': state.sortDescriptor?.column === column.key && state.sortDescriptor?.direction === 'descending',
@@ -706,6 +685,7 @@ function TableSelectAllCell({column}) {
706
685
  }
707
686
  <Checkbox
708
687
  {...checkboxProps}
688
+ isDisabled={isSingleSelectionMode}
709
689
  isEmphasized
710
690
  UNSAFE_style={isSingleSelectionMode ? {visibility: 'hidden'} : undefined}
711
691
  UNSAFE_className={classNames(styles, 'spectrum-Table-checkbox')} />