Skip to content

Tree bug fixes introduced by keyboard navigation #1379

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

Merged
merged 11 commits into from
May 18, 2018

Conversation

garygong
Copy link
Contributor

@garygong garygong commented May 14, 2018

This fixes two Tree bugs:


Pull Request Review checklist (do not remove)

  • npm run lint:fix has been run and linting passes.
  • Mocha, Jest (Storyshots), and components/component-docs.json CI tests pass (npm test).
  • Tests have been added for new props to prevent regressions in the future. See readme.
  • Review the appropriate Storybook stories. Open http://localhost:9001/.
  • Review tests are passing in the browser. Open http://localhost:8001/.
  • Review markup conforms to SLDS by looking at DOM snapshot strings.
  • Add year-first date and commit SHA to last-slds-markup-review in package.json and push.
  • Request a review of the deployed Heroku app by the Salesforce UX Accessibility Team.
  • Add year-first review date, and commit SHA, last-accessibility-review, to package.json and push.
  • While the contributor's branch is checked out, run npm run local-update within locally cloned site repo to confirm the site will function correctly at the next release.

- Tree is not rendered on props changes
- Show proper aria-label value when label is a node
@garygong garygong added the tree label May 14, 2018
@garygong garygong self-assigned this May 14, 2018
@garygong garygong requested a review from interactivellama May 14, 2018 17:33
@@ -54,16 +54,6 @@ class Tree extends React.Component {
});
}

shouldComponentUpdate (nextProps, nextState) {
Copy link
Contributor Author

@garygong garygong May 14, 2018

Choose a reason for hiding this comment

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

It turns out that it's simpler to avoid the react lifecycle completely by moving treeHasFocus out of state.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I'm seeing here is something like treeHasFocusDueToClick? Would that be more accurate? I'll go ahead and push that variable name if you agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that's right, go ahead. Thanks!

if (isFunction(props.onClick)) {
props.onClick(event, {
if (isFunction(props.onSelect)) {
props.onSelect(event, {
Copy link
Contributor

Choose a reason for hiding this comment

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

@garygong Removing this line makes the expand work.

@@ -60,7 +61,7 @@ const DemoTree = createReactClass({
? sampleNodes[this.props.exampleNodesIndex]
: sampleNodes.sampleNodesDefault;
return {
nodes: initalNodes,
nodes: cloneDeep(initalNodes),
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 was seeing that nodes values were carrying over test-to-test. We should start fresh every time.

@@ -29,15 +31,27 @@ import { TREE } from '../../utilities/constants';
class Tree extends React.Component {
constructor (props) {
super(props);
const flattenedNodes = this.flattenTree({
Copy link
Contributor Author

@garygong garygong May 17, 2018

Choose a reason for hiding this comment

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

Now, we find the first selected node and initialize it properly so that can be tabbed to. If no node is selected, it will be selected upon first focus.

@@ -173,7 +172,7 @@ const handleKeyDown = (event, props) => {
};

const handleFocus = (event, props) => {
if (!props.focusedNodeIndex) {
if (!props.focusedNodeIndex && event.target === event.currentTarget) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This selects the node upon first focus, but only do it if focusing the <li>. When focusing the button, we allow it to go through so that the branch expand handler works.

This allows manual testing of setting tabIndex/focus not on the first item.
Move flattenTree function out and make other methods fat arrows
This prevents data reference leaking between stories
@interactivellama interactivellama changed the title Tree bug fixes Tree bug fixes introduced by keyboard navigation May 18, 2018
@interactivellama interactivellama merged commit 36af33e into salesforce:master May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants