Bug 1529680 - [release 127] Fixing source selection with the keyboard (fixes #7874) (#7874) (#7992). r=dwalsh
This commit is contained in:
committed by
Jason Laster
parent
e3656b0fc3
commit
1950217be2
@@ -164,6 +164,10 @@ class SourcesTree extends Component<Props, State> {
|
|||||||
this.props.focusItem({ thread: this.props.thread, item });
|
this.props.focusItem({ thread: this.props.thread, item });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onActivate = (item: TreeNode) => {
|
||||||
|
this.selectItem(item);
|
||||||
|
};
|
||||||
|
|
||||||
// NOTE: we get the source from sources because item.contents is cached
|
// NOTE: we get the source from sources because item.contents is cached
|
||||||
getSource(item: TreeNode): ?Source {
|
getSource(item: TreeNode): ?Source {
|
||||||
const source = getSourceFromNode(item);
|
const source = getSourceFromNode(item);
|
||||||
@@ -194,13 +198,6 @@ class SourcesTree extends Component<Props, State> {
|
|||||||
this.props.setExpandedState(this.props.thread, expandedState);
|
this.props.setExpandedState(this.props.thread, expandedState);
|
||||||
};
|
};
|
||||||
|
|
||||||
onKeyDown = (e: KeyboardEvent) => {
|
|
||||||
const { focused } = this.props;
|
|
||||||
if (e.keyCode === 13 && focused) {
|
|
||||||
this.selectItem(focused);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
isEmpty() {
|
isEmpty() {
|
||||||
const { sourceTree } = this.state;
|
const { sourceTree } = this.state;
|
||||||
return sourceTree.contents.length === 0;
|
return sourceTree.contents.length === 0;
|
||||||
@@ -280,6 +277,7 @@ class SourcesTree extends Component<Props, State> {
|
|||||||
onCollapse: this.onCollapse,
|
onCollapse: this.onCollapse,
|
||||||
onExpand: this.onExpand,
|
onExpand: this.onExpand,
|
||||||
onFocus: this.onFocus,
|
onFocus: this.onFocus,
|
||||||
|
onActivate: this.onActivate,
|
||||||
renderItem: this.renderItem,
|
renderItem: this.renderItem,
|
||||||
preventBlur: true
|
preventBlur: true
|
||||||
};
|
};
|
||||||
@@ -336,7 +334,7 @@ class SourcesTree extends Component<Props, State> {
|
|||||||
|
|
||||||
return this.renderPane(
|
return this.renderPane(
|
||||||
this.renderThreadHeader(),
|
this.renderThreadHeader(),
|
||||||
<div key="tree" className="sources-list" onKeyDown={this.onKeyDown}>
|
<div key="tree" className="sources-list">
|
||||||
{this.renderTree()}
|
{this.renderTree()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -177,26 +177,17 @@ describe("SourcesTree", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("focusItem", () => {
|
describe("activateItem", () => {
|
||||||
it("update the focused item", async () => {
|
it("select activated item", async () => {
|
||||||
|
const { instance, props } = render();
|
||||||
const item = createMockItem();
|
const item = createMockItem();
|
||||||
const { component, props } = render({ focused: item });
|
const spy = jest.spyOn(instance, "selectItem");
|
||||||
|
|
||||||
await component
|
instance.onActivate(item);
|
||||||
.find(".sources-list")
|
expect(spy).toHaveBeenCalledWith(item);
|
||||||
.simulate("keydown", { keyCode: 13 });
|
expect(props.selectSource).toHaveBeenCalledWith(
|
||||||
|
"server1.conn13.child1/39"
|
||||||
expect(props.selectSource).toHaveBeenCalledWith(item.contents.id);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
it("allows focus on the (index)", async () => {
|
|
||||||
const item = createMockItem("https://davidwalsh.name/", "(index)");
|
|
||||||
|
|
||||||
const { component, props } = render({ focused: item });
|
|
||||||
await component
|
|
||||||
.find(".sources-list")
|
|
||||||
.simulate("keydown", { keyCode: 13 });
|
|
||||||
expect(props.selectSource).toHaveBeenCalledWith(item.contents.id);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -214,14 +205,6 @@ describe("SourcesTree", () => {
|
|||||||
instance.selectItem(createMockDirectory());
|
instance.selectItem(createMockDirectory());
|
||||||
expect(props.selectSource).not.toHaveBeenCalled();
|
expect(props.selectSource).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not select if no item is focused on", async () => {
|
|
||||||
const { component, props } = render();
|
|
||||||
await component
|
|
||||||
.find(".sources-list")
|
|
||||||
.simulate("keydown", { keyCode: 13 });
|
|
||||||
expect(props.selectSource).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("handles items", () => {
|
describe("handles items", () => {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ exports[`SourcesTree After changing expanded nodes Shows the tree with four.js,
|
|||||||
<div
|
<div
|
||||||
className="sources-list"
|
className="sources-list"
|
||||||
key="tree"
|
key="tree"
|
||||||
onKeyDown={[Function]}
|
|
||||||
>
|
>
|
||||||
<ManagedTree
|
<ManagedTree
|
||||||
autoExpandAll={false}
|
autoExpandAll={false}
|
||||||
@@ -26,6 +25,7 @@ exports[`SourcesTree After changing expanded nodes Shows the tree with four.js,
|
|||||||
getRoots={[Function]}
|
getRoots={[Function]}
|
||||||
itemHeight={21}
|
itemHeight={21}
|
||||||
key="full"
|
key="full"
|
||||||
|
onActivate={[Function]}
|
||||||
onCollapse={[Function]}
|
onCollapse={[Function]}
|
||||||
onExpand={[Function]}
|
onExpand={[Function]}
|
||||||
onFocus={[Function]}
|
onFocus={[Function]}
|
||||||
@@ -44,7 +44,6 @@ exports[`SourcesTree Should show the tree with nothing expanded 1`] = `
|
|||||||
<div
|
<div
|
||||||
className="sources-list"
|
className="sources-list"
|
||||||
key="tree"
|
key="tree"
|
||||||
onKeyDown={[Function]}
|
|
||||||
>
|
>
|
||||||
<ManagedTree
|
<ManagedTree
|
||||||
autoExpandAll={false}
|
autoExpandAll={false}
|
||||||
@@ -55,6 +54,7 @@ exports[`SourcesTree Should show the tree with nothing expanded 1`] = `
|
|||||||
getRoots={[Function]}
|
getRoots={[Function]}
|
||||||
itemHeight={21}
|
itemHeight={21}
|
||||||
key="full"
|
key="full"
|
||||||
|
onActivate={[Function]}
|
||||||
onCollapse={[Function]}
|
onCollapse={[Function]}
|
||||||
onExpand={[Function]}
|
onExpand={[Function]}
|
||||||
onFocus={[Function]}
|
onFocus={[Function]}
|
||||||
@@ -73,7 +73,6 @@ exports[`SourcesTree When loading initial source Shows the tree with one.js, two
|
|||||||
<div
|
<div
|
||||||
className="sources-list"
|
className="sources-list"
|
||||||
key="tree"
|
key="tree"
|
||||||
onKeyDown={[Function]}
|
|
||||||
>
|
>
|
||||||
<ManagedTree
|
<ManagedTree
|
||||||
autoExpandAll={false}
|
autoExpandAll={false}
|
||||||
@@ -91,6 +90,7 @@ exports[`SourcesTree When loading initial source Shows the tree with one.js, two
|
|||||||
getRoots={[Function]}
|
getRoots={[Function]}
|
||||||
itemHeight={21}
|
itemHeight={21}
|
||||||
key="full"
|
key="full"
|
||||||
|
onActivate={[Function]}
|
||||||
onCollapse={[Function]}
|
onCollapse={[Function]}
|
||||||
onExpand={[Function]}
|
onExpand={[Function]}
|
||||||
onFocus={[Function]}
|
onFocus={[Function]}
|
||||||
@@ -109,7 +109,6 @@ exports[`SourcesTree on receiving new props updates highlighted items updates hi
|
|||||||
<div
|
<div
|
||||||
className="sources-list"
|
className="sources-list"
|
||||||
key="tree"
|
key="tree"
|
||||||
onKeyDown={[Function]}
|
|
||||||
>
|
>
|
||||||
<ManagedTree
|
<ManagedTree
|
||||||
autoExpandAll={false}
|
autoExpandAll={false}
|
||||||
@@ -251,6 +250,7 @@ exports[`SourcesTree on receiving new props updates highlighted items updates hi
|
|||||||
}
|
}
|
||||||
itemHeight={21}
|
itemHeight={21}
|
||||||
key="full"
|
key="full"
|
||||||
|
onActivate={[Function]}
|
||||||
onCollapse={[Function]}
|
onCollapse={[Function]}
|
||||||
onExpand={[Function]}
|
onExpand={[Function]}
|
||||||
onFocus={[Function]}
|
onFocus={[Function]}
|
||||||
|
|||||||
Reference in New Issue
Block a user