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

@react-aria/label

Package Overview
Dependencies
Maintainers
2
Versions
804
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/label

Spectrum UI components in React

  • 3.0.0-nightly.1488
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
950K
decreased by-16.65%
Maintainers
2
Weekly downloads
 
Created

What is @react-aria/label?

@react-aria/label is a library that provides accessible labeling functionality for React components. It helps in associating labels with form elements and other interactive components, ensuring that they are accessible to screen readers and other assistive technologies.

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

Labeling a form field

This feature allows you to associate a label with a form field, ensuring that the label is properly connected to the input element for accessibility.

import { useLabel } from '@react-aria/label';

function MyTextField(props) {
  let { labelProps, fieldProps } = useLabel(props);

  return (
    <div>
      <label {...labelProps}>{props.label}</label>
      <input {...fieldProps} />
    </div>
  );
}

<MyTextField label="Name" />

Custom labeling

This feature allows you to use custom elements for labels, such as a span, while still maintaining proper accessibility.

import { useLabel } from '@react-aria/label';

function CustomLabel(props) {
  let { labelProps, fieldProps } = useLabel(props);

  return (
    <div>
      <span {...labelProps}>{props.label}</span>
      <input {...fieldProps} />
    </div>
  );
}

<CustomLabel label="Email" />

Aria-labelledby

This feature allows you to use the aria-labelledby attribute to associate a label with an input element, which can be useful for more complex labeling scenarios.

import { useLabel } from '@react-aria/label';

function AriaLabeledByExample(props) {
  let { labelProps, fieldProps } = useLabel({ ...props, 'aria-labelledby': 'custom-label' });

  return (
    <div>
      <span id="custom-label">Custom Label</span>
      <input {...fieldProps} />
    </div>
  );
}

<AriaLabeledByExample />

Other packages similar to @react-aria/label

FAQs

Package last updated on 25 Mar 2022

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