Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4d25901
A little remaining Table work
snowystinger Sep 17, 2020
7fcb2f4
Wrote some tests
snowystinger Sep 18, 2020
2cf8522
Wiring up disabledKeys, it's close, the checkboxes are disabled, but …
snowystinger Sep 18, 2020
0f148f9
fix lint
snowystinger Sep 20, 2020
aeafa14
disabling hover styles and selection of disabled rows via click/selec…
LFDanLu Sep 21, 2020
ce75c25
removing active state from disabled rows and making them grey out
LFDanLu Sep 21, 2020
4bcb7ef
fixing table delegate getKeyBelow so it choses enabled rows only
LFDanLu Sep 21, 2020
ac8731a
adding tests for disabled rows
LFDanLu Sep 22, 2020
0f3eafe
Adding disabled keys to SelectionManager so they aren't included in b…
LFDanLu Sep 22, 2020
52b3507
removing disabled table row styles
LFDanLu Sep 22, 2020
e2a1411
tentative fix to stop "select all" div from being keyboard focuses wh…
LFDanLu Sep 22, 2020
211d7f5
disable focusing first column header via click if selectionMode is si…
LFDanLu Sep 22, 2020
212a66a
Merge branch 'main' into table-work
LFDanLu Sep 23, 2020
e3baf49
Addressing review comments
LFDanLu Sep 23, 2020
fea3832
adding dep to useTable memo
LFDanLu Sep 23, 2020
1333eee
Merge branch 'table-work' of https://github.com/adobe/react-spectrum …
LFDanLu Sep 23, 2020
5a44a1c
Revert "tentative fix to stop "select all" div from being keyboard fo…
LFDanLu Oct 2, 2020
bb1062d
adding aria-disabled to select all header
LFDanLu Oct 2, 2020
c3d0e93
Merge branch 'main' into table-work
LFDanLu Oct 12, 2020
03021af
Merge branch 'main' of https://github.com/adobe/react-spectrum into t…
LFDanLu Oct 20, 2020
7d0aee2
making SelectionManager clearSelection call setSelectedKeys only if t…
LFDanLu Oct 21, 2020
8bb1427
Hiding checkbox and adding focus ring to select all cell in single se…
LFDanLu Oct 22, 2020
44d04cc
allow user to focus disabled rows/cells
LFDanLu Oct 22, 2020
da1eecc
fixing page up/down behavior
LFDanLu Oct 23, 2020
2d0a07e
refining page down/up fix in table and adding tests
LFDanLu Oct 23, 2020
ab28baa
adding select function to SelectionManager
LFDanLu Oct 23, 2020
77f16ef
Merge branch 'main' into table-work
LFDanLu Oct 23, 2020
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
6 changes: 3 additions & 3 deletions packages/@adobe/spectrum-css-temp/components/table/skin.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ tbody.spectrum-Table-body {
box-sizing: border-box;

.spectrum-Table-cellWrapper {
/* Add an opaque background so that the transparent background
/* Add an opaque background so that the transparent background
* on the cell doesn't allow other cells to show through sticky cells. */
background-color: var(--spectrum-table-background-color);
}
Expand All @@ -134,7 +134,7 @@ tbody.spectrum-Table-body {
}
}

&:active .spectrum-Table-cell {
&:active .spectrum-Table-cell:not(.is-disabled) {
background-color: var(--spectrum-table-row-background-color-down);
}

Expand Down Expand Up @@ -200,7 +200,7 @@ tbody.spectrum-Table-body {
background-color: var(--spectrum-table-quiet-row-background-color-hover);
}

&:active .spectrum-Table-cell {
&:active .spectrum-Table-cell:not(.is-disabled) {
background-color: var(--spectrum-table-quiet-row-background-color-down);
}

Expand Down
18 changes: 1 addition & 17 deletions packages/@react-aria/selection/src/useSelectableItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,7 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
focus
} = options;

let onSelect = (e: PressEvent | PointerEvent) => {
if (manager.selectionMode === 'none') {
return;
}

if (manager.selectionMode === 'single') {
if (manager.isSelected(key) && !manager.disallowEmptySelection) {
manager.toggleSelection(key);
} else {
manager.replaceSelection(key);
}
} else if (e.shiftKey) {
manager.extendSelection(key);
} else if (manager) {
manager.toggleSelection(key);
}
};
let onSelect = (e: PressEvent | PointerEvent) => manager.select(key, e);

// Focus the associated DOM node when this item becomes the focusedKey
let isFocused = key === manager.focusedKey;
Expand Down
31 changes: 19 additions & 12 deletions packages/@react-aria/table/src/TableKeyboardDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class TableKeyboardDelegate<T> implements KeyboardDelegate {
return child.key;
}

let firstItem = this.collection.getItem(this.collection.getFirstKey());
let firstItem = this.collection.getItem(this.getFirstKey());
return [...firstItem.childNodes][startItem.index].key;
}

Expand All @@ -98,8 +98,8 @@ export class TableKeyboardDelegate<T> implements KeyboardDelegate {
key = startItem.parentKey;
}

// Find the next enabled item
key = this.findNextKey(item => item.type === 'item' && !this.disabledKeys.has(item.key), key);
// Find the next item
key = this.findNextKey(item => item.type === 'item', key);
if (key != null) {
// If focus was on a cell, focus the cell with the same index in the next row.
if (this.isCell(startItem)) {
Expand Down Expand Up @@ -133,8 +133,8 @@ export class TableKeyboardDelegate<T> implements KeyboardDelegate {
key = startItem.parentKey;
}

// Find the previous enabled item
key = this.findPreviousKey(item => item.type === 'item' && !this.disabledKeys.has(item.key), key);
// Find the previous item
key = this.findPreviousKey(item => item.type === 'item', key);
if (key != null) {
// If focus was on a cell, focus the cell with the same index in the previous row.
if (this.isCell(startItem)) {
Expand Down Expand Up @@ -282,8 +282,8 @@ export class TableKeyboardDelegate<T> implements KeyboardDelegate {
}
}

// Find the first enabled row
key = this.findNextKey(item => item.type === 'item' && !this.disabledKeys.has(item.key));
// Find the first row
key = this.findNextKey(item => item.type === 'item');

// If global flag is set, focus the first cell in the first row.
if (key != null && item && this.isCell(item) && global) {
Expand Down Expand Up @@ -312,8 +312,8 @@ export class TableKeyboardDelegate<T> implements KeyboardDelegate {
}
}

// Find the last enabled row
key = this.findPreviousKey(item => item.type === 'item' && !this.disabledKeys.has(item.key));
// Find the last row
key = this.findPreviousKey(item => item.type === 'item');

// If global flag is set, focus the last cell in the last row.
if (key != null && item && this.isCell(item) && global) {
Expand Down Expand Up @@ -375,16 +375,23 @@ export class TableKeyboardDelegate<T> implements KeyboardDelegate {

getKeyPageBelow(key: Key) {
let itemRect = this.getItemRect(key);

if (!itemRect) {
return null;
}

let pageHeight = this.getPageHeight();
let pageY = Math.min(this.getContentHeight() - pageHeight, itemRect.y + pageHeight);
let pageY = Math.min(this.getContentHeight(), itemRect.y + pageHeight);

while (itemRect && itemRect.maxY < pageY) {
key = this.getKeyBelow(key);
itemRect = this.getItemRect(key);
let nextKey = this.getKeyBelow(key);
itemRect = this.getItemRect(nextKey);

// Guard against case where maxY of the last key is barely less than pageY due to rounding
// and thus it attempts to set key to null
if (nextKey != null) {
key = nextKey;
}
}

return key;
Expand Down
8 changes: 5 additions & 3 deletions packages/@react-aria/table/src/useTableCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {useSelectableItem} from '@react-aria/selection';
interface GridCellProps {
node: Node<unknown>,
ref: RefObject<HTMLElement>,
isVirtualized?: boolean
isVirtualized?: boolean,
isDisabled?: boolean
}

interface GridCellAria {
Expand All @@ -32,7 +33,8 @@ export function useTableCell<T>(props: GridCellProps, state: TableState<T>): Gri
let {
node,
ref,
isVirtualized
isVirtualized,
isDisabled
} = props;

// Handles focusing the cell. If there is a focusable child,
Expand All @@ -56,7 +58,7 @@ export function useTableCell<T>(props: GridCellProps, state: TableState<T>): Gri
});

// TODO: move into useSelectableItem?
let {pressProps} = usePress(itemProps);
let {pressProps} = usePress({...itemProps, isDisabled});

// Grid cells can have focusable elements inside them. In this case, focus should
// be marshalled to that element rather than focusing the cell itself.
Expand Down
7 changes: 4 additions & 3 deletions packages/@react-aria/table/src/useTableColumnHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ interface ColumnHeaderProps {
node: Node<unknown>,
ref: RefObject<HTMLElement>,
isVirtualized?: boolean,
colspan?: number
colspan?: number,
isDisabled?: boolean
}

interface ColumnHeaderAria {
columnHeaderProps: HTMLAttributes<HTMLElement>
}

export function useTableColumnHeader<T>(props: ColumnHeaderProps, state: TableState<T>): ColumnHeaderAria {
let {node, colspan, ref} = props;
let {node, colspan, ref, isDisabled} = props;
let {gridCellProps} = useTableCell(props, state);

let {pressProps} = usePress({
isDisabled: !node.props.allowsSorting,
isDisabled: !node.props.allowsSorting || isDisabled,
onPress() {
state.sort(node.key);
}
Expand Down
8 changes: 5 additions & 3 deletions packages/@react-aria/table/src/useTableRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ interface RowProps {
node: Node<unknown>,
ref?: RefObject<HTMLElement>,
isVirtualized?: boolean,
isSelected?: boolean
isSelected?: boolean,
isDisabled?: boolean
}

interface RowAria {
Expand All @@ -33,7 +34,8 @@ export function useTableRow<T>(props: RowProps, state: TableState<T>): RowAria {
node,
ref,
isVirtualized,
isSelected
isSelected,
isDisabled
} = props;

let {itemProps} = useSelectableItem({
Expand All @@ -44,7 +46,7 @@ export function useTableRow<T>(props: RowProps, state: TableState<T>): RowAria {
});

// TODO: move into useSelectableItem?
let {pressProps} = usePress(itemProps);
let {pressProps} = usePress({...itemProps, isDisabled});

let rowProps: HTMLAttributes<HTMLElement> = {
role: 'row',
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-aria/table/src/useTableRowHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {useTableCell} from './useTableCell';
interface RowHeaderProps {
node: TableNode<unknown>,
ref: RefObject<HTMLElement>,
isVirtualized?: boolean
isVirtualized?: boolean,
isDisabled?: boolean
}

interface RowHeaderAria {
Expand Down
13 changes: 9 additions & 4 deletions packages/@react-aria/table/src/useTableSelectionCheckbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {TableState} from '@react-stately/table';
import {useId} from '@react-aria/utils';

interface SelectionCheckboxProps {
key: Key
key: Key,
isDisabled?: boolean
}

interface SelectionCheckboxAria {
Expand All @@ -26,19 +27,23 @@ interface SelectionCheckboxAria {

export function useTableSelectionCheckbox<T>(props: SelectionCheckboxProps, state: TableState<T>): SelectionCheckboxAria {
let {
key
key,
isDisabled
} = props;

let manager = state.selectionManager;
let checkboxId = useId();
let isSelected = state.selectionManager.isSelected(key);
let isSelected = state.selectionManager.isSelected(key) && !isDisabled;

let onChange = () => manager.select(key);

return {
checkboxProps: {
id: checkboxId,
'aria-label': 'Select',
'aria-labelledby': `${checkboxId} ${getRowLabelledBy(state, key)}`,
isSelected,
onChange: () => state.selectionManager.toggleSelection(key)
onChange
}
};
}
Expand Down
Loading