Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessibility: Support aria-labels #125

Merged

Conversation

atlidohop
Copy link
Contributor

Addresses issue #124

@mpowaga
Copy link
Contributor

mpowaga commented Mar 6, 2018

Thanks @atlidohop! Looks good to me. Just one nitpick - what's the purpose of making aria props default to empty string? Shouldn't they stay undefined when not provided?

@atlidohop
Copy link
Contributor Author

Good point, @mpowaga . Changes coming up.

@atlidohop
Copy link
Contributor Author

Beware, this is untested code, but works for my use case. How can I run index.html?

@atlidohop
Copy link
Contributor Author

atlidohop commented Mar 6, 2018

This should work for all cases now @mpowaga . I also made some changes to make this package more accessible to contributing developers. Let me know if I'm breaking something somewhere else. 😅

@mpowaga
Copy link
Contributor

mpowaga commented Mar 6, 2018

I appreciate the effort to make it easier to contribute but React and other packages must be declared as peerDependencies. Can you open an issue where we can discuss how we can improve development experience?

@atlidohop
Copy link
Contributor Author

Sure thing. I'll revert the changes in package.json.

react-slider.js Outdated
@@ -734,6 +734,9 @@
var className = this.props.handleClassName + ' ' +
(this.props.handleClassName + '-' + i) + ' ' +
(this.state.index === i ? this.props.handleActiveClassName : '');
var ariaLabelArray = this.props.ariaLabel && this.props.ariaLabel.constructor === Array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At best we should use Array.isArray but because it's not supported by all browsers we need a polyfill. Can you add it at the top where we define our util functions, e.g.

var isArray = Array.isArray || function(x) {
  return Object.prototype.toString.call(x) === '[object Array]';
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing.

react-slider.js Outdated
@@ -749,6 +752,10 @@
"aria-valuenow": this.state.value[i],
"aria-valuemin": this.props.min,
"aria-valuemax": this.props.max,
"aria-label": ariaLabelArray && i < this.props.ariaLabel.length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bound check is not necessary here (in fact it's an error because when out of bound access is detected it will pass an array to aria-label property). We can simply write it as follows.

"aria-label": isArray(this.props.ariaLabel) ? this.props.ariaLabel[i] : this.props.ariaLabel,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right! Changing this.

README.md Outdated
@@ -145,6 +145,16 @@ Callback called only after moving a handle has ended or when a new value is set

Callback called when the the slider is clicked (handle or bars). Receives the value at the clicked position as argument.

##### ariaLabel {oneOfType([string, arrayOf(string)])} default: ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default: '' can be removed now.

README.md Outdated
Use an array for more than one handle.
The length of the array must match the number of handles in the value array.

##### ariaValuetext {string} default: ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default: '' can be removed now (here as well 😄)

README.md Outdated
@@ -155,3 +165,18 @@ or an array of numbers in case of a multi slider.
### License

See the [License](LICENSE) file.

### Developers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this section for now and add it in another PR once we decide how development setup should work.

@atlidohop
Copy link
Contributor Author

@mpowaga Thanks for good comments, much better now. 😄

@mpowaga mpowaga merged commit bf3c3d7 into zillow:master Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants