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

@react-aria/slider

Package Overview
Dependencies
Maintainers
2
Versions
792
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/slider

Slider

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

Version published
Weekly downloads
528K
decreased by-39.88%
Maintainers
2
Weekly downloads
 
Created

What is @react-aria/slider?

@react-aria/slider is a React library that provides accessible slider components. It is part of the React Aria collection of hooks and components that help build accessible web applications. The package offers a range of features to create sliders that are keyboard navigable and screen reader friendly.

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

Single Slider

This code demonstrates how to create a single slider using @react-aria/slider. It includes the necessary hooks and components to ensure the slider is accessible.

import { useSlider, useSliderThumb } from '@react-aria/slider';
import { useSliderState } from '@react-stately/slider';
import { VisuallyHidden } from '@react-aria/visually-hidden';
import { useRef } from 'react';

function SingleSlider(props) {
  let trackRef = useRef(null);
  let state = useSliderState(props);
  let { groupProps, trackProps, thumbProps } = useSlider(props, state, trackRef);
  let { thumbProps: thumbProps0, inputProps: inputProps0 } = useSliderThumb({ index: 0 }, state);

  return (
    <div {...groupProps}>
      <div {...trackProps} ref={trackRef} style={{ position: 'relative', height: '4px', background: 'gray' }}>
        <div {...thumbProps0} style={{ position: 'absolute', top: '-6px', left: `${state.getThumbPercent(0) * 100}%`, width: '20px', height: '20px', background: 'blue' }}>
          <VisuallyHidden>
            <input {...inputProps0} />
          </VisuallyHidden>
        </div>
      </div>
    </div>
  );
}

Range Slider

This code demonstrates how to create a range slider with two thumbs using @react-aria/slider. It ensures both thumbs are accessible and can be controlled via keyboard and screen readers.

import { useSlider, useSliderThumb } from '@react-aria/slider';
import { useSliderState } from '@react-stately/slider';
import { VisuallyHidden } from '@react-aria/visually-hidden';
import { useRef } from 'react';

function RangeSlider(props) {
  let trackRef = useRef(null);
  let state = useSliderState(props);
  let { groupProps, trackProps, thumbProps } = useSlider(props, state, trackRef);
  let { thumbProps: thumbProps0, inputProps: inputProps0 } = useSliderThumb({ index: 0 }, state);
  let { thumbProps: thumbProps1, inputProps: inputProps1 } = useSliderThumb({ index: 1 }, state);

  return (
    <div {...groupProps}>
      <div {...trackProps} ref={trackRef} style={{ position: 'relative', height: '4px', background: 'gray' }}>
        <div {...thumbProps0} style={{ position: 'absolute', top: '-6px', left: `${state.getThumbPercent(0) * 100}%`, width: '20px', height: '20px', background: 'blue' }}>
          <VisuallyHidden>
            <input {...inputProps0} />
          </VisuallyHidden>
        </div>
        <div {...thumbProps1} style={{ position: 'absolute', top: '-6px', left: `${state.getThumbPercent(1) * 100}%`, width: '20px', height: '20px', background: 'blue' }}>
          <VisuallyHidden>
            <input {...inputProps1} />
          </VisuallyHidden>
        </div>
      </div>
    </div>
  );
}

Other packages similar to @react-aria/slider

FAQs

Package last updated on 02 Dec 2020

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