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

feat(ObjectViewer): improve a11y #1616

Merged
merged 45 commits into from
Sep 18, 2018

Conversation

jsomsanith-tlnd
Copy link
Contributor

@jsomsanith-tlnd jsomsanith-tlnd commented Aug 13, 2018

What is the problem this PR is trying to solve?
Table mode

  • no caption
  • no ids on headers
  • no headers attributes on cells

JSON mode

  • no accessible tree structure
  • no tree gesture

What is the chosen solution to this problem?
Table mode

  • add hidden caption that will contains a props.title (required)
  • add ids on headers based on a props.id (required)
  • set those ids in the cells headers attribute

JSON mode (refacto)

Please check if the PR fulfills these requirements

  • The PR commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features) And non reg done before need review
  • Docs have been added / updated (for bug fixes / features)
  • Related design / discussions / pages (not in jira), if any, are all linked or available in the PR

[x] This PR introduces a breaking change

This impacts only the component. If you use the cmf container, it works as expected.

Before After Explanation
props.onMouseOver - Not accessible. This would introduce performance issues with keyboad navigation. But this is not used, so let's remove it.
props.onSelect(event, jsonpath) props.onSelect(event, { jsonpath }) This simplifies the code. This is triggered through TreeGesture HOC that takes an item and pass it through to the props callback. This is simple and compatible with TreeView and the new ObjectViewer apis.
- Required props.onToggleAllSiblings(event, siblings) This is for accessibility. It is triggered on * keydown to expand all the nodes at the same level
has been removed.

Before

import ObjectViewer from '@talend/react-components/lib/ObjectViewer';

class MyComponent extends React.Component {
	...

	mouseOverHandler(event, item) {}

	selectHandler(event, jsonpath) {}

	render() {
		return (
			<ObjectViewer
				onMouseOver={this.mouseOverHandler}
				onSelect=(this.selectHandler}
				...
			/>
		);
	}
}

After

import ObjectViewer from '@talend/react-components/lib/ObjectViewer';

class MyComponent extends React.Component {
	...

	selectHandler(event, jsonpath) {}

	toggleAllHandler(event, itemsToToggle) {}

	render() {
		return (
			<ObjectViewer
				onSelect=(this.selectHandler}
				onToggleAllSiblings={this.toggleAllHandler}
				...
			/>
		);
	}
}

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

1 similar comment
@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

1 similar comment
@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

1 similar comment
@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

1 similar comment
@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

Copy link
Contributor

@jmfrancois jmfrancois left a comment

Choose a reason for hiding this comment

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

I have covered the treeview part.
Don t forget to check the console in the storybook i have lots of JS Error

case keycode.codes.end:
focusOn(event, getLastItem(ref));
break;
case keycode.codes['numpad *']:
Copy link
Contributor

Choose a reason for hiding this comment

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

it doesn t work with *

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it, but I need to test the key, not the keyCode. Depending on the keyboard, the keyCode is different :/


TreeGesture.propTypes = {
...omit(WrappedComponent.propTypes, 'onKeyDown'),
onToggleAllSiblings: PropTypes.func.isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

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

onSelect and onToggle are used and required (in your code)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

break;
default:
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

please add support for this.props.onKeyDown

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No there is no need. If the need comes, it's easy to add it, but adding a feature in case someone needs it is not a good idea IMO

@@ -0,0 +1,162 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

it s a function so please name the file withTreeGesture (like connect)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the file name


const treeProps = {
items: [
{ id: 0 }, // 0 0
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry I don t understand those comments ( // 1 0)
Looks like battleships coordinates :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are coordinates :D
Those are level / index. It's easier to understand with those while reading some tests. I'll add a legend


onToggleAllSiblings(event, items) {
event.stopPropagation();
return this.props.onToggleAllSiblings(event, items);
Copy link
Contributor

Choose a reason for hiding this comment

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

you have hide event.stopPropagation in every handler.
I found that makes the readability quite hard.
What do you think about:
call event.stopPropagation in onKeyDown when the key is handled and call the associated effect.

the focusOn should not stop propagation but just call focus if element exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

],
}, // 0 1
{ id: 2 }, // 0 2
{ id: 3 }, // 0 3
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if we should keep those comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the legend

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

1 similar comment
@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

};
const wrapper = mount(<ComponentWithGesture {...props} />);
const event = {
keyCode: keycode.codes['numpad *'],
Copy link
Contributor

Choose a reason for hiding this comment

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

this is wrong, the code use the native event, not the numpad, so why it here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@@ -154,6 +154,7 @@ const defaultProps = {
structure,
onSelect: action('onSelect'),
onToggle: action('onToggle'),
onToggleAllSiblings: action('onToggleAllSiblings'),
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

1 similar comment
@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@build-travis-ci
Copy link
Collaborator

:octocat: Demo is available here

@jsomsanith-tlnd jsomsanith-tlnd merged commit 42b7ac8 into master Sep 18, 2018
@jsomsanith-tlnd jsomsanith-tlnd deleted the jsomsanith/feat/a11y_object_viewer branch September 18, 2018 08:26
jsomsanith-tlnd added a commit that referenced this pull request Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants