question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useSlider() and useSliderState() for a Slider component

See original GitHub issue

I’d like to implement useSlider() for @react-aria and useSliderState() for @react-stately. I believe the first step is to draft an RFC?

Before I get started, though, if folks from the Spectrum team had already thought about what the API would look like, it’d be very helpful to get a brain dump first!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
chungwucommented, Jul 21, 2020

Hi all! Finally got around to pulling together a draft PR for this 😄

You’ll find it in #809

I built the react-aria and react-stately hooks, and a few toy components using those hooks, and some Storybook stories, so we can get a feel for how the component interactions work, and what the DX is like in using these hooks.

1reaction
majornistacommented, Jul 17, 2020

@chungwu You’re close. I would use a label for the div with id="label" and have its for/htmlFor attribute point to the id attribute on the first input, which could be assigned on the React component, but if not be generated internally. Each input should have aria-labelledby="label THE-GENERATED-ID-FOR-THE-INPUT". So that the Min should announce as “label Minimum”, and the Max should announce as “label Maximum”.

Modified version:

<div role="group" aria-labelledby="range-input-label-0">
  <label id="range-input-label-0" for="range-input-0">Whatever I passed to label prop</label>
  <div className="thumbs">

    <div className="thumb">
      <input id="range-input-0" aria-labelledby="range-input-label-0 range-input-0" type="range" aria-label="Minimum" aria-valuemin/max/now=.../>
      <div className="thumb-knob"/>
    </div>

    <div className="thumb">
      <input id="range-input-1" aria-labelledby="range-input-label-0 range-input-1" type="range" aria-label="Maximum" aria-valuemin/max/now=.../>
      <div className="thumb-knob"/>
    </div>

  </div>
</div>

Small hint, put thumb-knob after the input so you can render the focused style using adjacent CSS selector.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useSliderState – React Stately
Provides state management for a slider component. Stores values for all thumbs, formats values for localization, and provides methods to update the position...
Read more >
Unstyled React Slider component and hook - MUI Base
The useSlider hook lets you apply the functionality of a slider to a fully custom component. It returns props to be placed on...
Read more >
React slider tutorial using react-slider - LogRocket Blog
Learn how to create different sliders using react-slider, a React headless component that's easy to build and customize.
Read more >
useSlider – React Aria - NET
useSlider. Provides the behavior and accessibility implementation for a slider component representing one or more values.
Read more >
Learn What is Reactjs Slider Component & How to Use It
map() function. import React, {useState} from 'react'. import './Slider.css'. import dataSlider from '.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found