Bug 1438912 - by default, do not navigate to next node on ArrowRight key. r=nchevobbe

MozReview-Commit-ID: KQlHIA7pYAn
This commit is contained in:
Yura Zenevich 2018-03-08 15:51:09 -05:00
Родитель 26b8f527e1
Коммит 89b8270203
7 изменённых файлов: 49 добавлений и 7 удалений

Просмотреть файл

@ -49,6 +49,7 @@ class Census extends Component {
return Tree({ return Tree({
autoExpandDepth: 0, autoExpandDepth: 0,
preventNavigationOnArrowRight: false,
focused: census.focused, focused: census.focused,
getParent: node => { getParent: node => {
const parent = parentMap[node.id]; const parent = parentMap[node.id];

Просмотреть файл

@ -134,6 +134,7 @@ class DominatorTree extends Component {
return Tree({ return Tree({
key: "dominator-tree-tree", key: "dominator-tree-tree",
autoExpandDepth: DOMINATOR_TREE_AUTO_EXPAND_DEPTH, autoExpandDepth: DOMINATOR_TREE_AUTO_EXPAND_DEPTH,
preventNavigationOnArrowRight: false,
focused: dominatorTree.focused, focused: dominatorTree.focused,
getParent: node => getParent: node =>
node instanceof DominatorTreeLazyChildren node instanceof DominatorTreeLazyChildren

Просмотреть файл

@ -35,6 +35,7 @@ class Individuals extends Component {
return Tree({ return Tree({
key: "individuals-tree", key: "individuals-tree",
autoExpandDepth: 0, autoExpandDepth: 0,
preventNavigationOnArrowRight: false,
focused: individuals.focused, focused: individuals.focused,
getParent: node => null, getParent: node => null,
getChildren: node => [], getChildren: node => [],

Просмотреть файл

@ -189,6 +189,7 @@ class JITOptimizations extends Component {
return Tree({ return Tree({
autoExpandDepth, autoExpandDepth,
preventNavigationOnArrowRight: false,
getParent: node => { getParent: node => {
let site = getSite(node.id); let site = getSite(node.id);
let parent; let parent;

Просмотреть файл

@ -163,6 +163,7 @@ class WaterfallTree extends Component {
render() { render() {
return Tree({ return Tree({
preventNavigationOnArrowRight: false,
getRoots: this._getRoots, getRoots: this._getRoots,
getParent: this._getParent, getParent: this._getParent,
getChildren: this._getChildren, getChildren: this._getChildren,

Просмотреть файл

@ -198,6 +198,10 @@ class Tree extends Component {
// Handle when item is activated with a keyboard (using Space or Enter) // Handle when item is activated with a keyboard (using Space or Enter)
onActivate: PropTypes.func, onActivate: PropTypes.func,
// Indicates if pressing ArrowRight key should only expand expandable node
// or if the selection should also move to the next node.
preventNavigationOnArrowRight: PropTypes.bool,
// The depth to which we should automatically expand new items. // The depth to which we should automatically expand new items.
autoExpandDepth: PropTypes.number, autoExpandDepth: PropTypes.number,
@ -228,6 +232,7 @@ class Tree extends Component {
static get defaultProps() { static get defaultProps() {
return { return {
autoExpandDepth: AUTO_EXPAND_DEPTH, autoExpandDepth: AUTO_EXPAND_DEPTH,
preventNavigationOnArrowRight: true,
}; };
} }
@ -502,9 +507,10 @@ class Tree extends Component {
break; break;
case "ArrowRight": case "ArrowRight":
if (!this.props.isExpanded(this.props.focused)) { if (this.props.getChildren(this.props.focused).length &&
!this.props.isExpanded(this.props.focused)) {
this._onExpand(this.props.focused); this._onExpand(this.props.focused);
} else { } else if (!this.props.preventNavigationOnArrowRight) {
this._focusNextNode(); this._focusNextNode();
} }
break; break;

Просмотреть файл

@ -16,12 +16,17 @@ Test keyboard navigation with the Tree component.
<pre id="test"> <pre id="test">
<script src="head.js" type="application/javascript"></script> <script src="head.js" type="application/javascript"></script>
<script type="application/javascript"> <script type="application/javascript">
"use strict";
window.onload = async function () { window.onload = async function () {
try { try {
const ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom"); const ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom");
const { createFactory } = browserRequire("devtools/client/shared/vendor/react"); const { createFactory } = browserRequire("devtools/client/shared/vendor/react");
const { Simulate } = browserRequire("devtools/client/shared/vendor/react-dom-test-utils"); const { Simulate } =
const Tree = createFactory(browserRequire("devtools/client/shared/components/VirtualizedTree")); browserRequire("devtools/client/shared/vendor/react-dom-test-utils");
const Tree =
createFactory(browserRequire("devtools/client/shared/components/VirtualizedTree"));
function renderTree(props) { function renderTree(props) {
const treeProps = Object.assign({}, const treeProps = Object.assign({},
@ -175,7 +180,8 @@ window.onload = async function () {
"M:false", "M:false",
"-N:false", "-N:false",
"--O:true", "--O:true",
], "After the DOWN, O should still be focused and we shouldn't have overflowed past it."); ], "After the DOWN, O should still be focused " +
"and we shouldn't have overflowed past it.");
// LEFT -------------------------------------------------------------------- // LEFT --------------------------------------------------------------------
@ -246,7 +252,30 @@ window.onload = async function () {
"--O:false", "--O:false",
], "After the RIGHT, E's children should be expanded again."); ], "After the RIGHT, E's children should be expanded again.");
info("Right to go to next item."); info("Right on already expanded node.");
Simulate.keyDown(document.querySelector(".tree"), { key: "ArrowRight" });
await forceRender(tree);
isRenderedTree(document.body.textContent, [
"A:false",
"-B:false",
"--E:true",
"---K:false",
"---L:false",
"--F:false",
"--G:false",
"-C:false",
"--H:false",
"--I:false",
"-D:false",
"--J:false",
"M:false",
"-N:false",
"--O:false",
], "After the RIGHT on already expanded node, E should remain focused.");
info("Right when preventNavigationOnArrowRight is unset to go to next item.");
renderTree({ focused: "E", preventNavigationOnArrowRight: false });
Simulate.keyDown(document.querySelector(".tree"), { key: "ArrowRight" }); Simulate.keyDown(document.querySelector(".tree"), { key: "ArrowRight" });
await forceRender(tree); await forceRender(tree);
@ -275,6 +304,8 @@ window.onload = async function () {
{ key: "ArrowDown", metaKey: true }, { key: "ArrowDown", metaKey: true },
{ key: "ArrowDown", shiftKey: true }, { key: "ArrowDown", shiftKey: true },
]; ];
await forceRender(tree);
for (let key of keysWithModifier) { for (let key of keysWithModifier) {
Simulate.keyDown(document.querySelector(".tree"), key); Simulate.keyDown(document.querySelector(".tree"), key);
await forceRender(tree); await forceRender(tree);
@ -297,7 +328,7 @@ window.onload = async function () {
"--O:false", "--O:false",
], "After DOWN + (alt|ctrl|meta|shift), K should remain focused."); ], "After DOWN + (alt|ctrl|meta|shift), K should remain focused.");
} }
} catch(e) { } catch (e) {
ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e)); ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
} finally { } finally {
SimpleTest.finish(); SimpleTest.finish();