ArrowKeyStepper.md

November 13, 2019 · View on GitHub

ArrowKeyStepper

High-order component that decorates another virtualized component and responds to arrow-key events by scrolling one row or column at a time. This provides a snap-to behavior rather than the default browser scrolling behavior.

Note that unlike the other HOCs in react-virtualized, the ArrowKeyStepper adds a <div> element around its children in order to attach a key-down event handler. The appearance of this wrapper element can be customized using the className property.

Prop Types

PropertyTypeRequired?Description
childrenFunctionFunction responsible for rendering children. This function should implement the following signature: ({ onSectionRendered: Function, scrollToColumn: number, scrollToRow: number }) => PropTypes.element
classNameStringCSS class name to attach to the wrapper <div>.
columnCountNumberNumber of columns in grid; for Table and List this property should always be 1.
disabledBooleanDisables all scrolling using arrow-keys; defaults to false
isControlledBooleanThis component is "controlled"; it will not update scrollToColumn or scrollToRow. This property should be used with onScrollToChange.
mode"edges" or "cells"Controls behavior of stepper when arrow key direction changes. "cells" means that the index will only increment or decrement by 1; "edges" (default) means that the opposite side of the grid will be incremented.
onScrollToChangeFunctionCalled when arrow key navigation should update the current scroll-to values.
rowCountNumberNumber of rows in grid.
scrollToColumnNumberOptional default/initial scrollToColumn value
scrollToRowNumberOptional default/initial scrollToRow value

Public Methods

setScrollIndexes ({ scrollToColumn: number, scrollToRow: number })

Override the local state of the component with new values for scrollToRow and scrollToColumn.

Children function

The child function is passed the following named parameters:

ParameterTypeDescription
onSectionRenderedFunctionPass-through callback to be attached to child component; informs the key-stepper which range of cells are currently visible.
scrollToColumnNumberSpecifies which column in the child component should be visible
scrollToRowNumberSpecifies which row in the child component should be visible

Examples

You can decorate any virtualized component (eg. Table, Grid, or List) with arrow-key snapping like so:

import React from 'react';
import ReactDOM from 'react-dom';
import {ArrowKeyStepper, Grid} from 'react-virtualized';
import 'react-virtualized/styles.css'; // only needs to be imported once

ReactDOM.render(
  <ArrowKeyStepper columnCount={columnCount} rowCount={rowCount}>
    {({onSectionRendered, scrollToColumn, scrollToRow}) => (
      <Grid
        columnCount={columnCount}
        onSectionRendered={onSectionRendered}
        rowCount={rowCount}
        scrollToColumn={scrollToColumn}
        scrollToRow={scrollToRow}
        {...otherGridProps}
      />
    )}
  </ArrowKeyStepper>,
  document.getElementById('example'),
);