Skip to content

Commit 22c301f

Browse files
authored
Highlight updates (#2587)
1 parent 0607a6d commit 22c301f

File tree

6 files changed

+31
-16
lines changed

6 files changed

+31
-16
lines changed

packages/@react-aria/grid/src/useGridCell.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ interface GridCellProps {
3636

3737
interface GridCellAria {
3838
/** Props for the grid cell element. */
39-
gridCellProps: HTMLAttributes<HTMLElement>
39+
gridCellProps: HTMLAttributes<HTMLElement>,
40+
/** Whether the cell is currently in a pressed state. */
41+
isPressed: boolean
4042
}
4143

4244
/**
@@ -75,7 +77,7 @@ export function useGridCell<T, C extends GridCollection<T>>(props: GridCellProps
7577
}
7678
};
7779

78-
let {itemProps} = useSelectableItem({
80+
let {itemProps, isPressed} = useSelectableItem({
7981
selectionManager: state.selectionManager,
8082
key: node.key,
8183
ref,
@@ -223,7 +225,8 @@ export function useGridCell<T, C extends GridCollection<T>>(props: GridCellProps
223225
}
224226

225227
return {
226-
gridCellProps
228+
gridCellProps,
229+
isPressed
227230
};
228231
}
229232

packages/@react-aria/grid/src/useGridRow.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export interface GridRowProps<T> {
2929

3030
export interface GridRowAria {
3131
/** Props for the grid row element. */
32-
rowProps: HTMLAttributes<HTMLElement>
32+
rowProps: HTMLAttributes<HTMLElement>,
33+
/** Whether the row is currently in a pressed state. */
34+
isPressed: boolean
3335
}
3436

3537
/**
@@ -45,7 +47,7 @@ export function useGridRow<T, C extends GridCollection<T>, S extends GridState<T
4547
onAction
4648
} = props;
4749

48-
let {itemProps} = useSelectableItem({
50+
let {itemProps, isPressed} = useSelectableItem({
4951
selectionManager: state.selectionManager,
5052
key: node.key,
5153
ref,
@@ -67,6 +69,7 @@ export function useGridRow<T, C extends GridCollection<T>, S extends GridState<T
6769
}
6870

6971
return {
70-
rowProps
72+
rowProps,
73+
isPressed
7174
};
7275
}

packages/@react-aria/selection/src/useSelectableItem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
198198
});
199199

200200
// Pressing the Enter key with selectionBehavior = 'replace' performs an action (i.e. navigation).
201-
let onKeyDown = hasSecondaryAction ? (e: KeyboardEvent) => {
201+
let onKeyUp = hasSecondaryAction ? (e: KeyboardEvent) => {
202202
if (e.key === 'Enter') {
203203
onAction();
204204
}
@@ -209,7 +209,7 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
209209
itemProps,
210210
allowsSelection || hasPrimaryAction ? pressProps : {},
211211
hasSecondaryAction ? longPressProps : {},
212-
{onKeyDown, onDoubleClick}
212+
{onKeyUp, onDoubleClick}
213213
),
214214
isPressed
215215
};

packages/@react-aria/table/src/useTableCell.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ interface TableCellProps {
2727

2828
interface TableCellAria {
2929
/** Props for the table cell element. */
30-
gridCellProps: HTMLAttributes<HTMLElement>
30+
gridCellProps: HTMLAttributes<HTMLElement>,
31+
/** Whether the cell is currently in a pressed state. */
32+
isPressed: boolean
3133
}
3234

3335
/**
@@ -37,7 +39,7 @@ interface TableCellAria {
3739
* @param ref - The ref attached to the cell element.
3840
*/
3941
export function useTableCell<T>(props: TableCellProps, state: TableState<T>, ref: RefObject<HTMLElement>): TableCellAria {
40-
let {gridCellProps} = useGridCell(props, state, ref);
42+
let {gridCellProps, isPressed} = useGridCell(props, state, ref);
4143

4244
let columnKey = props.node.column.key;
4345
if (state.collection.rowHeaderColumnKeys.has(columnKey)) {
@@ -46,6 +48,7 @@ export function useTableCell<T>(props: TableCellProps, state: TableState<T>, ref
4648
}
4749

4850
return {
49-
gridCellProps
51+
gridCellProps,
52+
isPressed
5053
};
5154
}

packages/@react-aria/table/src/useTableHeaderRow.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {GridRowAria, GridRowProps} from '@react-aria/grid';
14-
import {RefObject} from 'react';
13+
import {GridRowProps} from '@react-aria/grid';
14+
import {HTMLAttributes, RefObject} from 'react';
1515
import {TableState} from '@react-stately/table';
1616

17+
export interface TableHeaderRowAria {
18+
/** Props for the grid row element. */
19+
rowProps: HTMLAttributes<HTMLElement>
20+
}
21+
1722
/**
1823
* Provides the behavior and accessibility implementation for a header row in a table.
1924
* @param props - Props for the row.
2025
* @param state - State of the table, as returned by `useTableState`.
2126
*/
2227
// eslint-disable-next-line @typescript-eslint/no-unused-vars
23-
export function useTableHeaderRow<T>(props: GridRowProps<T>, state: TableState<T>, ref: RefObject<HTMLElement>): GridRowAria {
28+
export function useTableHeaderRow<T>(props: GridRowProps<T>, state: TableState<T>, ref: RefObject<HTMLElement>): TableHeaderRowAria {
2429
let {node, isVirtualized} = props;
2530
let rowProps = {
2631
role: 'row'

packages/@react-aria/table/src/useTableRow.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ import {TableState} from '@react-stately/table';
2323
*/
2424
export function useTableRow<T>(props: GridRowProps<T>, state: TableState<T>, ref: RefObject<HTMLElement>): GridRowAria {
2525
let {node} = props;
26-
let {rowProps} = useGridRow<T, TableCollection<T>, TableState<T>>(props, state, ref);
26+
let {rowProps, isPressed} = useGridRow<T, TableCollection<T>, TableState<T>>(props, state, ref);
2727
return {
2828
rowProps: {
2929
...rowProps,
3030
'aria-labelledby': getRowLabelledBy(state, node.key)
31-
}
31+
},
32+
isPressed
3233
};
3334
}

0 commit comments

Comments
 (0)