Skip to content

Commit

Permalink
feat: Adding a new ariaLabelledby prop for use with Assistive Technol…
Browse files Browse the repository at this point in the history
…ogies
  • Loading branch information
olliecurtis authored and stonebk committed May 18, 2021
1 parent a5a8686 commit 7d8cc4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/ReactSlider/ReactSlider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ class ReactSlider extends React.Component {
// eslint-disable-next-line zillow/react/require-default-props
ariaLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),

/**
* aria-labelledby for screen-readers to apply to the thumbs.
* Used when slider rendered with separate label.
*/
// eslint-disable-next-line zillow/react/require-default-props
ariaLabelledby: PropTypes.string,

/**
* aria-valuetext for screen-readers.
* Can be a static string, or a function that returns a string.
Expand Down Expand Up @@ -995,6 +1002,7 @@ class ReactSlider extends React.Component {
'aria-label': Array.isArray(this.props.ariaLabel)
? this.props.ariaLabel[i]
: this.props.ariaLabel,
'aria-labelledby': this.props.ariaLabelledby,
};

const state = {
Expand Down
4 changes: 4 additions & 0 deletions src/components/ReactSlider/ReactSlider.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Double slider
trackClassName="example-track"
defaultValue={[0, 100]}
ariaLabel={['Lower thumb', 'Upper thumb']}
ariaLabelledby="Slider label"
ariaValuetext={state => `Thumb value ${state.valueNow}`}
renderThumb={(props, state) => <div {...props}>{state.valueNow}</div>}
pearling
Expand All @@ -65,6 +66,7 @@ Multi slider
trackClassName="example-track"
defaultValue={[0, 50, 100]}
ariaLabel={['Leftmost thumb', 'Middle thumb', 'Rightmost thumb']}
ariaLabelledby="Slider label"
renderThumb={(props, state) => <div {...props}>{state.valueNow}</div>}
pearling
minDistance={10}
Expand All @@ -80,6 +82,7 @@ Vertical slider
trackClassName="example-track"
defaultValue={[0, 50, 100]}
ariaLabel={['Lowest thumb', 'Middle thumb', 'Top thumb']}
ariaLabelledby="Slider label"
renderThumb={(props, state) => <div {...props}>{state.valueNow}</div>}
orientation="vertical"
invert
Expand All @@ -99,6 +102,7 @@ Vertical slider with marks at an interval
defaultValue={[0, 50, 100]}
marks={25}
ariaLabel={['Lowest thumb', 'Middle thumb', 'Top thumb']}
ariaLabelledby="Slider label"
renderThumb={(props, state) => <div {...props}>{state.valueNow}</div>}
orientation="vertical"
invert
Expand Down

0 comments on commit 7d8cc4d

Please sign in to comment.