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

@react-aria/checkbox

Package Overview
Dependencies
Maintainers
2
Versions
819
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/checkbox

Spectrum UI components in React

  • 3.0.0-nightly-987f174ba-241015
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
998K
increased by13.69%
Maintainers
2
Weekly downloads
 
Created

What is @react-aria/checkbox?

@react-aria/checkbox is a React library that provides accessible checkbox components. It is part of the React Aria collection, which aims to provide a set of hooks and components that help developers build accessible web applications. The package ensures that checkboxes are fully accessible and compliant with ARIA standards.

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

Basic Checkbox

This code demonstrates how to create a basic accessible checkbox using the @react-aria/checkbox package. The useCheckbox hook is used to manage the checkbox state and ARIA attributes.

import { useCheckbox } from '@react-aria/checkbox';
import { useToggleState } from '@react-stately/toggle';

function Checkbox(props) {
  let state = useToggleState(props);
  let ref = React.useRef();
  let { inputProps } = useCheckbox(props, state, ref);

  return (
    <label>
      <input {...inputProps} ref={ref} />
      {props.children}
    </label>
  );
}

Indeterminate Checkbox

This code demonstrates how to create an indeterminate checkbox using the @react-aria/checkbox package. The isIndeterminate property is used to set the checkbox to an indeterminate state.

import { useCheckbox } from '@react-aria/checkbox';
import { useToggleState } from '@react-stately/toggle';

function IndeterminateCheckbox(props) {
  let state = useToggleState(props);
  let ref = React.useRef();
  let { inputProps } = useCheckbox({ ...props, isIndeterminate: true }, state, ref);

  return (
    <label>
      <input {...inputProps} ref={ref} />
      {props.children}
    </label>
  );
}

Custom Styled Checkbox

This code demonstrates how to create a custom styled checkbox using the @react-aria/checkbox package. The checkbox is styled with custom colors and layout.

import { useCheckbox } from '@react-aria/checkbox';
import { useToggleState } from '@react-stately/toggle';

function CustomCheckbox(props) {
  let state = useToggleState(props);
  let ref = React.useRef();
  let { inputProps } = useCheckbox(props, state, ref);

  return (
    <label style={{ display: 'flex', alignItems: 'center' }}>
      <input {...inputProps} ref={ref} style={{ marginRight: 8 }} />
      <span style={{ color: state.isSelected ? 'green' : 'red' }}>{props.children}</span>
    </label>
  );
}

Other packages similar to @react-aria/checkbox

FAQs

Package last updated on 15 Oct 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