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

@react-aria/button

Package Overview
Dependencies
Maintainers
2
Versions
846
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/button

Spectrum UI components in React

  • 3.0.0-nightly-b0f156972-241202
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
823K
decreased by-22.15%
Maintainers
2
Weekly downloads
 
Created

What is @react-aria/button?

@react-aria/button is a React library that provides accessible button components. It is part of the React Aria collection of hooks and components designed to help developers build accessible web applications. The package ensures that buttons are keyboard and screen reader accessible, adhering to WAI-ARIA guidelines.

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

Basic Button

This code demonstrates how to create a basic accessible button using the useButton hook from @react-aria/button. The useButton hook provides the necessary props to ensure the button is accessible.

import { useButton } from '@react-aria/button';
import { useRef } from 'react';

function MyButton(props) {
  let ref = useRef();
  let { buttonProps } = useButton(props, ref);

  return (
    <button {...buttonProps} ref={ref}>
      {props.children}
    </button>
  );
}

Button with Event Handling

This example shows how to handle events with the useButton hook. The onPress event is used to trigger an alert when the button is pressed.

import { useButton } from '@react-aria/button';
import { useRef } from 'react';

function MyButton(props) {
  let ref = useRef();
  let { buttonProps } = useButton({
    ...props,
    onPress: () => alert('Button pressed!')
  }, ref);

  return (
    <button {...buttonProps} ref={ref}>
      {props.children}
    </button>
  );
}

Disabled Button

This code demonstrates how to create a disabled button using the useButton hook. The isDisabled property ensures that the button is not interactive.

import { useButton } from '@react-aria/button';
import { useRef } from 'react';

function MyButton(props) {
  let ref = useRef();
  let { buttonProps } = useButton({
    ...props,
    isDisabled: true
  }, ref);

  return (
    <button {...buttonProps} ref={ref} disabled>
      {props.children}
    </button>
  );
}

Other packages similar to @react-aria/button

FAQs

Package last updated on 02 Dec 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