Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-aria/gridlist

Package Overview
Dependencies
Maintainers
2
Versions
476
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/gridlist

Spectrum UI components in React

  • 3.7.6-nightly.4507
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
690K
increased by5.85%
Maintainers
2
Weekly downloads
 
Created

What is @react-aria/gridlist?

@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.

What are @react-aria/gridlist's main functionalities?

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>
  );
}

Other packages similar to @react-aria/gridlist

FAQs

Package last updated on 13 Mar 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc