Security News
npm Updates Search Experience with New Objective Sorting Options
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
@react-aria/gridlist
Advanced tools
@react-aria/gridlist is a React library that provides accessible components and hooks for creating grid lists. It is part of the React Aria collection, which focuses on providing accessible UI components that adhere to WAI-ARIA standards.
GridList
This code demonstrates how to create a basic grid list using the @react-aria/gridlist package. The useGridList hook is used to manage the grid list state and properties, while the useGridListItem hook is used for individual grid list items.
import { useGridList, useGridListItem } from '@react-aria/gridlist';
import { useListState } from '@react-stately/list';
function GridListExample(props) {
let state = useListState(props);
let ref = React.useRef();
let { gridProps } = useGridList(props, state, ref);
return (
<div {...gridProps} ref={ref}>
{[...state.collection].map(item => (
<GridListItem key={item.key} item={item} state={state} />
))}
</div>
);
}
function GridListItem({ item, state }) {
let ref = React.useRef();
let { gridListItemProps } = useGridListItem({ node: item }, state, ref);
return (
<div {...gridListItemProps} ref={ref}>
{item.rendered}
</div>
);
}
Keyboard Navigation
This example extends the basic grid list to include keyboard navigation. By setting the tabIndex to 0 on each grid list item, users can navigate through the items using the keyboard.
import { useGridList, useGridListItem } from '@react-aria/gridlist';
import { useListState } from '@react-stately/list';
function GridListWithKeyboardNavigation(props) {
let state = useListState(props);
let ref = React.useRef();
let { gridProps } = useGridList(props, state, ref);
return (
<div {...gridProps} ref={ref}>
{[...state.collection].map(item => (
<GridListItem key={item.key} item={item} state={state} />
))}
</div>
);
}
function GridListItem({ item, state }) {
let ref = React.useRef();
let { gridListItemProps } = useGridListItem({ node: item }, state, ref);
return (
<div {...gridListItemProps} ref={ref} tabIndex={0}>
{item.rendered}
</div>
);
}
react-virtualized provides a set of components for efficiently rendering large lists and tabular data. It focuses on performance and virtualization, which makes it suitable for handling large datasets. Unlike @react-aria/gridlist, it does not specifically focus on accessibility.
react-window is a lightweight alternative to react-virtualized for rendering large lists and grids. It offers similar performance benefits but with a smaller bundle size. Like react-virtualized, it does not emphasize accessibility features as @react-aria/gridlist does.
react-table is a library for building fast and flexible tables in React. It provides a lot of customization options and supports features like sorting, filtering, and pagination. While it is powerful for table data, it does not inherently provide the same level of accessibility as @react-aria/gridlist.
This package is part of react-spectrum. See the repo for more details.
FAQs
Spectrum UI components in React
The npm package @react-aria/gridlist receives a total of 576,502 weekly downloads. As such, @react-aria/gridlist popularity was classified as popular.
We found that @react-aria/gridlist demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.